我想构建一个 GraphQL API。但是,我不想使用 express 或 connect,这使我无法使用express-graphql
. 我的架构是使用 from 的makeExecutableSchema
方法生成的graphql-tools
。这意味着我需要以某种方式手动调用架构上的查询。
基本上,我需要这样的东西:
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。
这样的事情可能吗?