【发布时间】:2017-09-03 03:40:33
【问题描述】:
当整个架构位于单个文件中时,下面的代码有效,但是当我尝试将其拆分为单个文件时出现上述错误。
我正在导入所有类型和函数。
我必须添加更多细节,但我不知道该说什么。我认为这是一个排序问题,因为它在单个文件中工作,但没有拆分。
非常感谢。
const UserCreateMutation = mutationWithClientMutationId({
name: 'UserCreate',
inputFields: {
email: {type: new GraphQLNonNull(GraphQLString)},
password: {type: new GraphQLNonNull(GraphQLString)}
},
outputFields: {
viewer: {
type: viewerType,
resolve() {
return viewerGet();
}
},
field: {
type: userType,
resolve(node) {
return node;
}
}
},
async mutateAndGetPayload({email, password}, {db, req}) {
export const viewerType = new GraphQLObjectType({
name: 'Viewer',
fields() {
return {
id: globalIdField('Viewer', ({_id: viewerLocalId}) => {
return viewerLocalId;
}),
_id: {type: GraphQLID},
user: {
type: userType,
resolve(parent, args, {req: {user}}) {
return user || {};
}
},
profile: {
type: profileConnectionType,
args: {
id: {type: GraphQLID},
searchTerm: {type: GraphQLString},
...connectionArgs
},
resolve(parent, {id: profileGlobalId, searchTerm, ...connectionArgs}, {db}) {
const query = (() => {
const q = {};
if (profileGlobalId) {
const {id: profileLocalId} = fromGlobalId(profileGlobalId);
Object.assign(
q,
{_id: new ObjectID(profileLocalId)}
);
}
if (searchTerm) {
Object.assign(
q,
{
$text: {
$search: `\"${searchTerm}\"`
}
}
);
}
return q;
})();
const sort = {_id: -1};
const limit = 0;
return connectionFromPromisedArray(
promisedArrayGet(
query,
sort,
limit,
profileCollectionName,
db
),
connectionArgs
);
}
}
};
},
interfaces: [nodeInterface]
});
class Viewer extends Object {}
export const viewerGet = () => {
return Object.assign(
new Viewer(),
{
_id: 'Viewer'
}
);
};
导入 { viewerType, userType, viewerGet }
【问题讨论】:
-
请通过导入 viewerType 和 viewerType ObjectType 更新问题
-
我添加了 viewerType 和 Object
-
将它们分成模块和普通的
module.exports工作正常 -
我是为 viewerType、viewerGet、userType 和 UserCreateMutation 做的。仍然得到同样的错误。我需要一段时间来重做整个应用程序。你觉得有必要吗?