jsgql

1.0.4 • Public • Published

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
    }
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i jsgql

Weekly Downloads

0

Version

1.0.4

License

MIT

Last publish

Collaborators

  • ceej