1.0.1 • Published 7 years ago

graphql-query-constructor v1.0.1

Weekly downloads
6
License
ISC
Repository
github
Last release
7 years ago

GraphQL Query Constructor

A quick and simple query constructor for GraphQL

Feel free to test this out with my simple GraphQL wrapper of the Goodreads API.

Install

npm i graphql-query-constructor

Require

const GraphQLClient = require('graphql-query-constructor')

// sendQuery would be a function which accept an Object and sends it to the GraphQL server.
const { Query, Mutation } = GraphQLClient(sendQuery)

Comparison

JavaScript
Query('author', {id: 160033}, [
  'name',
  Query('books', {}, [
    'id',
    'title',
    'isbn',
    Query('authors', {}, [
      'id',
      'name'
    ])
  ])
])

GraphQL

{
  author(id: 160033) {
    name,
    books {
      id,
      title,
      isbn,
      authors {
        id,
        name
      }
    }
  }
}

Examples

More detailed examples can be found inside the examples folder.