Skip to content
This repository has been archived by the owner on Feb 25, 2019. It is now read-only.

cobbweb/graphqljs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL JS

A simple GraphQL parser written in JavaScript.

TODO

  • Write some tests
  • Provided better syntax/parsing errors

Usage

Parser API

The parser is generated by PEGjs, I'd recommend reading their docs on parser usage. But it's pretty simple:

var parser = require('graphql');

var query = `
  node(1) {
    id
    name
    birthdate {
      day,
      month,
      year
    },
    friends.first(1) {
      id
      name
    }
  }
`;

var ast = parser.parse(query);
// ast is a plain JS object

Example output

Going off the above query, the return AST would look like this:

  {
    "call": "node",
    "parameter": "1",
    "root": true,
    "properties": [
      {
        "name": "id"
      },
      {
        "name": "name"
      },
      {
        "name": "birthdate",
        "properties": {
          "properties": [
            {
              "name": "day"
            },
            {
              "name": "month"
            },
            {
              "name": "year"
            }
          ]
        }
      },
      {
        "name": "friends",
        "calls": [
          {
            "call": "first",
            "parameter": "1"
          }
        ],
        "properties": {
          "properties": [
            {
              "name": "id"
            },
            {
              "name": "name"
            }
          ]
        }
      }
    ]
  }

Demo

After cloning, install deps with npm install.

You can re-build the parser by running npm run build

Or see a demo of its output by running npm run demo, this runs the parser over ./examples/friends.gql and dumps the parsed object to the console.

About

GraphQL parser written in JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published