Skip to content

cj/jsgql

Repository files navigation

jsgql

Javascript to graphql-tag/gql

Build Status Coverage Status Downloads License

Install

yarn add jsgql@latest

Description

Converts a javascript object to a graphql-tag/gql object.

Use

import jsgql from 'jsgql'

const testGql = {
  type: 'query',
  name: 'test',
  method: 'testMethod',
  methodArgs: {
    last: 1,
    filter: {
      barIn: ['test'],
      foo: {__variable__: 'foo'},
      baz: {__type__: 'CREATED'},
    },
  },
  variables: {
    id: 1,
    foo: 'bar',
  },
  types: {
    bar: 'Baz',
  },
  fields: [
    'id',
    ['foo', [
      'id', 'bar',
    ]],
  ],
}

console.log(jsgql(testGql))
// {
//   "kind": "Document",
// ...

The string that's created by the above object and sent to graphql-tag/gql

query name($id: ID!, $foo: Baz!, $bar: String!) {
  testMethod(id: $id, foo: $foo, bar: $bar, last: 1, filter: {
    barIn: ["test"], foo: $foo, baz: CREATED
  }) {
    id
    foo {
      id
      bar
    }
  }
}

About

Javascript to graphql-tag/gql

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published