【问题标题】:How do I properly create a connection in relay & graphql schema?如何在中继和 graphql 模式中正确创建连接?
【发布时间】:2018-01-18 15:11:51
【问题描述】:

我正在尝试在我的架构中的 relay & graphql 中创建分页。这是我的代码:

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,
});

我在 todo-modern 中创建了这个类似的示例,在我的 TodoListHome 组件中,这是我的 graphql 查询:

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

更新架构时没有问题,但是当我尝试构建时,这是我的错误:

不变违规:RelayParser:类型上的未知字段id FriendByUserConnection。来源:文档TodoListHome_viewer 文件: C:\Users\PE60\Desktop\socialnetworking-todoapp\js\components\TodoListHome.js.

执行甚至没有达到解决,所以我无法登录。但我相信错误不是来自那里。帮忙?

【问题讨论】:

    标签: javascript reactjs relayjs graphql-js relaymodern


    【解决方案1】:

    由于您使用的是graphql-js,因此您可能在/graphql 端点上托管了graphiql。这是调试查询和查看架构结构的好地方。在那里,您会看到您正在谈论的连接具有字段 edges,该字段具有字段 node,其中包含您要查找的字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-18
      • 2019-10-05
      • 2016-12-09
      • 2021-09-01
      • 2019-05-25
      • 1970-01-01
      • 1970-01-01
      • 2016-10-28
      相关资源
      最近更新 更多