diff --git a/package-lock.json b/package-lock.json index 85f59b81b4f..c4214f11e34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "crypto-hash": "1.3.0", "fetch-mock": "9.11.0", "glob": "7.2.0", - "graphql": "15.6.1", + "graphql": "^16.0.0", "jest": "26.6.3", "jest-fetch-mock": "3.0.3", "jest-junit": "12.3.0", @@ -67,7 +67,7 @@ "npm": "^7.20.3 || ^8.0.0" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0", + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0", "react": "^16.8.0 || ^17.0.0", "subscriptions-transport-ws": "^0.9.0" }, @@ -4713,11 +4713,11 @@ "dev": true }, "node_modules/graphql": { - "version": "15.6.1", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.6.1.tgz", - "integrity": "sha512-3i5lu0z6dRvJ48QP9kFxBkJ7h4Kso7PS8eahyTFz5Jm6CvQfLtNIE8LX9N6JLnXTuwR+sIYnXzaWp6anOg0QQw==", + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.0.0.tgz", + "integrity": "sha512-n9NxoRfwnpYBZB/WJ7L166gyrShuZ8qYgVaX8oxVyELcJfAwkvwPt6WlYIl90WRlzqDjaNWvLmNOSnKs5llZWQ==", "engines": { - "node": ">= 10.x" + "node": "^12.22.0 || ^14.16.0 || >=16.0.0" } }, "node_modules/graphql-tag": { @@ -15718,9 +15718,9 @@ "dev": true }, "graphql": { - "version": "15.6.1", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.6.1.tgz", - "integrity": "sha512-3i5lu0z6dRvJ48QP9kFxBkJ7h4Kso7PS8eahyTFz5Jm6CvQfLtNIE8LX9N6JLnXTuwR+sIYnXzaWp6anOg0QQw==" + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.0.0.tgz", + "integrity": "sha512-n9NxoRfwnpYBZB/WJ7L166gyrShuZ8qYgVaX8oxVyELcJfAwkvwPt6WlYIl90WRlzqDjaNWvLmNOSnKs5llZWQ==" }, "graphql-tag": { "version": "2.12.3", diff --git a/package.json b/package.json index 50892156c60..48fef01673d 100644 --- a/package.json +++ b/package.json @@ -55,14 +55,14 @@ { "name": "apollo-client", "path": "./dist/apollo-client.min.cjs", - "maxSize": "28.25 kB" + "maxSize": "28.3 kB" } ], "engines": { "npm": "^7.20.3 || ^8.0.0" }, "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0", + "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0", "react": "^16.8.0 || ^17.0.0", "subscriptions-transport-ws": "^0.9.0" }, @@ -108,7 +108,7 @@ "crypto-hash": "1.3.0", "fetch-mock": "9.11.0", "glob": "7.2.0", - "graphql": "15.6.1", + "graphql": "^16.0.0", "jest": "26.6.3", "jest-fetch-mock": "3.0.3", "jest-junit": "12.3.0", diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 1c4514b653f..f674a8cbfbf 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -7,6 +7,7 @@ import { QueryOptions, makeReference, } from '../core'; +import { Kind } from "graphql"; import { Observable } from '../utilities'; import { ApolloLink } from '../link/core'; @@ -2241,7 +2242,7 @@ describe('ApolloClient', () => { cache: new InMemoryCache(), defaultOptions: { query: { - query: {kind: 'Document', definitions: []}, + query: {kind: Kind.DOCUMENT, definitions: []}, variables: {foo: 'bar'}, errorPolicy: 'none', context: null, diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 2570cb889db..b3a22c110f9 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -1,6 +1,6 @@ import { invariant, InvariantError } from '../utilities/globals'; -import { DocumentNode } from 'graphql'; +import { DocumentNode, OperationTypeNode } from 'graphql'; import { equal } from '@wry/equality'; import { ApolloLink, execute, FetchResult } from '../link/core'; @@ -572,7 +572,7 @@ export class QueryManager { definitions: transformed.definitions.map(def => { if (def.kind === "OperationDefinition" && def.operation !== "query") { - return { ...def, operation: "query" }; + return { ...def, operation: "query" as OperationTypeNode }; } return def; }), diff --git a/src/link/core/types.ts b/src/link/core/types.ts index 0f99ccd794b..847cf626816 100644 --- a/src/link/core/types.ts +++ b/src/link/core/types.ts @@ -21,13 +21,13 @@ export interface Operation { } export interface FetchResult< - TData = { [key: string]: any }, - C = Record, - E = Record -> extends ExecutionResult { - data?: TData | null; - extensions?: E; - context?: C; + TData = Record, + TContext = Record, + TExtensions = Record +> extends ExecutionResult { + data?: TData | null | undefined; + extensions?: TExtensions; + context?: TContext; }; export type NextLink = (operation: Operation) => Observable; diff --git a/src/link/http/__tests__/HttpLink.ts b/src/link/http/__tests__/HttpLink.ts index ad3bfa1b617..0dbc5ebcf28 100644 --- a/src/link/http/__tests__/HttpLink.ts +++ b/src/link/http/__tests__/HttpLink.ts @@ -126,7 +126,7 @@ describe('HttpLink', () => { expect(body).toBeUndefined(); expect(method).toBe('GET'); expect(uri).toBe( - '/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', + '/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', ); }), error: error => done.fail(error), @@ -148,7 +148,7 @@ describe('HttpLink', () => { expect(body).toBeUndefined(); expect(method).toBe('GET'); expect(uri).toBe( - '/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', + '/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', ); }), error: error => done.fail(error), @@ -174,7 +174,7 @@ describe('HttpLink', () => { expect(body).toBeUndefined(); expect(method).toBe('GET'); expect(uri).toBe( - '/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', + '/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', ); }), ); @@ -197,7 +197,7 @@ describe('HttpLink', () => { expect(body).toBeUndefined(); expect(method).toBe('GET'); expect(uri).toBe( - '/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', + '/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', ); }), ); diff --git a/src/link/schema/index.ts b/src/link/schema/index.ts index 1a8f23837b6..9cda33dd189 100644 --- a/src/link/schema/index.ts +++ b/src/link/schema/index.ts @@ -63,14 +63,14 @@ export class SchemaLink extends ApolloLink { } } - return execute( - this.schema, - operation.query, - this.rootValue, - context, - operation.variables, - operation.operationName, - ) + return execute({ + schema: this.schema, + document: operation.query, + rootValue: this.rootValue, + contextValue: context, + variableValues: operation.variables, + operationName: operation.operationName, + }); }).then(data => { if (!observer.closed) { observer.next(data); diff --git a/src/react/components/__tests__/ssr/server.test.tsx b/src/react/components/__tests__/ssr/server.test.tsx index 7fb8704c0ab..890f8c78188 100644 --- a/src/react/components/__tests__/ssr/server.test.tsx +++ b/src/react/components/__tests__/ssr/server.test.tsx @@ -158,14 +158,12 @@ describe('SSR', () => { const apolloClient = new ApolloClient({ link: new ApolloLink(config => { return new Observable(observer => { - execute( - Schema, - print(config.query), - null, - null, - config.variables, - config.operationName - ) + execute({ + schema: Schema, + source: print(config.query), + variableValues: config.variables, + operationName: config.operationName, + }) .then(result => { observer.next(result); observer.complete(); diff --git a/src/react/hoc/__tests__/queries/errors.test.tsx b/src/react/hoc/__tests__/queries/errors.test.tsx index aed268b9a0e..963d95ca3e8 100644 --- a/src/react/hoc/__tests__/queries/errors.test.tsx +++ b/src/react/hoc/__tests__/queries/errors.test.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; +// @ts-ignore import { withState } from './recomposeWithState.js'; import { DocumentNode } from 'graphql'; diff --git a/src/react/hoc/__tests__/ssr/server.test.tsx b/src/react/hoc/__tests__/ssr/server.test.tsx index f7ba71de7ea..fc001c11283 100644 --- a/src/react/hoc/__tests__/ssr/server.test.tsx +++ b/src/react/hoc/__tests__/ssr/server.test.tsx @@ -110,14 +110,12 @@ describe('SSR', () => { const apolloClient = new ApolloClient({ link: new ApolloLink(config => { return new Observable(observer => { - execute( - Schema, - print(config.query), - null, - null, - config.variables, - config.operationName - ) + execute({ + schema: Schema, + source: print(config.query), + variableValues: config.variables, + operationName: config.operationName + }) .then(result => { observer.next(result); observer.complete(); diff --git a/src/testing/react/__tests__/__snapshots__/MockedProvider.test.tsx.snap b/src/testing/react/__tests__/__snapshots__/MockedProvider.test.tsx.snap index f5819bd6f17..0aae53847b6 100644 --- a/src/testing/react/__tests__/__snapshots__/MockedProvider.test.tsx.snap +++ b/src/testing/react/__tests__/__snapshots__/MockedProvider.test.tsx.snap @@ -14,7 +14,6 @@ exports[`General use should error if the query in the mock and component do not __typename } } - Expected variables: {"username":"mock_username"} ] `; @@ -26,7 +25,6 @@ exports[`General use should error if the variables do not deep equal 1`] = ` __typename } } - Expected variables: {"username":"some_user","age":42} 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 __typename } } - Expected variables: {"username":"other_user","age":} Failed to match 1 mock for this query, which had the following variables: @@ -67,7 +64,7 @@ Object { exports[`General use should pipe exceptions thrown in custom onError functions through the link chain 1`] = `[Error: oh no!]`; -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"}]`; +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}"}]`; exports[`General use should return "No more mocked responses" errors in response 1`] = ` [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 __typename } } - Expected variables: {} ] `; @@ -88,7 +84,6 @@ exports[`General use should support custom error handling using setOnError 1`] = __typename } } - Expected variables: {"username":"mock_username"} ] `; diff --git a/src/utilities/common/errorHandling.ts b/src/utilities/common/errorHandling.ts index fb965009082..39e8950a0df 100644 --- a/src/utilities/common/errorHandling.ts +++ b/src/utilities/common/errorHandling.ts @@ -1,5 +1,5 @@ import { ExecutionResult } from 'graphql'; -export function graphQLResultHasError(result: ExecutionResult): boolean { +export function graphQLResultHasError(result: ExecutionResult): boolean { return (result.errors && result.errors.length > 0) || false; } diff --git a/src/utilities/graphql/fragments.ts b/src/utilities/graphql/fragments.ts index f6ce8f07008..f47dca571ac 100644 --- a/src/utilities/graphql/fragments.ts +++ b/src/utilities/graphql/fragments.ts @@ -4,7 +4,9 @@ import { DocumentNode, FragmentDefinitionNode, InlineFragmentNode, - SelectionNode + SelectionNode, + Kind, + OperationTypeNode, } from 'graphql'; /** @@ -75,15 +77,16 @@ export function getFragmentQueryDocument( ...document, definitions: [ { - kind: 'OperationDefinition', - operation: 'query', + kind: Kind.OPERATION_DEFINITION, + // OperationTypeNode is an enum + operation: 'query' as OperationTypeNode, selectionSet: { - kind: 'SelectionSet', + kind: Kind.SELECTION_SET, selections: [ { - kind: 'FragmentSpread', + kind: Kind.FRAGMENT_SPREAD, name: { - kind: 'Name', + kind: Kind.NAME, value: actualFragmentName, }, }, diff --git a/src/utilities/graphql/transform.ts b/src/utilities/graphql/transform.ts index 2a5128d0524..ca364721694 100644 --- a/src/utilities/graphql/transform.ts +++ b/src/utilities/graphql/transform.ts @@ -2,6 +2,7 @@ import { invariant } from '../globals'; import { DocumentNode, + Kind, SelectionNode, SelectionSetNode, OperationDefinitionNode, @@ -53,9 +54,9 @@ export type RemoveVariableDefinitionConfig = RemoveNodeConfig< >; const TYPENAME_FIELD: FieldNode = { - kind: 'Field', + kind: Kind.FIELD, name: { - kind: 'Name', + kind: Kind.NAME, value: '__typename', }, };