Is it possible to get a human readable, nested JSON representation of a GraphQL schema in JavaScript?

398 views Asked by At

I am trying to get an object representation of our graph without writing something custom to parse the output of the introspectionQuery.

Ideally this would be a JSON object that had keys of the type name and their type as the value in the shape of the results of a query.

I have been playing around with the graphql/utilities but don't find a way to do this one thing.

Any ideas on this?

Something like this:

import { graphql } from 'graphql';
import { introspectionQuery } from 'graphql/utilities';
import schema from '../schema';

export default async function(req, res) {
    const result = await graphql(schema, introspectionQuery, {}, {}, {});
    return res.json(result);
}

Outputs the schema, but it's not good as a visual representation of our data.

1

There are 1 answers

0
Jazzy On

Found my answer here: https://github.com/APIs-guru/graphql-voyager

Represent any GraphQL API as an interactive graph. It's time to finally see the graph behind GraphQL. You can also explore number of public GraphQL APIs from our list.

With graphql-voyager you can visually explore your GraphQL API as an interactive graph. This is a great tool when designing or discussing your data model. It includes multiple example GraphQL schemas and also allows you to connect it to your own GraphQL endpoint. What are you waiting for, explore your API!