babel-plugin-graphql
Babel plugin that compile GraphQL tagged template strings.
Issues related to GraphQL parsing should be reporter on graphql-parser
issue-tracker.
Install
npm install --save-dev babel-plugin-graphql
Usage
Run:
babel --plugins graphql script.js
Or add the plugin to your .babelrc
configuration:
Note: Due to current API limitations you need to enable es7.objectRestSpread
transformer or stage 1 transformers.
Example
The plugin will compile the following code:
const IMAGE_WIDTH = 80const IMAGE_HEIGHT = 80 const PostFragment = graphql` { post { title, published_at } }` const UserQuery = graphql` { user(id: <id>) { nickname, avatar(width: , height: ) { url }, posts(first: <count>) { count, edges { node { } } } } }`
into:
var IMAGE_WIDTH = 80;var IMAGE_HEIGHT = 80; var { return fields: post: fields: title: {} published_at: {} ;}; var { return fields: user: params: id: paramsid fields: nickname: {} avatar: params: width: IMAGE_WIDTH height: IMAGE_HEIGHT fields: url: {} posts: params: first: paramscount fields: count: {} edges: fields: node: fields: ;};