如何获取graphQl片段?
我需要将片段设置为我的 gql。这是工作代码:
const findEntity = gql`
query findEntity($pagination: Pagination, $sort: Sort) {
organizationList(pagination: $pagination, sort: $sort) {
data {
_id
name
}
}
}
`;
此代码不起作用:
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}
}
}
`;
错误:[{message:“无法查询类型“OrganizationsPage”上的字段“fragment”。”,…},…]
我做错了什么?我想我重复了文档样本......
I need to set fragment to my 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".",…},…]
What I do wrong? I think I repeated documentation sample...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
片段使用伪扩展语法,您需要将它们包含在查询中。为了符合约定,我还对片段名称使用了大写字母。
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.