【发布时间】:2021-09-08 09:15:03
【问题描述】:
我如何将 userThat(可能还有其他几个相关字段)重构为其他不错的模块化文件,然后将它们包含到 root_query_type.js 中
这是一个普通的 node/express/graphql GraphQLObjectType 实现。
还是我注定要拥有庞大的 root_query_type.js ?
schema.js
module.exports = new GraphQLSchema({
query: RootQueryType
});
root_query_type.js
const RootQueryType = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
userThis: {
type: UserType,
resolve(parentValue, args, request) {
return thisResult;
}
},
userThat: {
type: UserType,
args: {
thatArgs: { type: new GraphQLNonNull(GraphQLString) },
},
resolve: (parentValue, arg, request) => {
return thatResult;
},
},
【问题讨论】:
-
这里的 GraphQL 没有什么特别之处。您只有一个大的对象字面量 - 您可以将其拆分为单独的属性,并从单独的模块导入每个值。
标签: javascript node.js graphql graphql-schema