Giter Club home page Giter Club logo

graphql-ast-types's Introduction

graphql-ast-types

Autogenerated helper functions for generating a GraphQL AST

This project generates helpers functions from the graphql/language AST flow descriptions. It is intended to help with building a valid GraphQL AST.

Getting Started

yarn add graphql-ast-types

import * as t from 'graphql-ast-types';

The implementation here mimics that of babel-types. Thanks Babel team.

Usage

The following is an example of how to build a simple query with AST types.

import * as t from 'graphql-ast-types';
import { print } from 'graphql/language';

const ast = t.document([
  t.operationDefinition(
    'query',
    t.selectionSet([
      t.field(t.name('foo')),
      t.field(t.name('bar'))
    ])
  )
]);

print(ast);

/*
query {
  foo
  bar
}
*/

In addition, method calls are validated for correctness and accompanied by is and assert helpers.

t.isName(t.name('Hello')); // true

t.isName({ kind: 'Name' }); // true
t.assert({ kind: 'Name' }); // no error

t.isName({ kind: 'IntValue' }); // false
t.assert({ kind: 'IntValue' }); // error

The full API can be found here.

graphql-ast-types's People

Contributors

imranolas avatar kitten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

graphql-ast-types's Issues

Can some examples be provided!?

This is a great library but I just don't have the time to sit down and work out the intricacies of building out a AST for an operation with variables. Could some more examples be provided?

Using this lib in browsers

Hi, thanks for this library :)

We have an issue using it in CRA app though, because the babel env preset is configured to target node only. Would you agree a PR adding the following to it?

"targets": {
  "node": "6.10",
+ "browsers": ["last 2 versions"]
}

PS: we use it in react-admin for the grahql data providers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.