File tree 2 files changed +93
-0
lines changed
2 files changed +93
-0
lines changed Original file line number Diff line number Diff line change @@ -186,3 +186,95 @@ it('should support `contextValue` configuration', async () => {
186
186
} ,
187
187
} )
188
188
} )
189
+
190
+ it ( 'should support schema with query and mutation `variables`' , async ( ) => {
191
+ const spy = vi . fn ( )
192
+
193
+ await createServer ( [
194
+ plugin ( {
195
+ schema : {
196
+ typeDefs : gql `
197
+ input MessageInput {
198
+ content: String
199
+ }
200
+
201
+ type Message {
202
+ content: String
203
+ }
204
+
205
+ type Query {
206
+ getMessage(id: ID!): Message
207
+ }
208
+
209
+ type Mutation {
210
+ createMessage(input: MessageInput): Message
211
+ }
212
+ ` ,
213
+ resolvers : {
214
+ Query : {
215
+ getMessage : ( _ , args ) => {
216
+ spy ( args )
217
+ return {
218
+ content : `Message: ${ args . id } ` ,
219
+ }
220
+ } ,
221
+ } ,
222
+ Mutation : {
223
+ createMessage : ( _ , args ) => {
224
+ spy ( args )
225
+ return {
226
+ content : `Message: ${ args . input . content } ` ,
227
+ }
228
+ } ,
229
+ } ,
230
+ } ,
231
+ } ,
232
+ } ) ,
233
+ ] )
234
+
235
+ const query = await request (
236
+ gql `
237
+ query getMessage($id: ID!) {
238
+ getMessage(id: $id) {
239
+ content
240
+ }
241
+ }
242
+ ` ,
243
+ {
244
+ id : 'Hello-World' ,
245
+ } ,
246
+ )
247
+
248
+ expect ( query ) . toEqual < ExecutionResult > ( {
249
+ errors : undefined ,
250
+ data : {
251
+ getMessage : {
252
+ content : 'Message: Hello-World' ,
253
+ } ,
254
+ } ,
255
+ } )
256
+
257
+ const mutation = await request (
258
+ gql `
259
+ mutation createMessage($input: MessageInput!) {
260
+ createMessage(input: $input) {
261
+ content
262
+ }
263
+ }
264
+ ` ,
265
+ {
266
+ input : {
267
+ content : 'Hello World' ,
268
+ } ,
269
+ } ,
270
+ )
271
+
272
+ expect ( mutation ) . toEqual < ExecutionResult > ( {
273
+ errors : undefined ,
274
+ data : {
275
+ createMessage : {
276
+ content : 'Message: Hello World' ,
277
+ } ,
278
+ } ,
279
+ } )
280
+ } )
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ export function handleGraphQLRequest(
25
25
const result = await graphql ( {
26
26
schema,
27
27
source : body . query ,
28
+ variableValues : body . variables ,
28
29
contextValue,
29
30
} )
30
31
You can’t perform that action at this time.
0 commit comments