【问题标题】:Specify response type for inline fragment graphql in js file为js文件中的内联片段graphql指定响应类型
【发布时间】:2022-12-17 07:52:36
【问题描述】:

这里使用了内联片段 graphql。我无法在 js 文件中写入返回类型。

图形数据库:

query MyQuery {
  samples(dataset: "", view: "") {
    edges {
      node {
        ... on ImageSample {
          id
        }
        ... on PointCloudSample {
          id
        }
      }
    }
  }
}

JS 文件:这会引发语法错误:

const SAMPLE_DATA = {
  edges: {
    node: {
      ... on ImageSample {
        id
        sample
      }
      ... on PointCloudSample {
        id
      }
    }
  }
};

我也试过 node: {id} 但没有帮助

无法查询类型“SampleItem”上的字段“id”。您是想在“Sample”、“ImageSample”、“PointCloudSample”或“VideoSample”上使用内联片段吗?

像这样调用 GraphQL 查询:

  const gqlQuery = jsonToGraphQLQuery({
    query: {
      samples: {
        __args: {
          ...data,
        },
        ...SAMPLE_DATA
      }
    }
  }, { pretty: true });

谁能帮我写SAMPLE_DATA响应类型?

【问题讨论】:

    标签: node.js graphql fiftyone


    【解决方案1】:

    我编写了 GraphQL API。以下是截至 v0.18.0 的完全有效查询。

    query {
      samples(dataset: "datasetName", view: []) {
        edges {
          node {
            ... on ImageSample {
              id
            }
            ... on PointCloudSample {
              id
            }
          }
        }
      }
    }
    

    我相信您只需要按照querying with multiple inline fragmentsjson-to-graphql-query说明进行操作。

    const SAMPLE_DATA = {
      edges: {
        node: {
          __on: [
            { __typeName: "ImageSample", id: true },
            { __typeName: "PointCloudSample", id: true }
          ]
        }
      }
    };
    

    【讨论】:

      猜你喜欢
      • 2019-05-14
      • 2020-04-30
      • 2018-01-11
      • 1970-01-01
      • 1970-01-01
      • 2020-10-20
      • 2019-03-26
      • 2020-05-27
      • 2021-06-03
      相关资源
      最近更新 更多