graphql-dotnet

GraphQL .Net Custom Extensions


Is there an example showing how you can include custom extensions in the results of graphql? I am looking for something like this to be returned with all results:

"extensions: {
   "numberOfResolvers": 100,
   "timeElapsed": 334
}

I am bootstrapping using services:

services.AddGraphQL(options =>
        {
            options.EnableMetrics = false;
            options.ExposeExceptions = true;
        })

I am not interested in more detailed metrics that EnableMetrics=true will give. So it would be great if we an globally include some extension logic to have that in in all results.


Solution

  • Looks like the best way to achieve this is using a middleware that adds the extension data after execution. The example is already in the github graphql-dotnet codebase -- looking up EnrichWithApolloTracing and following what it does.