Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Story

As a server, I want to add an extensions callback function similar to what's available in the express-graphql package options
so that I can add additional key-value metadata to each response. This is useful for capturing runtime and metrics for a given request.

Acceptance criteria

  • The graphql-http createHandler function should have an optional extensions function for adding additional metadata to the GraphQL response as a key-value object. The result will be added to the "extensions" field in the resulting JSON. This is often a useful place to add development time metadata such as the runtime of a query or the amount of resources consumed. This may be an async function. The function is given one object as an argument: { document, variables, operationName, result, context }.
You must be logged in to vote

This is already possible with the onOperation handler hook. Roughly:

import { createHandler } from 'graphql-http';
import { schema } from './my-graphql-schema';

const handler = createHandler({
  schema,
  onOperation(_req, _args, result) {
    return {
      ...result,
      extensions: {
        myCustom: 'metadata',
      },
    };
  },
});

Replies: 1 comment · 1 reply

Comment options

This is already possible with the onOperation handler hook. Roughly:

import { createHandler } from 'graphql-http';
import { schema } from './my-graphql-schema';

const handler = createHandler({
  schema,
  onOperation(_req, _args, result) {
    return {
      ...result,
      extensions: {
        myCustom: 'metadata',
      },
    };
  },
});
You must be logged in to vote
1 reply
@bryanpyle
Comment options

Awesome! I'll give this a shot. Thank you!

Answer selected by enisdenjo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #107 on August 16, 2023 09:43.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.