Skip to content

This is a simple module that takes a graphQL query string and converts it into a JSON object. Think of it as the reverse of the excellent module json-to-graphql-query.

License

Notifications You must be signed in to change notification settings

trayio/graphql-query-to-json

Repository files navigation

graphql-query-to-json

Statement coverage Function coverage Line coverage Branches badge

This is a simple module that takes a graphQL query string and converts it into a JSON object. Think of it as the reverse of the excellent module json-to-graphql-query.

Installation

npm install graphql-query-to-json
# or
yarn add graphql-query-to-json

Usage

const {graphQlQueryToJson} = require("graphql-query-to-json")

const query = `
query GetThisStuff($name: String, $lastName: String) {
    viewer {
        personal(criteria: {
            name: $name,
            lastName: $lastName
        }) {
            name
            address
        }
    }
}
`
const result = graphQlQueryToJson(query, {
    variables: {
        name: "PETER",
        lastName: "SCHMIDT",
    },
})
expect(result).toEqual({
    query: {
        viewer: {
            personal: {
                __args: {
                    criteria: {
                        name: "PETER",
                        lastName: "SCHMIDT",
                    },
                },
                name: true,
                address: true,
            },
        },
    },
})

Debugging

Run the VSCode configuration "Jest" and set a breakpoint in the code wherever you feel the need to inspect.

About

This is a simple module that takes a graphQL query string and converts it into a JSON object. Think of it as the reverse of the excellent module json-to-graphql-query.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published