Skip to content

Commit fc9dde8

Browse files
authored
Revert "[Apollo] Update packages to latest (#413)" (#414)
This reverts commit ea0d95c.
1 parent d45733e commit fc9dde8

26 files changed

+313
-197
lines changed

Diff for: packages/apollo/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Provides out of the box support for GraphQL, powered by [Apollo](https://www.apo
66
yarn add @airbnb/lunar-apollo
77
```
88

9+
This package relies on GraphQL related packages to also be installed.
10+
11+
```bash static
12+
yarn add graphql graphql-tag
13+
```
14+
915
## Setup
1016

1117
Initialize the package to create an Apollo client. The following option settings may be passed to

Diff for: packages/apollo/package.json

+15-4
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,29 @@
1919
},
2020
"peerDependencies": {
2121
"@airbnb/lunar": "^3.0.0",
22-
"graphql": "^15.5.0",
23-
"react": "^16.8.0"
22+
"graphql": "^14.1.0",
23+
"graphql-tag": "^2.10.0",
24+
"react": "^16.8.0",
25+
"react-apollo": "^3.0.0"
2426
},
2527
"devDependencies": {
2628
"@airbnb/lunar-test-utils": "^3.0.2",
27-
"graphql": "^15.5.0",
29+
"@apollo/react-testing": "^3.1.3",
30+
"graphql": "^14.6.0",
31+
"graphql-tag": "^2.10.3",
2832
"react": "^16.13.0",
33+
"react-apollo": "^3.1.3",
2934
"react-test-renderer": "^16.13.1"
3035
},
3136
"dependencies": {
32-
"@apollo/client": "^3.3.12",
3337
"@types/lodash": "*",
38+
"apollo-cache": "^1.3.4",
39+
"apollo-cache-inmemory": "^1.6.5",
40+
"apollo-client": "^2.6.8",
41+
"apollo-link": "^1.2.13",
42+
"apollo-link-error": "^1.1.12",
43+
"apollo-link-http": "^1.5.16",
44+
"apollo-utilities": "^1.3.3",
3445
"lodash": "^4.17.15"
3546
}
3647
}

Diff for: packages/apollo/src/components/Mutation/index.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import React from 'react';
2-
import { MutationResult, MutationFunction, OperationVariables, ApolloError } from '@apollo/client';
32
import {
43
Mutation as BaseMutation,
54
MutationComponentOptions,
6-
} from '@apollo/client/react/components';
5+
MutationResult,
6+
MutationFunction,
7+
OperationVariables,
8+
} from 'react-apollo';
9+
import { ApolloError } from 'apollo-client';
710
import ErrorMessage from '@airbnb/lunar/lib/components/ErrorMessage';
811
import Loader from '@airbnb/lunar/lib/components/Loader';
912
import renderElementOrFunction, {

Diff for: packages/apollo/src/components/Mutation/story.tsx

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
2-
import { gql, MutationFunction } from '@apollo/client';
2+
import gql from 'graphql-tag';
33
import Button from '@airbnb/lunar/lib/components/Button';
44
import Shimmer from '@airbnb/lunar/lib/components/Shimmer';
55
import ErrorMessage from '@airbnb/lunar/lib/components/ErrorMessage';
6-
import { MockedProvider } from '@apollo/client/testing';
6+
import { MutationFunction } from 'react-apollo';
7+
import { MockedProvider } from '@apollo/react-testing';
78
import Mutation from '.';
89

910
const MUTATION = gql`
@@ -108,11 +109,7 @@ customLoadingComponent.story = {
108109
export function customErrorComponent() {
109110
return (
110111
<MockedProvider mocks={[errorMock]} addTypename={false}>
111-
<Mutation
112-
mutation={MUTATION}
113-
variables={variables}
114-
error={(error) => <ErrorMessage error={error} />}
115-
>
112+
<Mutation mutation={MUTATION} error={(error) => <ErrorMessage error={error} />}>
116113
{(updateUser) => <UpdateButton onUpdate={updateUser} />}
117114
</Mutation>
118115
</MockedProvider>

Diff for: packages/apollo/src/components/Provider/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { ApolloProvider } from '@apollo/client';
2+
import { ApolloProvider } from 'react-apollo';
33
import Apollo from '../..';
44

55
export type ProviderProps = {

Diff for: packages/apollo/src/components/Query/index.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React from 'react';
2-
import { QueryResult, OperationVariables, ApolloError } from '@apollo/client';
3-
import { Query as BaseQuery, QueryComponentOptions } from '@apollo/client/react/components';
2+
import {
3+
Query as BaseQuery,
4+
QueryComponentOptions,
5+
QueryResult,
6+
OperationVariables,
7+
} from 'react-apollo';
8+
import { ApolloError } from 'apollo-client';
49
import ErrorMessage from '@airbnb/lunar/lib/components/ErrorMessage';
510
import Loader from '@airbnb/lunar/lib/components/Loader';
611
import renderElementOrFunction, {

Diff for: packages/apollo/src/components/Query/story.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import Shimmer from '@airbnb/lunar/lib/components/Shimmer';
33
import ErrorMessage from '@airbnb/lunar/lib/components/ErrorMessage';
4-
import { MockedProvider } from '@apollo/client/testing';
5-
import { gql } from '@apollo/client';
4+
import { MockedProvider } from '@apollo/react-testing';
5+
import gql from 'graphql-tag';
66
import Query from '.';
77

88
const QUERY = gql`

Diff for: packages/apollo/src/hooks/useMutation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { useMutation } from '@apollo/client';
1+
import { useMutation } from 'react-apollo';
22

33
export default useMutation;

Diff for: packages/apollo/src/hooks/useQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { useQuery } from '@apollo/client';
1+
import { useQuery } from 'react-apollo';
22

33
export default useQuery;

Diff for: packages/apollo/src/hooks/useSubscription.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { useSubscription } from '@apollo/client';
1+
import { useSubscription } from 'react-apollo';
22

33
export default useSubscription;

Diff for: packages/apollo/src/index.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import Core from '@airbnb/lunar';
2-
import {
3-
ApolloClient,
4-
ApolloClientOptions,
5-
InMemoryCache,
6-
InMemoryCacheConfig,
7-
ApolloLink,
8-
HttpLink,
9-
} from '@apollo/client';
10-
import { onError } from '@apollo/client/link/error';
2+
import { ApolloClient, ApolloClientOptions } from 'apollo-client';
3+
import { InMemoryCache, InMemoryCacheConfig } from 'apollo-cache-inmemory';
4+
import { ApolloLink } from 'apollo-link';
5+
import { onError } from 'apollo-link-error';
6+
import { HttpLink } from 'apollo-link-http';
117
import Mutation from './components/Mutation';
128
import Query from './components/Query';
139
import Provider from './components/Provider';
1410
// @ts-ignore
1511
import pkg from '../package.json';
1612

17-
export * from '@apollo/client';
13+
export * from 'apollo-client';
14+
export * from 'apollo-cache-inmemory';
1815

1916
export { onError, HttpLink, Mutation, Query, Provider };
2017

Diff for: packages/apollo/src/updaters/addToList.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { DocumentNode } from 'graphql';
2-
import { get, set } from 'lodash/fp';
3-
import { DataProxy, MutationResult } from '@apollo/client';
2+
import get from 'lodash/get';
3+
import set from 'lodash/set';
4+
import { DataProxy } from 'apollo-cache';
5+
import { MutationFetchResult } from 'react-apollo';
46
import prepareQuery from '../utils/prepareQuery';
57
import getQueryName from '../utils/getQueryName';
68

79
export default function addToList<Result, Vars = {}>(
8-
docOrQuery: DocumentNode | DataProxy.Query<Vars, Result>,
10+
docOrQuery: DocumentNode | DataProxy.Query<Vars>,
911
listPath: string,
1012
mutationPath: string,
1113
) {
12-
const query = prepareQuery<Result, Vars>(docOrQuery);
14+
const query = prepareQuery<Vars>(docOrQuery);
1315

14-
return (cache: DataProxy, mutationResult: MutationResult<Result>) => {
16+
return (cache: DataProxy, mutationResult: MutationFetchResult<Result>) => {
1517
const queryResult = cache.readQuery<Result>(query);
16-
const list = get(listPath, queryResult);
18+
const nextResult = { ...queryResult };
19+
const list = get(queryResult, listPath);
1720

1821
if (typeof list === 'undefined' || !Array.isArray(list)) {
1922
if (__DEV__) {
@@ -23,7 +26,7 @@ export default function addToList<Result, Vars = {}>(
2326
}
2427
}
2528

26-
const data = get(mutationPath, mutationResult);
29+
const data = get(mutationResult.data, mutationPath);
2730

2831
if (typeof data === 'undefined') {
2932
if (__DEV__) {
@@ -33,7 +36,7 @@ export default function addToList<Result, Vars = {}>(
3336
}
3437
}
3538

36-
const nextResult = set(listPath, [...list, data], { ...queryResult });
39+
set(nextResult, listPath, [...list, data]);
3740

3841
cache.writeQuery({
3942
...query,

Diff for: packages/apollo/src/updaters/removeFromList.ts

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import { DocumentNode } from 'graphql';
2-
import { get, set } from 'lodash/fp';
3-
import { DataProxy, ApolloCache, StoreObject } from '@apollo/client';
2+
import get from 'lodash/get';
3+
import set from 'lodash/set';
4+
import { DataProxy } from 'apollo-cache';
45
import prepareQuery from '../utils/prepareQuery';
56
import getQueryName from '../utils/getQueryName';
67

78
export default function removeFromList<Result, Vars = {}>(
8-
docOrQuery: DocumentNode | DataProxy.Query<Vars, Result>,
9+
docOrQuery: DocumentNode | DataProxy.Query<Vars>,
910
listPath: string,
1011
id: string | number,
1112
idName: string = 'id',
1213
) {
13-
const query = prepareQuery<Result, Vars>(docOrQuery);
14+
const query = prepareQuery<Vars>(docOrQuery);
1415

15-
return (cache: ApolloCache<Result>) => {
16+
return (cache: DataProxy) => {
1617
const queryResult = cache.readQuery<Result>(query);
17-
const list = get(listPath, queryResult);
18+
const nextResult = { ...queryResult };
19+
const list = get(queryResult, listPath);
1820

1921
if (typeof list === 'undefined' || !Array.isArray(list)) {
2022
if (__DEV__) {
@@ -24,19 +26,10 @@ export default function removeFromList<Result, Vars = {}>(
2426
}
2527
}
2628

27-
const rootItem = listPath.split('.')[0];
28-
// @ts-ignore
29-
const resultRoot = queryResult[rootItem] as StoreObject;
30-
// Evict cache before writeQuery: https://github.com/apollographql/apollo-client/issues/6451
31-
cache.evict({
32-
id: cache.identify(resultRoot),
33-
broadcast: false,
34-
});
35-
36-
const nextResult = set(
29+
set(
30+
nextResult,
3731
listPath,
3832
list.filter((item) => (item as { [key: string]: unknown })[idName] !== id),
39-
{ ...queryResult },
4033
);
4134

4235
cache.writeQuery({

Diff for: packages/apollo/src/utils/prepareQuery.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { DocumentNode } from 'graphql';
2-
import { DataProxy } from '@apollo/client';
2+
import { DataProxy } from 'apollo-cache';
33

4-
export default function prepareQuery<Result, Vars = {}>(
5-
docOrQuery: DocumentNode | DataProxy.Query<Vars, Result>,
6-
): DataProxy.Query<Vars, Result> {
4+
export default function prepareQuery<Vars = {}>(
5+
docOrQuery: DocumentNode | DataProxy.Query<Vars>,
6+
): DataProxy.Query<Vars> {
77
const query = docOrQuery;
88

99
if ((query as DocumentNode).kind) {
10-
return { query } as DataProxy.Query<Vars, Result>;
10+
return { query } as DataProxy.Query<Vars>;
1111
}
1212

13-
return query as DataProxy.Query<Vars, Result>;
13+
return query as DataProxy.Query<Vars>;
1414
}

Diff for: packages/apollo/test/components/Mutation.test.tsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
2-
import { gql, MutationResult, MutationFunction } from '@apollo/client';
2+
import { MutationResult, MutationFunction } from 'react-apollo';
33
import { mount } from 'enzyme';
4+
import gql from 'graphql-tag';
45
import { WrappingComponent } from '@airbnb/lunar-test-utils';
56
import Loader from '@airbnb/lunar/lib/components/Loader';
67
import ErrorMessage from '@airbnb/lunar/lib/components/ErrorMessage';
7-
import { MockedProvider, MockedResponse } from '@apollo/client/testing';
8+
import { MockedProvider, MockedResponse, wait } from '@apollo/react-testing';
89
import Mutation from '../../src/components/Mutation';
9-
import { wait } from '../utils';
1010

1111
const MUTATION = gql`
1212
mutation updateSomething($id: Int!, $name: String!) {
@@ -31,13 +31,8 @@ function ApolloComponent({
3131
);
3232
}
3333

34-
type Variables = {
35-
id: number;
36-
name: string;
37-
};
38-
3934
describe('Mutation', () => {
40-
const childHandler = (mutate: MutationFunction<unknown, Variables>) => (
35+
const childHandler = (mutate: MutationFunction<unknown, {}>) => (
4136
<button type="button" onClick={() => mutate({ variables: { id: 123, name: 'Something' } })}>
4237
Submit
4338
</button>

Diff for: packages/apollo/test/components/Provider.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { mountWithStyles, WrappingComponent } from '@airbnb/lunar-test-utils';
3-
import { ApolloProvider } from '@apollo/client';
3+
import { ApolloProvider } from 'react-apollo';
44
import Apollo from '../../src';
55
import Provider from '../../src/components/Provider';
66

Diff for: packages/apollo/test/components/Query.test.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
3-
import { gql } from '@apollo/client';
3+
import gql from 'graphql-tag';
44
import { WrappingComponent } from '@airbnb/lunar-test-utils';
55
import Loader from '@airbnb/lunar/lib/components/Loader';
66
import ErrorMessage from '@airbnb/lunar/lib/components/ErrorMessage';
7-
import { MockedProvider, MockedResponse } from '@apollo/client/testing';
7+
import { MockedProvider, MockedResponse, wait } from '@apollo/react-testing';
88
import Query from '../../src/components/Query';
9-
import { wait } from '../utils';
109

1110
const QUERY = gql`
1211
query getSomething {

Diff for: packages/apollo/test/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApolloClient } from '@apollo/client';
1+
import ApolloClient from 'apollo-client';
22
import Apollo, { Settings, HttpLink } from '../src';
33

44
describe('Apollo', () => {

Diff for: packages/apollo/test/updaters/__snapshots__/addToList.test.ts.snap

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ exports[`addToList() errors if mutation data does not exist 1`] = `"Cannot find
44

55
exports[`addToList() errors if property name is not an array 1`] = `"\\"getSomething\\" list \\"something.name\\" is not an array."`;
66

7-
exports[`addToList() errors if query does not exist in cache 1`] = `"\\"otherQuery\\" list \\"something.things\\" is not an array."`;
7+
exports[`addToList() errors if query does not exist in cache 1`] = `
8+
"Can't find field things on object {
9+
\\"something\\": {
10+
\\"type\\": \\"id\\",
11+
\\"generated\\": false,
12+
\\"id\\": \\"something:123\\",
13+
\\"typename\\": \\"something\\"
14+
}
15+
}."
16+
`;

Diff for: packages/apollo/test/updaters/__snapshots__/removeFromList.test.ts.snap

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,13 @@
22

33
exports[`removeFromList() errors if property name is not an array 1`] = `"\\"getSomething\\" list \\"something.name\\" is not an array."`;
44

5-
exports[`removeFromList() errors if query does not exist in cache 1`] = `"\\"otherQuery\\" list \\"things\\" is not an array."`;
5+
exports[`removeFromList() errors if query does not exist in cache 1`] = `
6+
"Can't find field things on object {
7+
\\"something\\": {
8+
\\"type\\": \\"id\\",
9+
\\"generated\\": false,
10+
\\"id\\": \\"something:123\\",
11+
\\"typename\\": \\"something\\"
12+
}
13+
}."
14+
`;

0 commit comments

Comments
 (0)