babel-plugin-graphql-js-client-transform
This Babel plugin will transform any tagged raw GraphQL query to Shopify/graphql-js-client query builder syntax.
Table Of Contents
Installation
$ yarn add babel-plugin-graphql-js-client-transform
.babelrc
In your {
"plugins": [
"graphql-js-client-transform"
]
}
Usage
// Finds template literals tagged with gql; // Finds template literals tagged with customTagName;
The plugin will pick up any template literals tagged with the imported gql
function.
Do not reassign the function to another variable after it has been imported.
; ... const newTag = gql; `...`; // Don't do this. This template literal won't be transformed.
An instance of Shopify/graphql-js-client must be supplied to the tag.
Examples
The following are example usages.
Example 1
Convert a simple query.
Source Code
;...client;
Transformed Code
; ... const _document = client; // Creates a document to store the query_document; client;
Example 2
The query can also be stored inside a variable instead of being sent directly.
Source Code
; ... const query = ` query { shop { name } }`; client;
Transformed Code
; ... const _document = client; // Creates a document to store the query_document; const query = _document; client;
License
MIT, see LICENSE.md for details.