A light weight library to generate Axios`s GraphQL query from JSON.
Local installation
npm install axios-graphql-builder --save
Syntax | Parameter * | Output |
buildQuery | JSON Object*, Param (Optional) | GraphQL Query for Axios |
*Note: Last child in JSON object hierarchy should be assigned null value
Once installed in your project. It can be used as:
Example:
import { buildQuery } from 'axios-graphql-builder'
const jsonInput = {
query: {
a: null,
b: null,
c: {
c1: null,
c2: null
}
}
}
const paramList = [{ key: 'a', param: 'id: 10' }]
const output = buildQuery(jsonInput, paramList)
console.log(output) >>> { "query": "query \n a(id: 10) \n b \n c { \n c1 \n c2 \n } \n " }
- buildQuery: Return a GraphQl Query which can be directly passed into Axios.
- Author: Subhendu Kumar Sahoo
- Email: smaro.nitr@gmail.com
- Website: https://smaro-nitr.github.io
- Always welcome for a bugfix, feature suggestion, and feedback