【发布时间】:2017-07-23 10:16:11
【问题描述】:
我目前正在做 facebook relayjs 教程,我需要帮助理解教程的这一部分,它指出
接下来,让我们定义一个节点接口和类型。我们只需要提供一个 Relay 从对象映射到关联的 GraphQL 类型的方式 使用该对象,并从全局 ID 到它指向的对象
const {nodeInterface, nodeField} = nodeDefinitions(
(globalId) => {
const {type, id} = fromGlobalId(globalId);
if (type === 'Game') {
return getGame(id);
} else if (type === 'HidingSpot') {
return getHidingSpot(id);
} else {
return null;
}
},
(obj) => {
if (obj instanceof Game) {
return gameType;
} else if (obj instanceof HidingSpot) {
return hidingSpotType;
} else {
return null;
}
}
);
在 nodeDefinition 的第一个参数上,它的 globalId 是从哪里得到的? Game 和 HidingSpot 是 GraphQLSchema 上的名称吗?这个 'const {type, id} = fromGlobalId(globalId);' 是什么意思做?还有什么是第二个论点?我需要帮助理解 nodeDefinitions,不知何故我在官方文档上找不到 nodeDefinitions。谢谢。
【问题讨论】:
标签: relayjs