GraphQL icon indicating copy to clipboard operation
GraphQL copied to clipboard

Add extensions to the response map

Open jamhall opened this issue 9 years ago • 4 comments

The GraphQL specification states:

The response map may also contain an entry with key extensions. This entry, if set, must have a map as its value. This entry is reserved for implementors to extend the protocol however they see fit, and hence there are no additional restrictions on its contents.

express-graphql gives a good use case in their README.

The example they give is to use the extensions field for adding the amount of time consumed by running the provided query, which could perhaps be used by your development tools.

app.use('/graphql', graphqlHTTP(request => {
  const startTime = Date.now();
  return {
    schema: MyGraphQLSchema,
    graphiql: true,
    extensions({ document, variables, operationName, result }) {
      return { runTime: Date.now() - startTime };
    }
  };
}));

When querying this endpoint, it would include this information in the result, for example:

{
  "data": { ... }
  "extensions": {
    "runTime": 135
  }
}

What do you think of implementing this into this project?

jamhall avatar Dec 04 '16 11:12 jamhall

@jamhall I love it! Will absolutely do :)

viniychuk avatar Dec 04 '16 16:12 viniychuk

@viniychuk - Awesome! Look forward to using it :)

jamhall avatar Dec 04 '16 17:12 jamhall

+1 ... This would be super helpful. Looking forward to it

StymiedSloth avatar Dec 05 '16 14:12 StymiedSloth

+1 Also looking forward to using this.

clintburgos avatar Mar 03 '17 15:03 clintburgos