我想與多個GraphQL類型共享一個nodeInterface。目前收到此錯誤:共享中繼節點接口
Error: User may only implement Interface types, it cannot implement: undefined.
我已經聲明如下界面:
// file: node-interface.js
let {nodeInterface, nodeField} = nodeDefinitions(
(globalId) => {
let {type, id} = fromGlobalId(globalId);
if (type === 'UserModel') {;
return UserModel.findOne(id).exec();
}
return null;
},
(obj) => {
if (obj instanceof UserModel) {
return UserType;
}
return null;
}
);
export { nodeInterface };
export { nodeField };
and attempting to use it in my UserType like this
// file: user.js
import {
nodeInterface
} from ‘./node-interface';
let UserType = new GraphQLObjectType({
name: 'User',
description: 'A user',
fields:() => ({
id: globalIdField('User'),
username: {
type: GraphQLString,
},
}),
interfaces: [nodeInterface]
});
我缺少什麼?我需要能夠將多個GraphQL類型的聲明分解爲相應的文件並實現nodeInterface ...
不知道,但你可能需要把類型爲註冊模塊打破nodeinterface <->用戶循環依賴。 –