我想与多个 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 ...