diff --git a/docs/source/apollo-client/core.md b/docs/source/apollo-client/core.md index dd4a8f3d09f..834b1e464a9 100644 --- a/docs/source/apollo-client/core.md +++ b/docs/source/apollo-client/core.md @@ -20,25 +20,31 @@ const query = gql` ` ``` -There are two ways to import and use the `gql` tag. You can either register it globally: +The `gql` tag is a function under the hood, therefore it must be imported wherever it is used: ```js -// Register it globally -import { registerGqlTag } from 'apollo-client/gql'; -registerGqlTag(); +import gql from 'graphql-tag'; -// Now, in any part of your app you can use the gql tag const query = gql`...`; ``` -Alternatively, you can import it in every file if you want to be more explicit: +Alternatively, if you prefer *not* to import the `gql` tag each time you use it, you can register it as a global: ```js -import gql from 'apollo-client/gql'; +// In a browser +import gql from 'graphql-tag'; +window['gql'] = gql; + +// In node.js +import gql from 'graphql-tag'; +global['gql'] = gql; +// Now, in any part of your app you can use the gql tag const query = gql`...`; ``` +**Note:** ES6 imports are hoisted, which may mean that client code using the `gql` tag gets evaluated before the registration of the global. To avoid race conditions, it's best to just import the tag into each file that uses it. + This template literal tag serves two functions: 1. It parses the query string.