【发布时间】:2020-12-25 05:09:42
【问题描述】:
我想构建一个 GraphQL API。但是,我不想使用 express 或 connect,这使我无法使用 express-graphql。我的模式是使用来自graphql-tools 的makeExecutableSchema 方法生成的。这意味着我需要以某种方式手动调用架构上的查询。
基本上,我需要这样的东西:
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。
这样的事情可能吗?
【问题讨论】:
-
"我不想使用 express 或 connect" - 你还在用什么?
-
@Bergi 我正在构建自己的框架,eon.js,我想在其中构建 grahpql 支持。在底层,eon 使用核心 http 模块。
标签: javascript node.js api graphql graphql-tools