This repository has been archived by the owner on Nov 8, 2017. It is now read-only.
forked from graphql-go/graphql
/
directives.go
60 lines (56 loc) · 1.68 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
package graphql
// Directive structs are used by the GraphQL runtime as a way of modifying execution
// behavior. Type system creators will usually not create these directly.
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"`
}
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,
}
}
// IncludeDirective is used to conditionally include fields or fragments
var IncludeDirective = 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,
})
// SkipDirective Used to conditionally skip (exclude) fields or fragments
var SkipDirective = 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,
})