• Stars
    star
    167
  • Rank 226,635 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Babel Macro for graphql-tag

graphql-tag.macro

Babel Macro for the graphql-tag library.

What it does

It inlines the result of parsing the GraphQL queries with graphql-tag.

Converts this:

const query = gql`
  query {
    hello {
      world
    }
  }
`;

To this:

const query = {
  'kind': 'Document',
  'definitions': [{
    'kind': 'OperationDefinition',
    'operation': 'query',
    'variableDefinitions': [],
    'directives': [],
    'selectionSet': {
      'kind': 'SelectionSet',
      'selections': [{
        'kind': 'Field',
        'alias': null,
        'name': {
          'kind': 'Name',
          'value': 'hello'
        },
        'arguments': [],
        'directives': [],
        'selectionSet': {
          'kind': 'SelectionSet',
          'selections': [{
            'kind': 'Field',
            'alias': null,
            'name': {
              'kind': 'Name',
              'value': 'world'
            },
            'arguments': [],
            'directives': [],
            'selectionSet': null
          }]
        }
      }]
    }
  }],
  'loc': {
    'start': 0,
    'end': 45,
    'source': {
      'body': '\\\\n  query {\\\\n    hello {\\\\n      world\\\\n    }\\\\n  }\\\\n',
      'name': 'GraphQL request',
      'locationOffset': {
        'line': 1,
        'column': 1
      }
    }
  }
};

It also supports adding interpolated fragments:

const frag = gql`
  fragment Frag on Hello {
    world
  }
`;

const query = gql`
  query {
    hello {
      universe
      ...Frag
    }
  }

  ${frag}
`;

Why

To avoid the runtime overhead of parsing a string into a GraphQL AST.

Installation and setup

Install and configure babel-macros if you haven't already.

Then install this package:

# with yarn
yarn add -D graphql-tag.macro

# with npm
npm install -D graphql-tag.macro

Usage

The usage is the same as using graphql-tag directly, the only difference is that you have to import gql from the macro now:

import gql from 'graphql-tag.macro';

const query = gql`
  query {
    hello {
      world
    }
  }
`;

More Repositories

1

redux-immutable-state-invariant

Redux middleware that detects mutations between and outside redux dispatches. For development use only.
JavaScript
937
star
2

react-sound

Sound component to play audio in your web apps
JavaScript
485
star
3

activerecord-futures

Specify queries to be sent all at once to the database. Save round trips!
Ruby
107
star
4

graphql-persisted-document-loader

Webpack loader that adds a documentId to a compiled graphql document, which can be used when persisting/retrieving documents
JavaScript
81
star
5

workshop-pensando-en-react

Workshop introductorio a React
JavaScript
51
star
6

makery.js

Factory-style (via blueprints) object creation for tests. Inspired by Ruby Machinist.
JavaScript
22
star
7

fnky

A funky (and "souly"?) library for functional programming in Javascript
JavaScript
17
star
8

react-style-hot-reload

Exploring how to make react-style work with HMR and react-hot-loader
JavaScript
13
star
9

redux-state-router

Define your urls as a function of your state
JavaScript
8
star
10

cycle-poc

Playing with Cyclejs
JavaScript
5
star
11

StateMachine

State Machine pattern for .NET (inspired by ruby gem state_machine)
C#
4
star
12

rpg

This wanted be a super cool MMORPG, but I abandoned it :(
CoffeeScript
2
star
13

js-runner-fatigue

JS (runner) Fatigue - A game to cope with learning different JS stacks
JavaScript
2
star
14

graphql-client

wip
JavaScript
2
star
15

react-job-board

Quick example job board app using React.
JavaScript
2
star
16

enter-hangman

Hangman game made with React for a live coding session at Meetup.js Buenos Aires
JavaScript
2
star
17

demo_app

Some other app for ruby
Ruby
1
star
18

leoasis.github.com

My Personal Blog
JavaScript
1
star
19

stillness

Immutable manipulation helpers to aid in nested state updates
JavaScript
1
star
20

immutable-model

Immutable Model and Collection abstractions backed by Immutable.js
JavaScript
1
star
21

perf-graphql-tag

Repo to see how much time is saved when preprocessing graphql-tag calls
JavaScript
1
star
22

vows-test

Testing of the Vows module for node.js
JavaScript
1
star