首页 > 解决方案 > GraphQL 返回数据结果 + 更多

问题描述

我有一个 Dotnetcore 3.0 项目 (Project1) 使用 graphql-dotnet 库在 Graphql 端点调用另一个 Dotnetcore 3.0 项目 (Project2)

Project2 工作正常且符合预期,仅在被 GraphiQL 或邮递员击中时返回“数据”对象。但是,当从 Project1 调用 Project2 获取数据的值时,我得到这样的对象响应

    {
  "data": {
    "member": {
      "forename": "IT",
      "email": "email@email.com                                                                                                                                                                                                                                             ",
      "name": "Test"
    }
  },
  "errors": null,
  "query": "query{\n  member(memberNo: \"MYMEMBERNUMBER\"){\n    forename\n    email\n    name\n  }\n}\n",
  "document": {
    "originalQuery": "query{\n  member(memberNo: \"MYMEMBERNUMBER\"){\n    forename\n    email\n    name\n  }\n}\n",
    "children": [
      {
        "children": [
          {
            "children": [
              {
                "children": [
                  {
                    "children": [
                      {
                        "children": [
                          {
                            "children": [],
                            "sourceLocation": {
                              "start": 26,
                              "end": 39,
                              "line": 0,
                              "column": 0
                            }
                          }
                        ],
                        "sourceLocation": {
                          "start": 16,
                          "end": 25,
                          "line": 0,
                          "column": 0
                        }
                      }
                    ],
                    "sourceLocation": null
                  },
                  {
                    "children": [],
                    "sourceLocation": null
                  },
                  {
                    "children": [
                      {
                        "children": [
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": {
                              "start": -1,
                              "end": -1,
                              "line": 0,
                              "column": 0
                            }
                          }
                        ],
                        "sourceLocation": {
                          "start": 45,
                          "end": 63,
                          "line": 0,
                          "column": 0
                        }
                      },
                      {
                        "children": [
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": {
                              "start": -1,
                              "end": -1,
                              "line": 0,
                              "column": 0
                            }
                          }
                        ],
                        "sourceLocation": {
                          "start": 58,
                          "end": 72,
                          "line": 0,
                          "column": 0
                        }
                      },
                      {
                        "children": [
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": {
                              "start": -1,
                              "end": -1,
                              "line": 0,
                              "column": 0
                            }
                          }
                        ],
                        "sourceLocation": {
                          "start": 68,
                          "end": 76,
                          "line": 0,
                          "column": 0
                        }
                      }
                    ],
                    "sourceLocation": {
                      "start": 39,
                      "end": 78,
                      "line": 0,
                      "column": 0
                    }
                  }
                ],
                "sourceLocation": {
                  "start": 9,
                  "end": 78,
                  "line": 0,
                  "column": 0
                }
              }
            ],
            "sourceLocation": {
              "start": 5,
              "end": 79,
              "line": 0,
              "column": 0
            }
          }
        ],
        "sourceLocation": {
          "start": 0,
          "end": 79,
          "line": 0,
          "column": 0
        }
      }
    ],
    "operations": [
      {
        "name": null,
        "nameNode": null,
        "operationType": 0,
        "directives": [],
        "variables": [],
        "selectionSet": {
          "selections": [
            {}
          ],
          "children": [
            {
              "children": [
                {
                  "children": [
                    {
                      "children": [
                        {
                          "children": [],
                          "sourceLocation": {
                            "start": 26,
                            "end": 39,
                            "line": 0,
                            "column": 0
                          }
                        }
                      ],
                      "sourceLocation": {
                        "start": 16,
                        "end": 25,
                        "line": 0,
                        "column": 0
                      }
                    }
                  ],
                  "sourceLocation": null
                },
                {
                  "children": [],
                  "sourceLocation": null
                },
                {
                  "children": [
                    {
                      "children": [
                        {
                          "children": [],
                          "sourceLocation": null
                        },
                        {
                          "children": [],
                          "sourceLocation": null
                        },
                        {
                          "children": [],
                          "sourceLocation": {
                            "start": -1,
                            "end": -1,
                            "line": 0,
                            "column": 0
                          }
                        }
                      ],
                      "sourceLocation": {
                        "start": 45,
                        "end": 63,
                        "line": 0,
                        "column": 0
                      }
                    },
                    {
                      "children": [
                        {
                          "children": [],
                          "sourceLocation": null
                        },
                        {
                          "children": [],
                          "sourceLocation": null
                        },
                        {
                          "children": [],
                          "sourceLocation": {
                            "start": -1,
                            "end": -1,
                            "line": 0,
                            "column": 0
                          }
                        }
                      ],
                      "sourceLocation": {
                        "start": 58,
                        "end": 72,
                        "line": 0,
                        "column": 0
                      }
                    },
                    {
                      "children": [
                        {
                          "children": [],
                          "sourceLocation": null
                        },
                        {
                          "children": [],
                          "sourceLocation": null
                        },
                        {
                          "children": [],
                          "sourceLocation": {
                            "start": -1,
                            "end": -1,
                            "line": 0,
                            "column": 0
                          }
                        }
                      ],
                      "sourceLocation": {
                        "start": 68,
                        "end": 76,
                        "line": 0,
                        "column": 0
                      }
                    }
                  ],
                  "sourceLocation": {
                    "start": 39,
                    "end": 78,
                    "line": 0,
                    "column": 0
                  }
                }
              ],
              "sourceLocation": {
                "start": 9,
                "end": 78,
                "line": 0,
                "column": 0
              }
            }
          ],
          "sourceLocation": {
            "start": 5,
            "end": 79,
            "line": 0,
            "column": 0
          }
        },
        "children": [
          {
            "children": [
              {
                "children": [
                  {
                    "children": [
                      {
                        "children": [
                          {
                            "children": [],
                            "sourceLocation": {
                              "start": 26,
                              "end": 39,
                              "line": 0,
                              "column": 0
                            }
                          }
                        ],
                        "sourceLocation": {
                          "start": 16,
                          "end": 25,
                          "line": 0,
                          "column": 0
                        }
                      }
                    ],
                    "sourceLocation": null
                  },
                  {
                    "children": [],
                    "sourceLocation": null
                  },
                  {
                    "children": [
                      {
                        "children": [
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": {
                              "start": -1,
                              "end": -1,
                              "line": 0,
                              "column": 0
                            }
                          }
                        ],
                        "sourceLocation": {
                          "start": 45,
                          "end": 63,
                          "line": 0,
                          "column": 0
                        }
                      },
                      {
                        "children": [
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": {
                              "start": -1,
                              "end": -1,
                              "line": 0,
                              "column": 0
                            }
                          }
                        ],
                        "sourceLocation": {
                          "start": 58,
                          "end": 72,
                          "line": 0,
                          "column": 0
                        }
                      },
                      {
                        "children": [
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": null
                          },
                          {
                            "children": [],
                            "sourceLocation": {
                              "start": -1,
                              "end": -1,
                              "line": 0,
                              "column": 0
                            }
                          }
                        ],
                        "sourceLocation": {
                          "start": 68,
                          "end": 76,
                          "line": 0,
                          "column": 0
                        }
                      }
                    ],
                    "sourceLocation": {
                      "start": 39,
                      "end": 78,
                      "line": 0,
                      "column": 0
                    }
                  }
                ],
                "sourceLocation": {
                  "start": 9,
                  "end": 78,
                  "line": 0,
                  "column": 0
                }
              }
            ],
            "sourceLocation": {
              "start": 5,
              "end": 79,
              "line": 0,
              "column": 0
            }
          }
        ],
        "sourceLocation": {
          "start": 0,
          "end": 79,
          "line": 0,
          "column": 0
        }
      }
    ],
    "fragments": [],
    "sourceLocation": null
  },
  "operation": {
    "name": null,
    "nameNode": null,
    "operationType": 0,
    "directives": [],
    "variables": [],
    "selectionSet": {
      "selections": [
        {}
      ],
      "children": [
        {
          "children": [
            {
              "children": [
                {
                  "children": [
                    {
                      "children": [],
                      "sourceLocation": {
                        "start": 26,
                        "end": 39,
                        "line": 0,
                        "column": 0
                      }
                    }
                  ],
                  "sourceLocation": {
                    "start": 16,
                    "end": 25,
                    "line": 0,
                    "column": 0
                  }
                }
              ],
              "sourceLocation": null
            },
            {
              "children": [],
              "sourceLocation": null
            },
            {
              "children": [
                {
                  "children": [
                    {
                      "children": [],
                      "sourceLocation": null
                    },
                    {
                      "children": [],
                      "sourceLocation": null
                    },
                    {
                      "children": [],
                      "sourceLocation": {
                        "start": -1,
                        "end": -1,
                        "line": 0,
                        "column": 0
                      }
                    }
                  ],
                  "sourceLocation": {
                    "start": 45,
                    "end": 63,
                    "line": 0,
                    "column": 0
                  }
                },
                {
                  "children": [
                    {
                      "children": [],
                      "sourceLocation": null
                    },
                    {
                      "children": [],
                      "sourceLocation": null
                    },
                    {
                      "children": [],
                      "sourceLocation": {
                        "start": -1,
                        "end": -1,
                        "line": 0,
                        "column": 0
                      }
                    }
                  ],
                  "sourceLocation": {
                    "start": 58,
                    "end": 72,
                    "line": 0,
                    "column": 0
                  }
                },
                {
                  "children": [
                    {
                      "children": [],
                      "sourceLocation": null
                    },
                    {
                      "children": [],
                      "sourceLocation": null
                    },
                    {
                      "children": [],
                      "sourceLocation": {
                        "start": -1,
                        "end": -1,
                        "line": 0,
                        "column": 0
                      }
                    }
                  ],
                  "sourceLocation": {
                    "start": 68,
                    "end": 76,
                    "line": 0,
                    "column": 0
                  }
                }
              ],
              "sourceLocation": {
                "start": 39,
                "end": 78,
                "line": 0,
                "column": 0
              }
            }
          ],
          "sourceLocation": {
            "start": 9,
            "end": 78,
            "line": 0,
            "column": 0
          }
        }
      ],
      "sourceLocation": {
        "start": 5,
        "end": 79,
        "line": 0,
        "column": 0
      }
    },
    "children": [
      {
        "children": [
          {
            "children": [
              {
                "children": [
                  {
                    "children": [
                      {
                        "children": [],
                        "sourceLocation": {
                          "start": 26,
                          "end": 39,
                          "line": 0,
                          "column": 0
                        }
                      }
                    ],
                    "sourceLocation": {
                      "start": 16,
                      "end": 25,
                      "line": 0,
                      "column": 0
                    }
                  }
                ],
                "sourceLocation": null
              },
              {
                "children": [],
                "sourceLocation": null
              },
              {
                "children": [
                  {
                    "children": [
                      {
                        "children": [],
                        "sourceLocation": null
                      },
                      {
                        "children": [],
                        "sourceLocation": null
                      },
                      {
                        "children": [],
                        "sourceLocation": {
                          "start": -1,
                          "end": -1,
                          "line": 0,
                          "column": 0
                        }
                      }
                    ],
                    "sourceLocation": {
                      "start": 45,
                      "end": 63,
                      "line": 0,
                      "column": 0
                    }
                  },
                  {
                    "children": [
                      {
                        "children": [],
                        "sourceLocation": null
                      },
                      {
                        "children": [],
                        "sourceLocation": null
                      },
                      {
                        "children": [],
                        "sourceLocation": {
                          "start": -1,
                          "end": -1,
                          "line": 0,
                          "column": 0
                        }
                      }
                    ],
                    "sourceLocation": {
                      "start": 58,
                      "end": 72,
                      "line": 0,
                      "column": 0
                    }
                  },
                  {
                    "children": [
                      {
                        "children": [],
                        "sourceLocation": null
                      },
                      {
                        "children": [],
                        "sourceLocation": null
                      },
                      {
                        "children": [],
                        "sourceLocation": {
                          "start": -1,
                          "end": -1,
                          "line": 0,
                          "column": 0
                        }
                      }
                    ],
                    "sourceLocation": {
                      "start": 68,
                      "end": 76,
                      "line": 0,
                      "column": 0
                    }
                  }
                ],
                "sourceLocation": {
                  "start": 39,
                  "end": 78,
                  "line": 0,
                  "column": 0
                }
              }
            ],
            "sourceLocation": {
              "start": 9,
              "end": 78,
              "line": 0,
              "column": 0
            }
          }
        ],
        "sourceLocation": {
          "start": 5,
          "end": 79,
          "line": 0,
          "column": 0
        }
      }
    ],
    "sourceLocation": {
      "start": 0,
      "end": 79,
      "line": 0,
      "column": 0
    }
  },
  "perf": [
    {
      "category": "operation",
      "subject": null,
      "metadata": null,
      "start": 0,
      "end": 24.5424,
      "duration": 24.5424
    },
    {
      "category": "document",
      "subject": "Building document",
      "metadata": null,
      "start": 0.016900000000000002,
      "end": 0.2521,
      "duration": 0.2352
    },
    {
      "category": "document",
      "subject": "Validating document",
      "metadata": null,
      "start": 0.2647,
      "end": 0.7371000000000001,
      "duration": 0.4724000000000001
    },
    {
      "category": "execution",
      "subject": "Executing operation",
      "metadata": null,
      "start": 0.7574000000000001,
      "end": 24.5392,
      "duration": 23.7818
    }
  ],
  "exposeExceptions": false,
  "extensions": null
}

从 Project2 获取数据的服务正在映射数据并成功返回对象。所以我不明白为什么当结果成功时我会得到所有这些额外的数据?

标签: c#graphql

解决方案


感谢 Xadam 的回复。阅读文档!

通过在控制器上设置它来修复

var executionOptions = new ExecutionOptions
            {
                Schema = _schema,
                Query = query.Query,
                Inputs = inputs,
                EnableMetrics = false
            };

推荐阅读