Skip to content

Commit d4c533f

Browse files
Switch to graphql@16.2 (#373)
1 parent 08a4a87 commit d4c533f

File tree

11 files changed

+46
-71
lines changed

11 files changed

+46
-71
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"build": "node resources/build.js"
4141
},
4242
"peerDependencies": {
43-
"graphql": "^15.5.3"
43+
"graphql": "^16.2.0"
4444
},
4545
"devDependencies": {
4646
"@babel/core": "7.15.5",
@@ -61,7 +61,7 @@
6161
"eslint-plugin-istanbul": "0.1.2",
6262
"eslint-plugin-node": "11.1.0",
6363
"flow-bin": "0.159.0",
64-
"graphql": "15.8.0",
64+
"graphql": "16.2.0",
6565
"mocha": "9.1.1",
6666
"nyc": "15.1.0",
6767
"prettier": "2.4.0",

src/__tests__/starWarsSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const { nodeInterface, nodeField } = nodeDefinitions(
116116
return getShip(id);
117117
}
118118
},
119-
(obj) => (obj.ships ? factionType : shipType),
119+
(obj) => (obj.ships ? factionType.name : shipType.name),
120120
);
121121

122122
/**

src/connection/__tests__/connection-test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const userType = new GraphQLObjectType({
5555

5656
const { connectionType: friendConnection } = connectionDefinitions({
5757
name: 'Friend',
58-
// @ts-expect-error
5958
nodeType: new GraphQLNonNull(userType),
6059
resolveNode: (edge) => allUsers[edge.node],
6160
edgeFields: () => ({
@@ -73,7 +72,6 @@ const { connectionType: friendConnection } = connectionDefinitions({
7372
});
7473

7574
const { connectionType: userConnection } = connectionDefinitions({
76-
// @ts-expect-error
7775
nodeType: new GraphQLNonNull(userType),
7876
resolveNode: (edge) => allUsers[edge.node],
7977
});
@@ -184,8 +182,7 @@ describe('connectionDefinition()', () => {
184182
});
185183

186184
it('generates correct types', () => {
187-
// FIXME remove trimEnd after we update to `graphql@16.0.0`
188-
expect(printSchema(schema).trimEnd()).to.deep.equal(dedent`
185+
expect(printSchema(schema)).to.deep.equal(dedent`
189186
type Query {
190187
user: User
191188
}

src/connection/connection.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import {
66
GraphQLString,
77
GraphQLBoolean,
88
getNamedType,
9+
resolveObjMapThunk,
910
} from 'graphql';
1011

1112
import type {
1213
GraphQLNamedOutputType,
1314
GraphQLFieldConfigArgumentMap,
14-
GraphQLFieldConfigMap,
15+
GraphQLFieldConfig,
1516
GraphQLFieldResolver,
16-
Thunk,
17+
ThunkObjMap,
1718
} from 'graphql';
1819

1920
/**
@@ -79,22 +80,15 @@ export interface ConnectionConfig {
7980
nodeType: GraphQLNamedOutputType | GraphQLNonNull<GraphQLNamedOutputType>;
8081
resolveNode?: GraphQLFieldResolver<any, any>;
8182
resolveCursor?: GraphQLFieldResolver<any, any>;
82-
edgeFields?: Thunk<GraphQLFieldConfigMap<any, any>>;
83-
connectionFields?: Thunk<GraphQLFieldConfigMap<any, any>>;
83+
edgeFields?: ThunkObjMap<GraphQLFieldConfig<any, any>>;
84+
connectionFields?: ThunkObjMap<GraphQLFieldConfig<any, any>>;
8485
}
8586

8687
export interface GraphQLConnectionDefinitions {
8788
edgeType: GraphQLObjectType;
8889
connectionType: GraphQLObjectType;
8990
}
9091

91-
function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
92-
return typeof thingOrThunk === 'function'
93-
? // @ts-expect-error - if it's a function, we assume a thunk without arguments
94-
thingOrThunk()
95-
: thingOrThunk;
96-
}
97-
9892
/**
9993
* Returns a GraphQLObjectType for a connection with the given name,
10094
* and whose nodes are of the specified type.
@@ -118,7 +112,7 @@ export function connectionDefinitions(
118112
resolve: config.resolveCursor,
119113
description: 'A cursor for use in pagination',
120114
},
121-
...resolveMaybeThunk(config.edgeFields ?? {}),
115+
...resolveObjMapThunk(config.edgeFields ?? {}),
122116
}),
123117
});
124118

@@ -134,7 +128,7 @@ export function connectionDefinitions(
134128
type: new GraphQLList(edgeType),
135129
description: 'A list of edges.',
136130
},
137-
...resolveMaybeThunk(config.connectionFields ?? {}),
131+
...resolveObjMapThunk(config.connectionFields ?? {}),
138132
}),
139133
});
140134

src/mutation/__tests__/mutation-test.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
GraphQLSchema,
99
graphql,
1010
graphqlSync,
11+
printType,
1112
printSchema,
1213
} from 'graphql';
1314

@@ -48,24 +49,17 @@ describe('mutationWithClientMutationId()', () => {
4849
},
4950
mutateAndGetPayload: dummyResolve,
5051
});
51-
const schema = wrapInSchema({ someMutation });
52-
const source = `
53-
mutation {
54-
someMutation {
55-
result
56-
}
57-
}
58-
`;
5952

60-
expect(graphqlSync({ schema, source })).to.deep.equal({
61-
errors: [
62-
{
63-
message:
64-
'Field "someMutation" argument "input" of type "SomeMutationInput!" is required, but it was not provided.',
65-
locations: [{ line: 3, column: 9 }],
66-
},
67-
],
53+
const wrapperType = new GraphQLObjectType({
54+
name: 'WrapperType',
55+
fields: { someMutation },
6856
});
57+
58+
expect(printType(wrapperType)).to.deep.equal(dedent`
59+
type WrapperType {
60+
someMutation(input: SomeMutationInput!): SomeMutationPayload
61+
}
62+
`);
6963
});
7064

7165
it('returns the same client mutation ID', () => {
@@ -317,8 +311,7 @@ describe('mutationWithClientMutationId()', () => {
317311

318312
const schema = wrapInSchema({ someMutation });
319313

320-
// FIXME remove trimEnd after we update to `graphql@16.0.0`
321-
expect(printSchema(schema).trimEnd()).to.deep.equal(dedent`
314+
expect(printSchema(schema)).to.deep.equal(dedent`
322315
type Query {
323316
dummy: Int
324317
}

src/mutation/mutation.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,19 @@ import {
33
GraphQLNonNull,
44
GraphQLObjectType,
55
GraphQLString,
6+
resolveObjMapThunk,
67
} from 'graphql';
78

89
import type {
910
GraphQLFieldConfig,
1011
GraphQLFieldExtensions,
11-
GraphQLInputFieldConfigMap,
12-
GraphQLFieldConfigMap,
12+
GraphQLInputFieldConfig,
1313
GraphQLResolveInfo,
14-
Thunk,
14+
ThunkObjMap,
1515
} from 'graphql';
1616

1717
type MutationFn = (object: any, ctx: any, info: GraphQLResolveInfo) => unknown;
1818

19-
function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
20-
return typeof thingOrThunk === 'function'
21-
? // @ts-expect-error - if it's a function, we assume a thunk without arguments
22-
thingOrThunk()
23-
: thingOrThunk;
24-
}
25-
2619
/**
2720
* A description of a mutation consumable by mutationWithClientMutationId
2821
* to create a GraphQLFieldConfig for that mutation.
@@ -42,8 +35,8 @@ interface MutationConfig {
4235
description?: string;
4336
deprecationReason?: string;
4437
extensions?: GraphQLFieldExtensions<any, any>;
45-
inputFields: Thunk<GraphQLInputFieldConfigMap>;
46-
outputFields: Thunk<GraphQLFieldConfigMap<any, any>>;
38+
inputFields: ThunkObjMap<GraphQLInputFieldConfig>;
39+
outputFields: ThunkObjMap<GraphQLFieldConfig<any, any>>;
4740
mutateAndGetPayload: MutationFn;
4841
}
4942

@@ -56,13 +49,13 @@ export function mutationWithClientMutationId(
5649
): GraphQLFieldConfig<unknown, unknown> {
5750
const { name, inputFields, outputFields, mutateAndGetPayload } = config;
5851
const augmentedInputFields = () => ({
59-
...resolveMaybeThunk(inputFields),
52+
...resolveObjMapThunk(inputFields),
6053
clientMutationId: {
6154
type: GraphQLString,
6255
},
6356
});
6457
const augmentedOutputFields = () => ({
65-
...resolveMaybeThunk(outputFields),
58+
...resolveObjMapThunk(outputFields),
6659
clientMutationId: {
6760
type: GraphQLString,
6861
},

src/node/__tests__/global-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ const { nodeField, nodeInterface } = nodeDefinitions(
5959
},
6060
(obj) => {
6161
if (obj.name) {
62-
return userType;
62+
return userType.name;
6363
}
6464
if (obj.photoId) {
65-
return photoType;
65+
return photoType.name;
6666
}
6767

6868
// istanbul ignore else (Can't be reached)
6969
if (obj.text) {
70-
return postType;
70+
return postType.name;
7171
}
7272
},
7373
);

src/node/__tests__/node-test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ const { nodeField, nodesField, nodeInterface } = nodeDefinitions(
4848
},
4949
(obj) => {
5050
if (userData.includes(obj)) {
51-
return userType;
51+
return userType.name;
5252
}
5353
// istanbul ignore else (Can't be reached)
5454
if (photoData.includes(obj)) {
55-
return photoType;
55+
return photoType.name;
5656
}
5757
},
5858
);
@@ -315,8 +315,7 @@ describe('Node interface and fields', () => {
315315
});
316316

317317
it('generates correct types', () => {
318-
// FIXME remove trimEnd after we update to `graphql@16.0.0`
319-
expect(printSchema(schema).trimEnd()).to.deep.equal(dedent`
318+
expect(printSchema(schema)).to.deep.equal(dedent`
320319
"""An object with an ID"""
321320
interface Node {
322321
"""The id of the object."""

src/node/__tests__/nodeAsync-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const userData = [
2525

2626
const { nodeField, nodeInterface } = nodeDefinitions(
2727
(id) => userData.find((obj) => obj.id === id),
28-
() => userType,
28+
() => userType.name,
2929
);
3030

3131
const userType: GraphQLObjectType = new GraphQLObjectType({

src/node/__tests__/plural-test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ describe('pluralIdentifyingRootField()', () => {
7878
});
7979

8080
it('generates correct types', () => {
81-
// FIXME remove trimEnd after we update to `graphql@16.0.0`
82-
expect(printSchema(schema).trimEnd()).to.deep.equal(dedent`
81+
expect(printSchema(schema)).to.deep.equal(dedent`
8382
type Query {
8483
"""Map from a username to the user"""
8584
usernames(usernames: [String!]!): [User]

0 commit comments

Comments
 (0)