Skip to content

Commit 24799a9

Browse files
committed
Upgrade to graphql 16
1 parent 6b8d13d commit 24799a9

File tree

14 files changed

+4955
-12879
lines changed

14 files changed

+4955
-12879
lines changed

package-lock.json

+4,898-12,825
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"npm": "^7.20.3 || ^8.0.0"
6363
},
6464
"peerDependencies": {
65-
"graphql": "^14.0.0 || ^15.0.0",
65+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
6666
"react": "^16.8.0 || ^17.0.0",
6767
"subscriptions-transport-ws": "^0.9.0"
6868
},
@@ -81,6 +81,7 @@
8181
"@wry/trie": "^0.3.0",
8282
"graphql-tag": "^2.12.3",
8383
"hoist-non-react-statics": "^3.3.2",
84+
"npm": "^7.24.2",
8485
"optimism": "^0.16.1",
8586
"prop-types": "^15.7.2",
8687
"symbol-observable": "^4.0.0",
@@ -108,7 +109,7 @@
108109
"crypto-hash": "1.3.0",
109110
"fetch-mock": "9.11.0",
110111
"glob": "7.2.0",
111-
"graphql": "15.7.2",
112+
"graphql": "^16.0.0",
112113
"jest": "27.3.1",
113114
"jest-fetch-mock": "3.0.3",
114115
"jest-junit": "13.0.0",

src/__tests__/ApolloClient.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
QueryOptions,
88
makeReference,
99
} from '../core';
10+
import { Kind } from "graphql";
1011

1112
import { Observable } from '../utilities';
1213
import { ApolloLink } from '../link/core';
@@ -2241,7 +2242,7 @@ describe('ApolloClient', () => {
22412242
cache: new InMemoryCache(),
22422243
defaultOptions: {
22432244
query: {
2244-
query: {kind: 'Document', definitions: []},
2245+
query: {kind: Kind.DOCUMENT, definitions: []},
22452246
variables: {foo: 'bar'},
22462247
errorPolicy: 'none',
22472248
context: null,

src/core/QueryManager.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { invariant, InvariantError } from '../utilities/globals';
22

33
import { DocumentNode } from 'graphql';
4+
// TODO(brian): A hack until this issue is resolved (https://github.com/graphql/graphql-js/issues/3356)
5+
type OperationTypeNode = any;
46
import { equal } from '@wry/equality';
57

68
import { ApolloLink, execute, FetchResult } from '../link/core';
@@ -572,7 +574,7 @@ export class QueryManager<TStore> {
572574
definitions: transformed.definitions.map(def => {
573575
if (def.kind === "OperationDefinition" &&
574576
def.operation !== "query") {
575-
return { ...def, operation: "query" };
577+
return { ...def, operation: "query" as OperationTypeNode };
576578
}
577579
return def;
578580
}),

src/link/core/types.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export interface Operation {
2121
}
2222

2323
export interface FetchResult<
24-
TData = { [key: string]: any },
25-
C = Record<string, any>,
26-
E = Record<string, any>
27-
> extends ExecutionResult {
28-
data?: TData | null;
29-
extensions?: E;
30-
context?: C;
24+
TData = Record<string, any>,
25+
TContext = Record<string, any>,
26+
TExtensions = Record<string, any>
27+
> extends ExecutionResult<TData, TExtensions> {
28+
data?: TData | null | undefined;
29+
extensions?: TExtensions;
30+
context?: TContext;
3131
};
3232

3333
export type NextLink = (operation: Operation) => Observable<FetchResult>;

src/link/http/__tests__/HttpLink.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('HttpLink', () => {
130130
expect(body).toBeUndefined();
131131
expect(method).toBe('GET');
132132
expect(uri).toBe(
133-
'/data?query=query%20SampleQuery%20%7B%0A%20%20stub%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D%0A&operationName=SampleQuery&variables=%7B%22params%22%3A%22stub%22%7D&extensions=%7B%22myExtension%22%3A%22foo%22%7D',
133+
'/data?query=query%20SampleQuery%20%7B%0A%20%20stub%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D&operationName=SampleQuery&variables=%7B%22params%22%3A%22stub%22%7D&extensions=%7B%22myExtension%22%3A%22foo%22%7D',
134134
);
135135
}),
136136
error: error => reject(error),
@@ -152,7 +152,7 @@ describe('HttpLink', () => {
152152
expect(body).toBeUndefined();
153153
expect(method).toBe('GET');
154154
expect(uri).toBe(
155-
'/data?foo=bar&query=query%20SampleQuery%20%7B%0A%20%20stub%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D%0A&operationName=SampleQuery&variables=%7B%7D',
155+
'/data?foo=bar&query=query%20SampleQuery%20%7B%0A%20%20stub%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D&operationName=SampleQuery&variables=%7B%7D',
156156
);
157157
}),
158158
error: error => reject(error),
@@ -178,7 +178,7 @@ describe('HttpLink', () => {
178178
expect(body).toBeUndefined();
179179
expect(method).toBe('GET');
180180
expect(uri).toBe(
181-
'/data?query=query%20SampleQuery%20%7B%0A%20%20stub%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D%0A&operationName=SampleQuery&variables=%7B%7D',
181+
'/data?query=query%20SampleQuery%20%7B%0A%20%20stub%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D&operationName=SampleQuery&variables=%7B%7D',
182182
);
183183
}),
184184
);
@@ -201,7 +201,7 @@ describe('HttpLink', () => {
201201
expect(body).toBeUndefined();
202202
expect(method).toBe('GET');
203203
expect(uri).toBe(
204-
'/data?query=query%20SampleQuery%20%7B%0A%20%20stub%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D%0A&operationName=SampleQuery&variables=%7B%7D',
204+
'/data?query=query%20SampleQuery%20%7B%0A%20%20stub%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D&operationName=SampleQuery&variables=%7B%7D',
205205
);
206206
}),
207207
);

src/link/schema/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ export class SchemaLink extends ApolloLink {
6363
}
6464
}
6565

66-
return execute(
67-
this.schema,
68-
operation.query,
69-
this.rootValue,
70-
context,
71-
operation.variables,
72-
operation.operationName,
73-
)
66+
return execute({
67+
schema: this.schema,
68+
document: operation.query,
69+
rootValue: this.rootValue,
70+
contextValue: context,
71+
variableValues: operation.variables,
72+
operationName: operation.operationName,
73+
});
7474
}).then(data => {
7575
if (!observer.closed) {
7676
observer.next(data);

src/react/components/__tests__/ssr/server.test.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,12 @@ describe('SSR', () => {
158158
const apolloClient = new ApolloClient({
159159
link: new ApolloLink(config => {
160160
return new Observable(observer => {
161-
execute(
162-
Schema,
163-
print(config.query),
164-
null,
165-
null,
166-
config.variables,
167-
config.operationName
168-
)
161+
execute({
162+
schema: Schema,
163+
source: print(config.query),
164+
variableValues: config.variables,
165+
operationName: config.operationName,
166+
})
169167
.then(result => {
170168
observer.next(result);
171169
observer.complete();

src/react/hoc/__tests__/queries/errors.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { render, wait } from '@testing-library/react';
33
import gql from 'graphql-tag';
4+
// @ts-ignore
45
import { withState } from './recomposeWithState.js';
56
import { DocumentNode } from 'graphql';
67

src/react/hoc/__tests__/ssr/server.test.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,12 @@ describe('SSR', () => {
110110
const apolloClient = new ApolloClient({
111111
link: new ApolloLink(config => {
112112
return new Observable(observer => {
113-
execute(
114-
Schema,
115-
print(config.query),
116-
null,
117-
null,
118-
config.variables,
119-
config.operationName
120-
)
113+
execute({
114+
schema: Schema,
115+
source: print(config.query),
116+
variableValues: config.variables,
117+
operationName: config.operationName
118+
})
121119
.then(result => {
122120
observer.next(result);
123121
observer.complete();

src/testing/react/__tests__/__snapshots__/MockedProvider.test.tsx.snap

+1-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ exports[`General use should error if the query in the mock and component do not
1414
__typename
1515
}
1616
}
17-
1817
Expected variables: {"username":"mock_username"}
1918
]
2019
`;
@@ -26,7 +25,6 @@ exports[`General use should error if the variables do not deep equal 1`] = `
2625
__typename
2726
}
2827
}
29-
3028
Expected variables: {"username":"some_user","age":42}
3129
3230
Failed to match 1 mock for this query, which had the following variables:
@@ -41,7 +39,6 @@ exports[`General use should error if the variables in the mock and component do
4139
__typename
4240
}
4341
}
44-
4542
Expected variables: {"username":"other_user","age":<undefined>}
4643
4744
Failed to match 1 mock for this query, which had the following variables:
@@ -67,7 +64,7 @@ Object {
6764
6865
exports[`General use should pipe exceptions thrown in custom onError functions through the link chain 1`] = `[Error: oh no!]`;
6966
70-
exports[`General use should return "Mocked response should contain" errors in response 1`] = `[Error: Mocked response should contain either result or error: {"query":"query GetUser($username: String!) {\\n user(username: $username) {\\n id\\n __typename\\n }\\n}\\n"}]`;
67+
exports[`General use should return "Mocked response should contain" errors in response 1`] = `[Error: Mocked response should contain either result or error: {"query":"query GetUser($username: String!) {\\n user(username: $username) {\\n id\\n __typename\\n }\\n}"}]`;
7168
7269
exports[`General use should return "No more mocked responses" errors in response 1`] = `
7370
[Error: No more mocked responses for the query: query GetUser($username: String!) {
@@ -76,7 +73,6 @@ exports[`General use should return "No more mocked responses" errors in response
7673
__typename
7774
}
7875
}
79-
8076
Expected variables: {}
8177
]
8278
`;
@@ -88,7 +84,6 @@ exports[`General use should support custom error handling using setOnError 1`] =
8884
__typename
8985
}
9086
}
91-
9287
Expected variables: {"username":"mock_username"}
9388
]
9489
`;

src/utilities/common/errorHandling.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ExecutionResult } from 'graphql';
22

3-
export function graphQLResultHasError(result: ExecutionResult): boolean {
3+
export function graphQLResultHasError(result: ExecutionResult<unknown>): boolean {
44
return (result.errors && result.errors.length > 0) || false;
55
}

src/utilities/graphql/fragments.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import {
44
DocumentNode,
55
FragmentDefinitionNode,
66
InlineFragmentNode,
7-
SelectionNode
7+
SelectionNode,
8+
OperationTypeNode,
89
} from 'graphql';
910

11+
// TODO(brian): A hack until this issue is resolved (https://github.com/graphql/graphql-js/issues/3356)
12+
type Kind = any;
1013
/**
1114
* Returns a query document which adds a single query operation that only
1215
* spreads the target fragment inside of it.
@@ -75,15 +78,16 @@ export function getFragmentQueryDocument(
7578
...document,
7679
definitions: [
7780
{
78-
kind: 'OperationDefinition',
79-
operation: 'query',
81+
kind: 'OperationDefinition' as Kind,
82+
// OperationTypeNode is an enum
83+
operation: 'query' as OperationTypeNode,
8084
selectionSet: {
81-
kind: 'SelectionSet',
85+
kind: 'SelectionSet' as Kind,
8286
selections: [
8387
{
84-
kind: 'FragmentSpread',
88+
kind: 'FragmentSpread' as Kind,
8589
name: {
86-
kind: 'Name',
90+
kind: 'Name' as Kind,
8791
value: actualFragmentName,
8892
},
8993
},

src/utilities/graphql/transform.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import {
1515
visit,
1616
} from 'graphql';
1717

18+
// TODO(brian): A hack until this issue is resolved (https://github.com/graphql/graphql-js/issues/3356)
19+
type Kind = any;
20+
1821
import {
1922
checkDocument,
2023
getOperationDefinition,
@@ -53,9 +56,9 @@ export type RemoveVariableDefinitionConfig = RemoveNodeConfig<
5356
>;
5457

5558
const TYPENAME_FIELD: FieldNode = {
56-
kind: 'Field',
59+
kind: 'Field' as Kind,
5760
name: {
58-
kind: 'Name',
61+
kind: 'Name' as Kind,
5962
value: '__typename',
6063
},
6164
};

0 commit comments

Comments
 (0)