我正在开发一个使用graphql的express后端,我不知道是否需要使用express-graphql或appolo-server-graphql库。谢谢你的帮助!
发布于 2019-04-25 02:47:56
我建议使用apollo-server-express而不是express-graphql。它们非常相似,但apollo-server-express有更多的花哨,同时拥有一个更简单、更清晰的API IMO。
对我来说,apollo-server-express最大的改进是它的游乐场:https://github.com/prisma/graphql-playground
出于几个原因,playground比express-graphql的graphiql更好,但一个重要的原因是,它允许您在请求中放置HTTP头,这更适合于处理会话。
www.graphqlbin.com将允许您在任何没有cors的端点上使用游乐场。如果你有cors,那么你需要直接从你的服务器上运行playground。
下面是一个示例代码,可以帮助您入门:
const { ApolloServer } = require('apollo-server-express')
const graphqlServer = new ApolloServer({
schema,
introspection: true,
playground: true,
})
graphqlServer.applyMiddleware({
app
})https://stackoverflow.com/questions/55834809
复制相似问题