本文介绍了具有Azure功能的Graphql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种通过azure函数和nodejs实现Graphql的方法.例如,类似- www.npmjs/package/graphql-服务器lambda
is there a way to implement Graphql via azure functions and nodejs. For example, something like - www.npmjs/package/graphql-server-lambda
推荐答案Apollo为GraphQL提供了Azure功能集成:
Apollo provides Azure Function Integration for GraphQL:
apollo-server-azure-functions
以下是他们的github回购中提供的示例:
Here is the sample provided on their github repo:
const server = require("apollo-server-azure-functions"); const graphqlTools = require("graphql-tools"); const typeDefs = ` type Random { id: Int! rand: String } type Query { rands: [Random] rand(id: Int!): Random } `; const rands = [{ id: 1, rand: "random" }, { id: 2, rand: "modnar" }]; const resolvers = { Query: { rands: () => rands, rand: (_, { id }) => rands.find(rand => rand.id === id) } }; const schema = graphqlTools.makeExecutableSchema({ typeDefs, resolvers }); module.exports = function run(context, request) { if (request.method === "POST") { server.graphqlAzureFunctions({ endpointURL: '/api/graphql' })(context, request); } else if (request.method === "GET") { return server.graphiqlAzureFunctions({ endpointURL: '/api/graphql' })(context, request); } };更多推荐
具有Azure功能的Graphql
发布评论