尝试在grahiql操场上运行以下gql,但出现以下错误:
必须使用值调用loader.load()函数,但得到:未定义
下面是代码:
{
messages {
edges {
createdAt
text
user{
id
}
}
}
}
/ *根据要求,我正在添加解析器代码和架构,感谢您的帮助:
* /
export default {
Query: {
messages: async (parent, {
cursor,
limit = 100
}, {
models
}) => {
const cursorOptions = cursor ?
{
createdAt: {
$lt: fromCursorHash(cursor),
},
} :
{};
const messages = await models.Message.find(
cursorOptions,
null, {
sort: {
createdAt: -1
},
limit: limit + 1,
},
);
const hasNextPage = messages.length > limit;
const edges = hasNextPage ? messages.slice(0, -1) : messages;
return {
edges,
pageInfo: {
hasNextPage,
endCursor: toCursorHash(
edges[edges.length - 1].createdAt.toString(),
),
},
};
},
message: async (parent, {
id
}, {
models
}) => {
return await models.Message.findById(id);
},
},
突变:{ createMessage:CombineResolvers(
async (parent, {
text
}, {
models,
me
}) => {
const message = await models.Message.create({
text,
userId: me.id,
});
pubsub.publish(EVENTS.MESSAGE.CREATED, {
messageCreated: {
message
},
});
return message;
},
),