Skip to content

Commit

Permalink
Avoid importing graphql/language/printer in apollo-client.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Jan 17, 2019
1 parent b4cfd4d commit 70c4cf3
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 25 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,12 @@

## Apollo Client (vNext)

### Apollo Client (vNext)

- The `apollo-client` package no longer exports a `printAST` function from
`graphql/language/printer`. If you need this functionality, import it
directly: `import { print } from "graphql/language/printer"`

## Apollo Client (2.4.9)

### Apollo Client (2.4.9)
Expand Down Expand Up @@ -71,8 +77,6 @@
[@PowerKiKi](https://github.com/PowerKiKi) in [#3693](https://github.com/apollographql/apollo-client/pull/3693) <br/>
[@nandito](https://github.com/nandito) in [#3865](https://github.com/apollographql/apollo-client/pull/3865)

### Apollo Utilities (1.0.27)

- Schema/AST tranformation utilities have been updated to work properly with
`@client` directives. <br/>
[@justinmakaila](https://github.com/justinmakaila) in [#3482](https://github.com/apollographql/apollo-client/pull/3482)
Expand Down
1 change: 0 additions & 1 deletion packages/apollo-client/rollup.config.js
Expand Up @@ -3,7 +3,6 @@ import build, { globals } from '../../config/rollup.config';
const globalsOverride = {
...globals,
'symbol-observable': '$$observable',
'graphql/language/printer': 'print',
};

export default build('apollo.core', {
Expand Down
11 changes: 0 additions & 11 deletions packages/apollo-client/src/__tests__/client.ts
@@ -1,7 +1,6 @@
import { cloneDeep, assign } from 'lodash';
import { GraphQLError, ExecutionResult, DocumentNode } from 'graphql';
import gql from 'graphql-tag';
import { print } from 'graphql/language/printer';
import { ApolloLink, Observable } from 'apollo-link';
import {
InMemoryCache,
Expand Down Expand Up @@ -1992,16 +1991,6 @@ describe('client', () => {
});
});

it('should expose a method called printAST that is prints graphql queries', () => {
const query = gql`
query {
fortuneCookie
}
`;

expect(printAST(query)).toBe(print(query));
});

it('should pass a network error correctly on a mutation', done => {
const mutation = gql`
mutation {
Expand Down
6 changes: 2 additions & 4 deletions packages/apollo-client/src/core/QueryManager.ts
@@ -1,6 +1,5 @@
import { execute, ApolloLink, FetchResult } from 'apollo-link';
import { ExecutionResult, DocumentNode } from 'graphql';
import { print } from 'graphql/language/printer';
import { DedupLink as Deduplicator } from 'apollo-link-dedup';
import { Cache } from 'apollo-cache';
import {
Expand Down Expand Up @@ -145,7 +144,6 @@ export class QueryManager<TStore> {
getDefaultValues(getMutationDefinition(mutation)),
variables,
));
const mutationString = print(mutation);

this.setQuery(mutationId, () => ({ document: mutation }));

Expand All @@ -169,7 +167,7 @@ export class QueryManager<TStore> {
return ret;
};

this.mutationStore.initMutation(mutationId, mutationString, variables);
this.mutationStore.initMutation(mutationId, mutation, variables);

this.dataStore.markMutationInit({
mutationId,
Expand Down Expand Up @@ -534,7 +532,7 @@ export class QueryManager<TStore> {
console.info(
'An unhandled error was thrown because no error handler is registered ' +
'for the query ' +
print(queryStoreValue.document),
JSON.stringify(queryStoreValue.document),
);
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/apollo-client/src/data/mutations.ts
@@ -1,3 +1,5 @@
import { DocumentNode } from 'graphql';

export class MutationStore {
private store: { [mutationId: string]: MutationStoreValue } = {};

Expand All @@ -11,11 +13,11 @@ export class MutationStore {

public initMutation(
mutationId: string,
mutationString: string,
mutation: DocumentNode,
variables: Object | undefined,
) {
this.store[mutationId] = {
mutationString: mutationString,
mutation,
variables: variables || {},
loading: true,
error: null,
Expand Down Expand Up @@ -50,7 +52,7 @@ export class MutationStore {
}

export interface MutationStoreValue {
mutationString: string;
mutation: DocumentNode;
variables: Object;
loading: boolean;
error: Error | null;
Expand Down
3 changes: 1 addition & 2 deletions packages/apollo-client/src/data/queries.ts
@@ -1,5 +1,4 @@
import { DocumentNode, GraphQLError, ExecutionResult } from 'graphql';
import { print } from 'graphql/language/printer';
import { isEqual } from 'apollo-utilities';

import { NetworkStatus } from '../core/networkStatus';
Expand Down Expand Up @@ -40,7 +39,7 @@ export class QueryStore {
if (
previousQuery &&
previousQuery.document !== query.document &&
print(previousQuery.document) !== print(query.document)
!isEqual(previousQuery.document, query.document)
) {
// XXX we're throwing an error here to catch bugs where a query gets overwritten by a new one.
// we should implement a separate action for refetching so that QUERY_INIT may never overwrite
Expand Down
2 changes: 0 additions & 2 deletions packages/apollo-client/src/index.ts
@@ -1,5 +1,3 @@
export { print as printAST } from 'graphql/language/printer';

export {
ObservableQuery,
FetchMoreOptions,
Expand Down

0 comments on commit 70c4cf3

Please sign in to comment.