forked from graphql-go/graphql
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdirectives.go
66 lines (62 loc) · 1.69 KB
/
directives.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package graphql
type Directive struct {
Name string `json:"name"`
Description string `json:"description"`
Args []*Argument `json:"args"`
OnOperation bool `json:"onOperation"`
OnFragment bool `json:"onFragment"`
OnField bool `json:"onField"`
}
/**
* Directives are used by the GraphQL runtime as a way of modifying execution
* behavior. Type system creators will usually not create these directly.
*/
func NewDirective(config *Directive) *Directive {
if config == nil {
config = &Directive{}
}
return &Directive{
Name: config.Name,
Description: config.Description,
Args: config.Args,
OnOperation: config.OnOperation,
OnFragment: config.OnFragment,
OnField: config.OnField,
}
}
/**
* Used to conditionally include fields or fragments
*/
var IncludeDirective *Directive = NewDirective(&Directive{
Name: "include",
Description: "Directs the executor to include this field or fragment only when " +
"the `if` argument is true.",
Args: []*Argument{
&Argument{
PrivateName: "if",
Type: NewNonNull(Boolean),
PrivateDescription: "Included when true.",
},
},
OnOperation: false,
OnFragment: true,
OnField: true,
})
/**
* Used to conditionally skip (exclude) fields or fragments
*/
var SkipDirective *Directive = NewDirective(&Directive{
Name: "skip",
Description: "Directs the executor to skip this field or fragment when the `if` " +
"argument is true.",
Args: []*Argument{
&Argument{
PrivateName: "if",
Type: NewNonNull(Boolean),
PrivateDescription: "Skipped when true.",
},
},
OnOperation: false,
OnFragment: true,
OnField: true,
})