graphql-json-query

0.2.3 • Public • Published

Graphql-json-query

Library for transform object json in query or mutation graphql without variables


Examples:

  1. Query type query
  2. Query type mutation
  3. Query owners
  4. Multiple queries

JSON TO QUERY (type query)

import { jsonToQuery } from 'graphql-json-query';

return jsonToQuery({
  schemaName: 'test',
  jsonData: {
    data: {
      testString: 'hello',
      testNumber: 56,
      testBoolean: true,
      testNull: null,
      testUndefined: undefined,
      testArray: ['aaa', 'bbb'],
      testjson: {
        testString2: 'hello3',
        testNumber2: 57,
      },
    },
  },
  returnData: ['Id', 'name', { options: ['data', 'example'] }],
});

RESPONSE

query {test(data: {testString: "hello", testNumber: 56, testBoolean: true, testNull: null, testArray: ["aaa", "bbb"], testjson: {testString2: "hello3", testNumber2: 57}}){Id name options : {  data  example  } }}

JSON TO QUERY (type mutation)

import { jsonToMutation } from 'graphql-json-query';

return jsonToMutation({
  schemaName: 'test',
  jsonData: {
    data: {
      testString: 'hello',
      testNumber: 56,
      testBoolean: true,
      testNull: null,
      testUndefined: undefined,
      testArray: ['aaa', 'bbb'],
      testjson: {
        testString2: 'hello3',
        testNumber2: 57,
      },
    },
  },
  returnData: ['Id', 'name', { options: ['data', 'example'] }],
});

RESPONSE

mutation {test(data: {testString: "hello", testNumber: 56, testBoolean: true, testNull: null, testArray: ["aaa", "bbb"], testjson: {testString2: "hello3", testNumber2: 57}}){Id name options : {  data  example  } }}

JSON TO QUERY (type own)

import { jsonToQueryOwn } from 'graphql-json-query';

return jsonToQueryOwn('testQuery', {
  schemaName: 'test',
  jsonData: {
    data: {
      testString: 'hello',
      testNumber: 56,
      testBoolean: true,
      testNull: null,
      testUndefined: undefined,
      testArray: ['aaa', 'bbb'],
      testjson: {
        testString2: 'hello3',
        testNumber2: 57,
      },
    },
  },
  returnData: ['Id', 'name', { options: ['data', 'example'] }],
});

RESPONSE

testQuery {test(data: {testString: "hello", testNumber: 56, testBoolean: true, testNull: null, testArray: ["aaa", "bbb"], testjson: {testString2: "hello3", testNumber2: 57}}){Id name options : {  data  example  } }}

MULTIPLE QUERYS EXAMPLE

this work in all cases

import { jsonToQuery } from 'graphql-json-query';

return jsonToQuery([{
  schemaName: 'test1',
  jsonData: {
    data: "hello"
  },
  returnData: ['world'],
},{
  schemaName: 'test2',
  jsonData: {
    data: "hello"
  },
  returnData: ['world'],
}]);}

RESPONSE

query {
  test1(data: "hello") {
    world
  }
  test2(data: "hello") {
    world
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i graphql-json-query

Weekly Downloads

1

Version

0.2.3

License

MIT

Unpacked Size

4.32 kB

Total Files

3

Last publish

Collaborators

  • kaiser-arg