@@ -30,6 +30,19 @@ func (h *HasRoleDirective) Validate(ctx context.Context, _ interface{}) error {
30
30
return nil
31
31
}
32
32
33
+ // NullableDirective
34
+ type WithNullableArgumentDirective struct {
35
+ ANullableArgument * string
36
+ }
37
+
38
+ func (_ * WithNullableArgumentDirective ) Validate (_ context.Context , _ interface {}) error {
39
+ return nil
40
+ }
41
+
42
+ func (_ * WithNullableArgumentDirective ) ImplementsDirective () string {
43
+ return "withNullableArgument"
44
+ }
45
+
33
46
type UpperDirective struct {}
34
47
35
48
func (d * UpperDirective ) ImplementsDirective () string {
@@ -55,6 +68,9 @@ type authResolver struct{}
55
68
func (* authResolver ) Greet (ctx context.Context , args struct { Name string }) string {
56
69
return fmt .Sprintf ("Hello, %s!" , args .Name )
57
70
}
71
+ func (* authResolver ) NullableDirective () string {
72
+ return "nullableDirective"
73
+ }
58
74
59
75
// ExampleDirectives demonstrates the use of the Directives schema option.
60
76
func ExampleDirectives () {
@@ -65,13 +81,15 @@ func ExampleDirectives() {
65
81
66
82
directive @hasRole(role: String!) on FIELD_DEFINITION
67
83
directive @upper on FIELD_DEFINITION
84
+ directive @withNullableArgument(aNullableArgument: String) on FIELD_DEFINITION
68
85
69
86
type Query {
70
87
greet(name: String!): String! @hasRole(role: "admin") @upper
88
+ nullableDirective: String! @withNullableArgument()
71
89
}
72
90
`
73
91
opts := []graphql.SchemaOpt {
74
- graphql .Directives (& HasRoleDirective {}, & UpperDirective {}),
92
+ graphql .Directives (& HasRoleDirective {}, & UpperDirective {}, & WithNullableArgumentDirective {} ),
75
93
// other options go here
76
94
}
77
95
schema := graphql .MustParseSchema (s , & authResolver {}, opts ... )
@@ -111,7 +129,7 @@ func ExampleDirectives() {
111
129
// "message": "access denied, role \"admin\" required",
112
130
// "locations": [
113
131
// {
114
- // "line": 10 ,
132
+ // "line": 11 ,
115
133
// "column": 4
116
134
// }
117
135
// ],
0 commit comments