how to explore GraphQLResolveInfo

This post will describe how to display the content of GraphQLResolveInfo in order to explore and analyze its content.

As discussed in the [previous post]() we absolutely need to explore the content of the 3rd parameter to our resolve method …

This post is a quick description of a way to achieve this.

In your relay schema, you create a dummy resolve method to print on the console the content of this structure:

var queryType = new GraphQLObjectType({
  name: 'RootQueryType',
  fields: () => ({
    user: {
      type: UserType,
      description: 'the users of the service',
      args: {
        id: {
          name: 'id',
          type: new GraphQLNonNull(GraphQLString)
      resolve: (parent, args, ast) => {
        console.log(require('util').inspect(ast, { showHidden: false, depth: null }));
        return { id: "1" , name: "Pierre Carion"};

This will print on the console the content of ast.

You may want to start your server in a specific mode to retrieve the content of the output in a file:

babel-node test/server.js | tee log.txt

The file log.txt is nearly a JSON file : there are a few transformations to perform on this file to make it a real JSON file.

In vi you can run those 3 commands to JSON’ified the content of that file:

:1,$ s/\[Function[^\]]*\]/"xxx"/g
:1,$ s/undefined/"undefined"/
:1,$ s/Circular/"Circular"/g

Finally, you can then reformat this JSON file into a format easier to read.

Personaly, I’ve used this online tool :

See you in the next post with more info. Hopefully.