首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用graphql工具调用查询

如何使用graphql工具调用查询
EN

Stack Overflow用户
提问于 2020-09-07 00:26:39
回答 1查看 118关注 0票数 0

我想构建一个GraphQL应用程序接口。但是,我不想使用express或connect,这会使我无法使用express-graphql。我的模式是使用graphql-tools中的makeExecutableSchema方法生成的。这意味着我需要以某种方式手动调用模式上的查询。

基本上,我需要这样的东西:

代码语言:javascript
复制
const { makeExecutableSchema, magicFunction /*This should invoke the query*/ } = require('graphql-tools');

const typeDefs = `
type Query {
  hello: String
}
`;
const resolvers = {
  Query: () => 'hello world!'
}
const schema = makeExecutableSchema({
  typeDefs,
  resolvers
});

// Run the query:
const query = `{
  hello
}`;

console.log('returned:', magicFunction(query, schema));

此外,如果请求来自浏览器,我需要显示GraphiQL。

这样的事情有可能发生吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-07 00:30:56

您要查找的魔术函数名为execute。注意,您首先需要对查询执行parsevalidate操作。

我建议看看the source of graphql-express来了解它是做什么的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63766387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档