gpt4 book ai didi

relayjs - 中继/graphql 查询中的 3 个点/句点/省略号是什么意思?

转载 作者:行者123 更新时间:2023-12-03 10:13:58 25 4
gpt4 key购买 nike

relay docs包含这个片段:

query RebelsRefetchQuery {
node(id: "RmFjdGlvbjox") {
id
... on Faction {
name
}
}
}

这是什么 ... on Faction on 语法是什么意思?

最佳答案

...有两种用途与碎片有关。

通过引用合并片段

query Foo {
user(id: 4) {
...userFields
}
}

fragment userFields on User {
name
}

具有将片段中的字段组合到嵌入查询中的效果:
query Foo {
user(id: 4) {
name
}
}

请注意,片段可能会组成其他片段。

内联片段

从文档:

If you are querying a field that returns an interface or a union type, you will need to use inline fragments to access data on the underlying concrete type.



https://graphql.org/learn/queries/#inline-fragments

这些可用于以依赖于类型的方式组合字段。例如:
query Foo {
profile(id: $id) {
url
... on User {
homeAddress
}
... on Business {
address
}
}
}

在这个例子中,服务器会判断是否返回 homeAddressaddress运行时字段,基于请求的对象是否为 UserBusiness .

关于relayjs - 中继/graphql 查询中的 3 个点/句点/省略号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34828418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com