Search code examples
graphqlgraphql-dotnetgraphql.net

GraphQL .NET - extensions in results


I'm starting out with GraphQL for .NET Core 3.1 (https://github.com/graphql-dotnet/graphql-dotnet). I have built a simple example from what I have seen online (not a lot of information out there yet about it).

When I do a query I get a result like the following:

{
  "data": {
    "orders": [
      {
        "id": "e9c4325e-4d4c-42f6-963e-be1ad71a5b36",
        "created": "2020-07-18"
      },
      {
        "id": "12926137-cf6f-4b53-8848-443659e50823",
        "created": "2020-07-18"
      },
      {
        "id": "3c0d782d-15b1-474d-8ca9-01e33dad8e00",
        "created": "2020-07-19"
      },
      {
        "id": "befbcd57-7814-4134-9f17-fb45672e44c0",
        "created": "2020-07-19"
      }
    ]
  },
  "extensions": {
    "tracing": {
      "Version": 1,
      "StartTime": "2020-07-18T19:45:15.5554022Z",
      "EndTime": "2020-07-18T19:45:15.6044022Z",
      "Duration": 49108500,
      "Parsing": {
        "StartOffset": 16700,
        "Duration": 1102700
      },
      "Validation": {
        "StartOffset": 1131500,
        "Duration": 421899
      },
      "Execution": {
        "Resolvers": [
          {
            "Path": [
              "orders"
            ],
            "ParentType": "Query",
            "FieldName": "orders",
            "ReturnType": "[OrderType]",
            "StartOffset": 1756600,
            "Duration": 45168300
          },
          {
            "Path": [
              "orders",
              0,
              "id"
            ],
            "ParentType": "OrderType",
            "FieldName": "id",
            "ReturnType": "String!",
            "StartOffset": 46995100,
            "Duration": 79099
          },
          {
            "Path": [
              "orders",
              0,
              "created"
            ],
            "ParentType": "OrderType",
            "FieldName": "created",
            "ReturnType": "Date!",
            "StartOffset": 47081299,
            "Duration": 219500
          },
          {
            "Path": [
              "orders",
              1,
              "id"
            ],
            "ParentType": "OrderType",
            "FieldName": "id",
            "ReturnType": "String!",
            "StartOffset": 47313299,
            "Duration": 6199
          },
          {
            "Path": [
              "orders",
              1,
              "created"
            ],
            "ParentType": "OrderType",
            "FieldName": "created",
            "ReturnType": "Date!",
            "StartOffset": 47322400,
            "Duration": 4599
          },
          {
            "Path": [
              "orders",
              2,
              "id"
            ],
            "ParentType": "OrderType",
            "FieldName": "id",
            "ReturnType": "String!",
            "StartOffset": 47329300,
            "Duration": 599
          },
          {
            "Path": [
              "orders",
              2,
              "created"
            ],
            "ParentType": "OrderType",
            "FieldName": "created",
            "ReturnType": "Date!",
            "StartOffset": 47331600,
            "Duration": 499
          },
          {
            "Path": [
              "orders",
              3,
              "id"
            ],
            "ParentType": "OrderType",
            "FieldName": "id",
            "ReturnType": "String!",
            "StartOffset": 47333799,
            "Duration": 400
          },
          {
            "Path": [
              "orders",
              3,
              "created"
            ],
            "ParentType": "OrderType",
            "FieldName": "created",
            "ReturnType": "Date!",
            "StartOffset": 47335900,
            "Duration": 399
          }
        ]
      }
    }
  }
}

This is my query:

query {
  orders {
    id,
    created
  }
}

Why am I getting the extensions on the response object? I have not seen that on any example, and it's bigger then the 'data' result itself - which defeats one of the purposes of GraphQL to save data transfer.


Solution

  • When you are configuring services, check if you have set the options.EnableMetrics to false, like this:

            services.AddGraphQL(options =>
            {
                options.EnableMetrics = false;
                options.ExposeExceptions = true;
                
            }).AddSystemTextJson(deserializerSettings => { }, serializerSettings => { })
                .AddWebSockets()
                .AddDataLoader()
                .AddGraphTypes(typeof(ItemSchema));
    

    That should get rid of the extensions data.