2017-08-10 25 views
0

我正在尝试在我的模式中创建一个分页继电器& graphql。这是我的代码:如何在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, 
}); 

我创造了这个在待办事项现代同样在看样品,在我TodoListHome组件,这是我graphql查询:

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

有当我更新的模式没有问题,但是当我尝试建立,这是我的错误:

Invariant Violation: RelayParser: Unknown field id on type FriendByUserConnection . Source: document TodoListHome_viewer file: C:\Users\PE60\Desktop\socialnetworking-todoapp\js\components\TodoListHome.js .

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

回答

0

由于您使用的是graphql-js,因此您可能在您的/graphql端点上托管了graphiql。这是调试查询并查看模式结构的好地方。您会看到您所说的连接有edges字段,其​​中有node字段,其​​中包含您要查找的字段。

相关问题