Skip to content

Commit

Permalink
Add GraphQL 16 to peer dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Nov 1, 2021
1 parent 16b2d51 commit 5761a44
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 65 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
QueryOptions,
makeReference,
} from '../core';
import { Kind } from "graphql";

import { Observable } from '../utilities';
import { ApolloLink } from '../link/core';
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -572,7 +572,7 @@ export class QueryManager<TStore> {
definitions: transformed.definitions.map(def => {
if (def.kind === "OperationDefinition" &&
def.operation !== "query") {
return { ...def, operation: "query" };
return { ...def, operation: "query" as OperationTypeNode };
}
return def;
}),
Expand Down
14 changes: 7 additions & 7 deletions src/link/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export interface Operation {
}

export interface FetchResult<
TData = { [key: string]: any },
C = Record<string, any>,
E = Record<string, any>
> extends ExecutionResult {
data?: TData | null;
extensions?: E;
context?: C;
TData = Record<string, any>,
TContext = Record<string, any>,
TExtensions = Record<string, any>
> extends ExecutionResult<TData, TExtensions> {
data?: TData | null | undefined;
extensions?: TExtensions;
context?: TContext;
};

export type NextLink = (operation: Operation) => Observable<FetchResult>;
Expand Down
8 changes: 4 additions & 4 deletions src/link/http/__tests__/HttpLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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',
);
}),
);
Expand All @@ -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',
);
}),
);
Expand Down
16 changes: 8 additions & 8 deletions src/link/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions src/react/components/__tests__/ssr/server.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/react/hoc/__tests__/queries/errors.test.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
14 changes: 6 additions & 8 deletions src/react/hoc/__tests__/ssr/server.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
]
`;
Expand All @@ -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:
Expand All @@ -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":<undefined>}
Failed to match 1 mock for this query, which had the following variables:
Expand All @@ -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!) {
Expand All @@ -76,7 +73,6 @@ exports[`General use should return "No more mocked responses" errors in response
__typename
}
}
Expected variables: {}
]
`;
Expand All @@ -88,7 +84,6 @@ exports[`General use should support custom error handling using setOnError 1`] =
__typename
}
}
Expected variables: {"username":"mock_username"}
]
`;
2 changes: 1 addition & 1 deletion src/utilities/common/errorHandling.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutionResult } from 'graphql';

export function graphQLResultHasError(result: ExecutionResult): boolean {
export function graphQLResultHasError(result: ExecutionResult<any>): boolean {
return (result.errors && result.errors.length > 0) || false;
}
15 changes: 9 additions & 6 deletions src/utilities/graphql/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
DocumentNode,
FragmentDefinitionNode,
InlineFragmentNode,
SelectionNode
SelectionNode,
Kind,
OperationTypeNode,
} from 'graphql';

/**
Expand Down Expand Up @@ -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,
},
},
Expand Down
5 changes: 3 additions & 2 deletions src/utilities/graphql/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { invariant } from '../globals';

import {
DocumentNode,
Kind,
SelectionNode,
SelectionSetNode,
OperationDefinitionNode,
Expand Down Expand Up @@ -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',
},
};
Expand Down

0 comments on commit 5761a44

Please sign in to comment.