【问题标题】:GraphQL .NET - extensions in resultsGraphQL .NET - 结果中的扩展
【发布时间】:2020-07-18 19:49:35
【问题描述】:

我开始使用 GraphQL for .NET Core 3.1 (https://github.com/graphql-dotnet/graphql-dotnet)。我根据我在网上看到的内容构建了一个简单的示例(关于它的信息还不是很多)。

当我进行查询时,我得到如下结果:

{
  "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
          }
        ]
      }
    }
  }
}

这是我的查询:

query {
  orders {
    id,
    created
  }
}

为什么我在响应对象上得到extensions?我在任何示例中都没有看到这一点,而且它比“数据”结果本身更大——这违背了 GraphQL 保存数据传输的目的之一。

【问题讨论】:

    标签: graphql graphql-dotnet graphql.net


    【解决方案1】:

    在你配置服务的时候,检查你是否把options.EnableMetrics设置为false,像这样:

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

    这应该去掉扩展数据。

    【讨论】:

    • 谢谢。起初将其设置为false 对我不起作用。现在确实如此。不知道为什么:)
    猜你喜欢
    • 2020-01-11
    • 2019-07-07
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-13
    相关资源
    最近更新 更多