在Apollo GraphQL解析器类型签名中,如果info
参数为空,可能是因为没有正确地传递info
参数。以下是解决此问题的代码示例:
const resolvers = {
Query: {
// 示例查询解析器
myQuery: (parent, args, context, info) => {
if (!info) {
throw new Error("info参数为空");
}
// 进行其他操作
},
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
});
server.listen().then(({ url }) => {
console.log(`Server running at ${url}`);
});
在上面的示例中,myQuery
是一个查询解析器,它接收四个参数:parent
、args
、context
和info
。如果info
参数为空,会抛出一个错误。
确保在查询解析器中正确地传递info
参数,以避免出现info参数为空
的问题。