当@include false 或@skip true 时是否可以在 graphql 中查询空值 UUID
Is it possible to query in graphql with null value UUID when @include false or @skip true
对于 Apollo GraphQL:
我正在尝试查询需要 UUID 的字段。但如果变量为空,我不需要该字段。我想知道处理这个问题的最佳方法是什么?我目前正在传递一个默认的 documentId 来解决这个问题。
这是一个查询示例
query GetOverview($initialFetch: Boolean!, $documentId: UUID!) {
organization {
name
inode(id: $documentId) @include(if: $initialFetch) {
... on Inode {
inodeId
parent {
inodeId
}
}
}
}
变量:
{ initialFetch: true, documentId: ... }
这是我返回的错误
"Variable "$documentId" of required type "UUID!" was not provided."
我发现 Apollo skip 是我需要的,它可以完全跳过 HoC。 https://www.apollographql.com/docs/react/basics/queries.html#graphql-skip
也可能建议拆分查询,尤其是在这种情况下。
https://www.apollographql.com/docs/react/recipes/query-splitting.html
正确做法的sudo代码:
query GetOrgName {
organization {
name
}
}
query GetInode {
inode(id: $documentId) {
... on Inode {
inodeId
parent {
inodeId
}
}
}
}
const splitQuery = compose(
graphql(getOrgName, { name: "orgName" }),
graphql(getInode, {
name: "inode",
skip: props => !props.initialFetch
})
)(Component);
对于 Apollo GraphQL:
我正在尝试查询需要 UUID 的字段。但如果变量为空,我不需要该字段。我想知道处理这个问题的最佳方法是什么?我目前正在传递一个默认的 documentId 来解决这个问题。
这是一个查询示例
query GetOverview($initialFetch: Boolean!, $documentId: UUID!) {
organization {
name
inode(id: $documentId) @include(if: $initialFetch) {
... on Inode {
inodeId
parent {
inodeId
}
}
}
}
变量:
{ initialFetch: true, documentId: ... }
这是我返回的错误
"Variable "$documentId" of required type "UUID!" was not provided."
我发现 Apollo skip 是我需要的,它可以完全跳过 HoC。 https://www.apollographql.com/docs/react/basics/queries.html#graphql-skip
也可能建议拆分查询,尤其是在这种情况下。 https://www.apollographql.com/docs/react/recipes/query-splitting.html
正确做法的sudo代码:
query GetOrgName {
organization {
name
}
}
query GetInode {
inode(id: $documentId) {
... on Inode {
inodeId
parent {
inodeId
}
}
}
}
const splitQuery = compose(
graphql(getOrgName, { name: "orgName" }),
graphql(getInode, {
name: "inode",
skip: props => !props.initialFetch
})
)(Component);