JSPM

  • Created
  • Published
  • Downloads 51124
  • Score
    100M100P100Q155979F
  • License MIT

Simple GraphQL Query Builder

Package Exports

  • gql-query-builder

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gql-query-builder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

GraphQL Query Builder

A simple helper function to generate GraphQL queries

Usage

Install

npm

npm install query-builder --save

yarn

yarn add query-builder

Example

Query

import queryBuilder from 'gql-query-builder'

const query = queryBuilder({
  type: 'query',
  operation: 'thoughts',
  fields: ['id', 'name', 'thought']
}))

console.log(query)

query {
  thoughts {
    id,
    name,
    thought
  }
}

Query (with data)

import queryBuilder from 'gql-query-builder'

const query = queryBuilder({
  type: 'query',
  operation: 'thought',
  data: {id: parseInt(id, 10)},
  fields: ['id', 'name', 'thought']
})

console.log(query)

query {
  thought(id: 1) {
    id,
    name,
    thought
  }
}

Mutation

import queryBuilder from 'gql-query-builder'

const query = queryBuilder({
  type: 'mutation', 
  operation: 'thoughtCreate', 
  data: { 
    name: "Tyrion Lannister", 
    thought: "I drink and I know things." 
  }, 
  fields: ['id']
})

console.log(query)

mutation {
  thoughtCreate(
    name: "Tyrion Lannister", 
    thought:"I drink and I know things."
  ) {
    id
  }
}