1.2.2 • Published 6 years ago

@jacco-meijer/graphql-query-builder v1.2.2

Weekly downloads
8
License
MIT
Repository
github
Last release
6 years ago

graphql-query-builder

About

Small library to build graphQL queries dynamically.

How does it work?

The library translates a javascript object into a GraphQL query string.

The object below:

{
  fields: {
    firstName: {},
    lastName: {},
  },
  operationName: 'firstAndLastName',
  operationType: 'query',
}

Turns into:

query firstAndLastName {
  firstName
  lastName
}

Examples

See jest test script for a larger example.

import {
  graphqlQueryBuilder as qb,
  Question,
} from '@jacco-meijer/graphql-query-builder'

const question: Question = {
  fields: {
    firstName: {
      arguments: {
        id: '4',
      },
    },
    lastName: {
      directive: {
        name: '@include',
        value: 'if: $withFriends',
      },
    },
  },
  operationType: 'query',
}

console.log(qb(question))
// query {
//  firstName(id: 4)
//  lastName @include(if: $withFriends)
// }

Supported fields

Have a look into the typescript definitions for that.

1.2.2

6 years ago

1.2.0

6 years ago

1.2.1

6 years ago

1.1.1

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago