From 8a334f7381e57ff0c7ca6569abfe10828853deae Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 19 Oct 2020 13:29:01 -0400 Subject: [PATCH] Avoid all sub-package imports from graphql package. Since we don't control the contents of this package, and nested subdirectories within the graphql package do not have their own package.json files with "main" and "module" entry points (like our `@apollo/client/*` sub-packages do), it is unfortunately not safe to reach into the package to import specific items, as demonstrated by #7184. This could cause a bundle size regression for bundlers that do not perform any tree-shaking, but it's the responsibility of the graphql package maintainers to support selective sub-package imports if they want to. Until that happens, @apollo/client must import from the graphql package in the only supported way: directly from the top-level package. --- src/__tests__/local-state/export.ts | 2 +- src/__tests__/local-state/general.ts | 3 +-- src/cache/inmemory/policies.ts | 2 +- src/core/LocalState.ts | 3 ++- src/link/batch/__tests__/batchLink.ts | 2 +- src/link/core/__tests__/ApolloLink.ts | 2 +- src/link/core/types.ts | 3 +-- src/link/http/selectHttpOptionsAndBody.ts | 2 +- src/link/persisted-queries/index.ts | 2 +- src/utilities/graphql/__tests__/fragments.ts | 2 +- src/utilities/graphql/__tests__/getFromAST.ts | 2 +- src/utilities/graphql/__tests__/transform.ts | 2 +- src/utilities/graphql/directives.ts | 3 +-- src/utilities/graphql/transform.ts | 2 +- src/utilities/testing/mocking/mockLink.ts | 2 +- 15 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/__tests__/local-state/export.ts b/src/__tests__/local-state/export.ts index 45eac6ace1f..a9e14a3a3c0 100644 --- a/src/__tests__/local-state/export.ts +++ b/src/__tests__/local-state/export.ts @@ -1,5 +1,5 @@ import gql from 'graphql-tag'; -import { print } from 'graphql/language/printer'; +import { print } from 'graphql'; import { Observable } from '../../utilities'; import { itAsync } from '../../testing'; diff --git a/src/__tests__/local-state/general.ts b/src/__tests__/local-state/general.ts index 5537f1bc011..4c442f6b6ed 100644 --- a/src/__tests__/local-state/general.ts +++ b/src/__tests__/local-state/general.ts @@ -1,6 +1,5 @@ import gql from 'graphql-tag'; -import { DocumentNode, GraphQLError } from 'graphql'; -import { getIntrospectionQuery } from 'graphql/utilities'; +import { DocumentNode, GraphQLError, getIntrospectionQuery } from 'graphql'; import { Observable } from '../../utilities'; import { ApolloLink } from '../../link/core'; diff --git a/src/cache/inmemory/policies.ts b/src/cache/inmemory/policies.ts index d36974b0845..7b9275761c7 100644 --- a/src/cache/inmemory/policies.ts +++ b/src/cache/inmemory/policies.ts @@ -3,7 +3,7 @@ import { FragmentDefinitionNode, SelectionSetNode, FieldNode, -} from "graphql"; +} from 'graphql'; import { KeyTrie } from 'optimism'; import { invariant, InvariantError } from 'ts-invariant'; diff --git a/src/core/LocalState.ts b/src/core/LocalState.ts index 680b8d92f3d..e21226e0e8a 100644 --- a/src/core/LocalState.ts +++ b/src/core/LocalState.ts @@ -7,8 +7,9 @@ import { FragmentDefinitionNode, FieldNode, ASTNode, + visit, + BREAK, } from 'graphql'; -import { visit, BREAK } from 'graphql/language/visitor'; import { invariant } from 'ts-invariant'; import { ApolloCache } from '../cache'; diff --git a/src/link/batch/__tests__/batchLink.ts b/src/link/batch/__tests__/batchLink.ts index c7c7a6ec8cf..5c993371743 100644 --- a/src/link/batch/__tests__/batchLink.ts +++ b/src/link/batch/__tests__/batchLink.ts @@ -1,5 +1,5 @@ import gql from 'graphql-tag'; -import { print } from 'graphql/language/printer'; +import { print } from 'graphql'; import { ApolloLink } from '../../core/ApolloLink'; import { execute } from '../../core/execute'; diff --git a/src/link/core/__tests__/ApolloLink.ts b/src/link/core/__tests__/ApolloLink.ts index c6b95ab47cc..ed189fc1131 100644 --- a/src/link/core/__tests__/ApolloLink.ts +++ b/src/link/core/__tests__/ApolloLink.ts @@ -1,5 +1,5 @@ import gql from 'graphql-tag'; -import { print } from 'graphql/language/printer'; +import { print } from 'graphql'; import { Observable } from '../../../utilities/observables/Observable'; import { FetchResult, Operation, NextLink, GraphQLRequest } from '../types'; diff --git a/src/link/core/types.ts b/src/link/core/types.ts index 9f5be3497f4..0f99ccd794b 100644 --- a/src/link/core/types.ts +++ b/src/link/core/types.ts @@ -1,5 +1,4 @@ -import { DocumentNode } from 'graphql/language/ast'; -import { ExecutionResult } from 'graphql/execution/execute'; +import { DocumentNode, ExecutionResult } from 'graphql'; export { DocumentNode }; import { Observable } from '../../utilities'; diff --git a/src/link/http/selectHttpOptionsAndBody.ts b/src/link/http/selectHttpOptionsAndBody.ts index 93c62d614d4..00635d3e446 100644 --- a/src/link/http/selectHttpOptionsAndBody.ts +++ b/src/link/http/selectHttpOptionsAndBody.ts @@ -1,4 +1,4 @@ -import { print } from 'graphql/language/printer'; +import { print } from 'graphql'; import { Operation } from '../core'; diff --git a/src/link/persisted-queries/index.ts b/src/link/persisted-queries/index.ts index 362fa1e9935..b4ec109abbc 100644 --- a/src/link/persisted-queries/index.ts +++ b/src/link/persisted-queries/index.ts @@ -1,4 +1,4 @@ -import { print } from 'graphql/language/printer'; +import { print } from 'graphql'; import { DocumentNode, ExecutionResult, diff --git a/src/utilities/graphql/__tests__/fragments.ts b/src/utilities/graphql/__tests__/fragments.ts index 211bd54aa3c..85211dfe333 100644 --- a/src/utilities/graphql/__tests__/fragments.ts +++ b/src/utilities/graphql/__tests__/fragments.ts @@ -1,4 +1,4 @@ -import { print } from 'graphql/language/printer'; +import { print } from 'graphql'; import gql from 'graphql-tag'; import { disableFragmentWarnings } from 'graphql-tag'; diff --git a/src/utilities/graphql/__tests__/getFromAST.ts b/src/utilities/graphql/__tests__/getFromAST.ts index 575ecfca038..b02575259a7 100644 --- a/src/utilities/graphql/__tests__/getFromAST.ts +++ b/src/utilities/graphql/__tests__/getFromAST.ts @@ -1,4 +1,4 @@ -import { print } from 'graphql/language/printer'; +import { print } from 'graphql'; import gql from 'graphql-tag'; import { FragmentDefinitionNode, OperationDefinitionNode } from 'graphql'; diff --git a/src/utilities/graphql/__tests__/transform.ts b/src/utilities/graphql/__tests__/transform.ts index 36c5b0d4d8e..a8699629ecf 100644 --- a/src/utilities/graphql/__tests__/transform.ts +++ b/src/utilities/graphql/__tests__/transform.ts @@ -1,4 +1,4 @@ -import { print } from 'graphql/language/printer'; +import { print } from 'graphql'; import gql from 'graphql-tag'; import { disableFragmentWarnings } from 'graphql-tag'; diff --git a/src/utilities/graphql/directives.ts b/src/utilities/graphql/directives.ts index 8fcb6e50297..2099e791c03 100644 --- a/src/utilities/graphql/directives.ts +++ b/src/utilities/graphql/directives.ts @@ -9,10 +9,9 @@ import { ArgumentNode, ValueNode, ASTNode, + visit, } from 'graphql'; -import { visit } from 'graphql/language/visitor'; - import { invariant } from 'ts-invariant'; export type DirectiveInfo = { diff --git a/src/utilities/graphql/transform.ts b/src/utilities/graphql/transform.ts index d06079df9a9..b46cc283725 100644 --- a/src/utilities/graphql/transform.ts +++ b/src/utilities/graphql/transform.ts @@ -10,8 +10,8 @@ import { FragmentSpreadNode, VariableDefinitionNode, VariableNode, + visit, } from 'graphql'; -import { visit } from 'graphql/language/visitor'; import { invariant } from 'ts-invariant'; import { diff --git a/src/utilities/testing/mocking/mockLink.ts b/src/utilities/testing/mocking/mockLink.ts index c74b5dba244..7fb4fda2cd5 100644 --- a/src/utilities/testing/mocking/mockLink.ts +++ b/src/utilities/testing/mocking/mockLink.ts @@ -1,4 +1,4 @@ -import { print } from 'graphql/language/printer'; +import { print } from 'graphql'; import { equal } from '@wry/equality'; import { invariant } from 'ts-invariant';