@@ -64,15 +64,17 @@ def with_no_directives():
6464 """
6565 )
6666
67- def with_known_directives ():
67+ def with_standard_directives ():
6868 assert_valid (
6969 """
7070 {
71- dog @include(if: true) {
72- name
73- }
7471 human @skip(if: false) {
7572 name
73+ pets {
74+ ... on Dog @include(if: true) {
75+ name
76+ }
77+ }
7678 }
7779 }
7880 """
@@ -82,102 +84,136 @@ def with_unknown_directive():
8284 assert_errors (
8385 """
8486 {
85- dog @unknown(directive: "value") {
87+ human @unknown(directive: "value") {
8688 name
8789 }
8890 }
8991 """ ,
90- [{"message" : "Unknown directive '@unknown'." , "locations" : [(3 , 19 )]}],
92+ [{"message" : "Unknown directive '@unknown'." , "locations" : [(3 , 21 )]}],
9193 )
9294
9395 def with_many_unknown_directives ():
9496 assert_errors (
9597 """
9698 {
97- dog @unknown(directive: "value") {
98- name
99- }
100- human @unknown(directive: "value") {
99+ __typename @unknown
100+ human @unknown {
101101 name
102- pets @unknown(directive: "value") {
102+ pets @unknown {
103103 name
104104 }
105105 }
106106 }
107107 """ ,
108108 [
109- {"message" : "Unknown directive '@unknown'." , "locations" : [(3 , 19 )]},
110- {"message" : "Unknown directive '@unknown'." , "locations" : [(6 , 21 )]},
111- {"message" : "Unknown directive '@unknown'." , "locations" : [(8 , 22 )]},
109+ {"message" : "Unknown directive '@unknown'." , "locations" : [(3 , 26 )]},
110+ {"message" : "Unknown directive '@unknown'." , "locations" : [(4 , 21 )]},
111+ {"message" : "Unknown directive '@unknown'." , "locations" : [(6 , 22 )]},
112112 ],
113113 )
114114
115115 def with_well_placed_directives ():
116116 assert_valid (
117117 """
118- query ($var: Boolean) @onQuery {
119- name @include(if: $var)
120- ...Frag @include(if: true)
121- skippedField @skip(if: true)
122- ...SkippedFrag @skip(if: true)
123-
124- ... @skip(if: true) {
125- skippedField
118+ query ($var: Boolean @onVariableDefinition) @onQuery {
119+ human @onField {
120+ ...Frag @onFragmentSpread
121+ ... @onInlineFragment {
122+ name @onField
123+ }
126124 }
127125 }
128126
129127 mutation @onMutation {
130- someField
128+ someField @onField
131129 }
132130
133131 subscription @onSubscription {
134- someField
132+ someField @onField
135133 }
136134
137- fragment Frag on SomeType @onFragmentDefinition {
138- someField
139- }
140- """
141- )
142-
143- def with_well_placed_variable_definition_directive ():
144- assert_valid (
145- """
146- query Foo($var: Boolean @onVariableDefinition) {
147- name
135+ fragment Frag on Human @onFragmentDefinition {
136+ name @onField
148137 }
149138 """
150139 )
151140
152141 def with_misplaced_directives ():
153142 assert_errors (
154143 """
155- query Foo($var: Boolean) @include(if: true) {
156- name @onQuery @include(if: $var)
157- ...Frag @onQuery
144+ query ($var: Boolean @onQuery) @onMutation {
145+ human @onQuery {
146+ ...Frag @onQuery
147+ ... @onQuery {
148+ name @onQuery
149+ }
150+ }
158151 }
159152
160- mutation Bar @onQuery {
161- someField
153+ mutation @onQuery {
154+ someField @onQuery
155+ }
156+
157+ subscription @onQuery {
158+ someField @onQuery
159+ }
160+
161+ fragment Frag on Human @onQuery {
162+ name @onQuery
162163 }
163164 """ ,
164165 [
165166 {
166- "message" : "Directive '@include' may not be used on query." ,
167- "locations" : [(2 , 38 )],
167+ "message" : "Directive '@onQuery'"
168+ " may not be used on variable definition." ,
169+ "locations" : [(2 , 34 )],
170+ },
171+ {
172+ "message" : "Directive '@onMutation' may not be used on query." ,
173+ "locations" : [(2 , 44 )],
168174 },
169175 {
170176 "message" : "Directive '@onQuery' may not be used on field." ,
171- "locations" : [(3 , 20 )],
177+ "locations" : [(3 , 21 )],
172178 },
173179 {
174180 "message" : "Directive '@onQuery'"
175181 " may not be used on fragment spread." ,
176- "locations" : [(4 , 23 )],
182+ "locations" : [(4 , 25 )],
183+ },
184+ {
185+ "message" : "Directive '@onQuery'"
186+ " may not be used on inline fragment." ,
187+ "locations" : [(5 , 21 )],
188+ },
189+ {
190+ "message" : "Directive '@onQuery' may not be used on field." ,
191+ "locations" : [(6 , 24 )],
177192 },
178193 {
179194 "message" : "Directive '@onQuery' may not be used on mutation." ,
180- "locations" : [(7 , 26 )],
195+ "locations" : [(11 , 22 )],
196+ },
197+ {
198+ "message" : "Directive '@onQuery' may not be used on field." ,
199+ "locations" : [(12 , 25 )],
200+ },
201+ {
202+ "message" : "Directive '@onQuery' may not be used on subscription." ,
203+ "locations" : [(15 , 26 )],
204+ },
205+ {
206+ "message" : "Directive '@onQuery' may not be used on field." ,
207+ "locations" : [(16 , 25 )],
208+ },
209+ {
210+ "message" : "Directive '@onQuery'"
211+ " may not be used on fragment definition." ,
212+ "locations" : [(19 , 36 )],
213+ },
214+ {
215+ "message" : "Directive '@onQuery' may not be used on field." ,
216+ "locations" : [(20 , 20 )],
181217 },
182218 ],
183219 )
0 commit comments