[英]How to fetch graphQl fragment?
I need to set fragment to my gql.我需要将片段设置为我的 gql。 It is working code:
它是工作代码:
const findEntity = gql`
query findEntity($pagination: Pagination, $sort: Sort) {
organizationList(pagination: $pagination, sort: $sort) {
data {
_id
name
}
}
}
`;
This code doesn't work:此代码不起作用:
const TEST_FRAGMENT = gql`
fragment organizationList on OrganizationsPage {
data {
_id
name
}
}
`;
const findEntity = gql`
query findEntity($pagination: Pagination, $sort: Sort) {
organizationList(pagination: $pagination, sort: $sort) {
${TEST_FRAGMENT}
}
}
`;
errors: [{message: "Cannot query field "fragment" on type "OrganizationsPage".",…},…]错误:[{消息:“无法查询类型为“OrganizationsPage”的字段“片段”。”,...},...]
What I do wrong?我做错了什么? I think I repeated documentation sample...
我想我重复了文档示例...
Fragments use pseudo-spread syntax and you need to include them in the query.片段使用伪传播语法,您需要将它们包含在查询中。 I also used caps for the fragment name for convention compliance.
为了符合约定,我还使用大写字母作为片段名称。
const findEntity = gql`
${TEST_FRAGMENT}
query findEntity($pagination: Pagination, $sort: Sort) {
organizationList(pagination: $pagination, sort: $sort) {
...OrganizationListFields
}
}
`;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.