You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/recipes/babel.md
+48-1Lines changed: 48 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@ To avoid this runtime overhead, you can precompile your queries created with `gr
9
9
1. Using [babel-plugin-graphql-tag](#using-babel-plugin-graphql-tag)
10
10
2. Using [graphql-tag.macro](#using-graphql-tagmacro)
11
11
12
+
If you prefer to keep your GraphQL code in separate files (`.graphql` or `.gql`) you can use [babel-plugin-inline-import-graphql-ast](https://github.com/detrohutt/babel-plugin-inline-import-graphql-ast). This plugin still uses `graphql-tag` under the hood, but transparently. You simply `import` your operations/fragments as if each were an export from your GraphQL file. This carries the same precompilation benefits as the above approaches.
13
+
12
14
## Using babel-plugin-graphql-tag
13
15
14
16
This approach will allow you to use the `graphql-tag` library as usual, and when processing the files with this babel plugin, the calls to that library will be replaced by the precompiled result.
Both approaches work with fragments. You can have fragments defined in a different call to `gql` (either in the same file or in a different one). You can then include them into the main query using interpolation, like this:
117
+
All of these approaches support the use of fragments.
118
+
119
+
For the first two approaches, you can have fragments defined in a different call to `gql` (either in the same file or in a different one). You can then include them into the main query using interpolation, like this:
75
120
76
121
```js
77
122
importgqlfrom'graphql-tag';
@@ -97,3 +142,5 @@ const query = gql`
97
142
${fragments.hello}
98
143
`;
99
144
```
145
+
146
+
With `babel-plugin-inline-import-graphql-ast`, you can just include your fragment in your GraphQL file along-side whatever uses it, or even import it from a separate file using the GraphQL `#import` syntax. See the [README](https://github.com/detrohutt/babel-plugin-inline-import-graphql-ast) for more information.
0 commit comments