有没有办法从graphql.js解析器的信息重建查询? let root={ 图书:(家长,参数,信息){…} } 让res=wait-graphql(schema,{books{title}}}},root);
graphql.js中是否已经有一个helper函数可以使用有没有办法从graphql.js解析器的信息重建查询? let root={ 图书:(家长,参数,信息){…} } 让res=wait-graphql(schema,{books{title}}}},root);,graphql,Graphql,graphql.js中是否已经有一个helper函数可以使用info?是的,有一种方法: 当您从expressgraphql使用graphqlHTTP时,第三个参数是graphQLParams,您可以为它提供实例上下文 graphqlHTTP(async (request, response, graphQLParams) => ({ schema, graphiql: true, context: graphQLParams })) 然后在模式定义中,您可以从任
info
?是的,有一种方法:
当您从expressgraphql使用graphqlHTTP时,第三个参数是graphQLParams,您可以为它提供实例上下文
graphqlHTTP(async (request, response, graphQLParams) => ({
schema,
graphiql: true,
context: graphQLParams
}))
然后在模式定义中,您可以从任何解析函数获取上下文,如下所示:
products: {
type: new GraphQLList(productType),
resolve: (parent, args, { query }, info) => {
return getProducts({
query
});
}
},
在本例中,context.query是您的实际查询:
{ products { id } }