具有Azure功能的Graphql

编程入门 行业动态 更新时间:2024-10-25 08:26:12
本文介绍了具有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

本文发布于:2023-11-28 07:49:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641540.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   Azure   Graphql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!