-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathlist-coercion-test.js
54 lines (50 loc) · 1.16 KB
/
list-coercion-test.js
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
/* @flow strict */
import {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLList,
GraphQLNonNull,
graphql,
} from 'graphql';
describe('list coercion', () => {
it('test input list coercion', async () => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
getById: {
type: GraphQLString,
args: {
id: {
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLInt))),
},
},
resolve: (_, args) => JSON.stringify(args.id),
},
},
}),
});
const res = await graphql({
schema,
source: `
query {
op1: getById(id: 1)
op2: getById(id: [1, 2, 3])
}
`,
});
expect(res.data).toEqual({ op1: '[1]', op2: '[1,2,3]' });
const res2 = await graphql({
schema,
source: `
query ($id: [Int!]!) {
getById(id: $id)
}
`,
variableValues: { id: 777 }, // Should be array, but pass just Int
});
expect(res2.data).toEqual({ getById: '[777]' });
});
});