Giter Club home page Giter Club logo

easygraphql-parser's Introduction

EasyGraphQL Mock
easygraphql-parser

Coverage Status Greenkeeper badge

easygraphql-parser is a node library used to parse the GraphQL schema into a JS object.

Installation

$ npm install easygraphql-parser --save

Usage

To get started with the mocks, you might need to follow the next steps:

Schema

type Family {
  name: String!
  ages: [Int!]!
}

type Query {
  getFamily: Family
}

Parser

'use strict'

const fs = require('fs')
const path = require('path')
const easygraphqlSchemaParser = require('easygraphql-parser')

const schemaCode = fs.readFileSync(path.join(__dirname, 'schema', 'schema.gql'), 'utf8')

const schema = easygraphqlSchemaParser(schemaCode)
console.log(schema)

Result

{ 
  Family: { 
    type: 'ObjectType',
    description: undefined,
    fields: [ 
      { 
        name: 'name',
        arguments: [],
        noNull: true,
        isArray: false,
        noNullArrayValues: false
        type: 'String',
        isDeprecated: false
      },
      { 
        name: 'ages',
        arguments: [],
        noNull: true,
        isArray: true,
        noNullArrayValues: true
        type: 'Int',
        isDeprecated: false
      } 
    ],
    values: [] 
  },
  Query: { 
    type: 'ObjectType',
    description: undefined,
    fields:  [ 
      { 
        name: 'getFamily',
        arguments: [],
        noNull: false,
        isArray: false,
        noNullArrayValues: false
        type: 'Family',
        isDeprecated: false
      } 
    ],
    values: [] 
  } 
}

License

The MIT License

Copyright (c) 2018 EasyGraphQL

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

easygraphql-parser's People

Contributors

emileber avatar estrada9166 avatar greenkeeper[bot] avatar mavv avatar nicodn avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

easygraphql-parser's Issues

Syntax error when parsing schemas with types that implement multiple interfaces

The following schema fails to parse:

interface Node {
  id: ID!
}

interface Object {
  name: String!
  id: ID!
}

type ActualThing implements Object, Node {
  name: String!
  id: ID!
  property: Int!
}

Error:

Syntax Error: Unexpected Name "Node"

GraphQL request (10:37)
 9: 
10: type ActualThing implements Object, Node {
                                        ^
11:   name: String!

    at syntaxError (node_modules/graphql/error/syntaxError.js:24:10)
    at unexpected (node_modules/graphql/language/parser.js:1491:33)
    at parseDefinition (node_modules/graphql/language/parser.js:155:9)
    at many (node_modules/graphql/language/parser.js:1524:16)
    at parseDocument (node_modules/graphql/language/parser.js:115:18)
    at parse (node_modules/graphql/language/parser.js:50:10)
    at schemaParser (node_modules/easygraphql-parser/lib/schemaParser.js:208:24)

Link unions to the composing types

Remember #9?

I just ran into a situation where it'd be extremely useful to have this type of double direction link for Union types and the member types part of that union.

What do you think?

GraphQL dependency collides with our own version

graphql is listed within the peerDependencies but also in the dependencies:

  "dependencies": {
    "graphql": "^14.4.0",
    "merge-graphql-schemas": "^1.5.8"
  },
  "peerDependencies": {
    "graphql": "^0.13.0 || ^14.0.0"
  },

It makes the GraphQLSchema instance check fail since my schema was built with my graphql dependency and the check is made against another instance of GraphQLSchema, namely, the nested graphql dependency.

Removing the node_modules/easygraphql-parser/node_modules directory makes it work.

Would it be possible to move the "graphql": "^14.4.0", to devDependencies in this package? It would still work for development, and would avoid any collision in the wild.

Link interfaces to their concrete implementations

It would extremely useful to have another field that specifies what types implement a specific interface. You could use the types field that's currently just used for unions, or you could add a separate field. Currently there's no way to ascertain the link between a concrete and an abstract type from the generated data structure.

Employee: { 
   type: 'InterfaceTypeDefinition',
   description: undefined,
   fields: [ [Object], [Object], [Object] ],
   values: [],
   types: [],
   implementedTypes: [ 'SecurityGuard', 'Secretary' ]
},

An in-range update of merge-graphql-schemas is breaking the build 🚨

The dependency merge-graphql-schemas was updated from 1.5.8 to 1.6.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

merge-graphql-schemas is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

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.