facebook的relayjs教程,我需要幫助理解教程的這一部分,它指出什麼是relay中的nodeInterface,nodeField和nodeDefinitions?我目前在做
接下來,讓我們定義一個節點接口和類型。我們只需要提供中繼從對象到與該對象關聯 的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。謝謝。
只是困惑,如何返回給定對象的類型,所以obj這裏來自何時創建? globalId顯然來自id字段。 –