Write and parse GraphQL queries in pure JSON
npm install json-graphql
import { parse, stringify } from 'json-graphql';
const graphql = `...`;
console.log(parse(graphql)); // Shows object
const json = {...};
console.log(stringify(json)); // Shows graphql
GraphQL query
{
human: hooman(id: "1000") {
name
height(unit: "FOOT")
}
}
JSON query
{
"human": {
"$": {
"_": "hooman",
"id": "1000"
},
"name": true,
"height": {
"$": {
"unit": "FOOT",
}
}
}
}
Takes a GraphQL query string and returns a JSON object
Takes a JSON query and returns a GraphQL query string