jsgql
v1.0.4
Published
Javascript to graphql-tag/gql
Downloads
1
Readme
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
}
}
}