简体   繁体   English

如何在中继和graphql模式中正确创建连接?

[英]How do I properly create a connection in relay & graphql schema?

I am trying to create a pagination in relay & graphql in my schema. 我试图在我的模式中的Relay&graphql中创建一个分页。 This is my code: 这是我的代码:

const GraphQLFriendByUser = new GraphQLObjectType({
  name: 'FriendByUser',
  fields: {
    id: globalIdField('FriendByUser'),
    _id: {
      type: GraphQLString,
      resolve: (root) => root._id,
    },
    email: {
      type: GraphQLBoolean,
      resolve: (root) => root.email,
    },
    fullName: {
      type: GraphQLString,
      resolve: (root) => {
        return root.fullName;
      },
    },
  },
  interfaces: [nodeInterface],
});

const {
  connectionType: FriendsByUserConnection,
  edgeType: GraphQLFriendByUserEdge,
} = connectionDefinitions({
  name: 'FriendByUser',
  nodeType: GraphQLFriendByUser,
});

I created this similarly looking at sample in todo-modern, In my TodoListHome component, this is my graphql query: 我在todo-modern中创建了类似此示例的示例,在我的TodoListHome组件中,这是我的graphql查询:

friendsByUserContext( first: 200 ) @connection(key: "TodoListHome_friendsByUserContext") {
      id
      _id
      fullName
      email
    }  

there's no problem when I update the schema, but when I try to build, this is my error: 更新架构没有问题,但是当我尝试构建时,这是我的错误:

Invariant Violation: RelayParser: Unknown field id on type FriendByUserConnection . 不变违规:RelayParser: FriendByUserConnection类型上的未知字段id Source: document TodoListHome_viewer file: C:\\Users\\PE60\\Desktop\\socialnetworking-todoapp\\js\\components\\TodoListHome.js . 来源:文档TodoListHome_viewer文件: C:\\Users\\PE60\\Desktop\\socialnetworking-todoapp\\js\\components\\TodoListHome.js

The execution doesn't even reach on resolve, so I cannot log. 执行甚至无法解决,因此我无法登录。 but I believe the error is not from there. 但我相信错误并非出自此。 Help? 救命?

Since you're using graphql-js , you probably have graphiql hosted on your /graphql endpoint. 由于您正在使用graphql-js ,因此您可能在/graphql端点上托管了/graphql That's a good place to debug queries and see the structure of your schema. 这是调试查询和查看架构结构的好地方。 There you'll see that the connection you're talking about has the field edges which has the field node which has the fields you're looking for. 在那里,您将看到您正在谈论的连接具有字段edges ,该edges具有包含要查找的字段的字段node

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM