Arj*_*Arj 2 azure graphql azure-functions
有没有办法通过azure函数和nodejs实现Graphql.例如,像https://www.npmjs.com/package/graphql-server-lambda
Apollo为GraphQL提供Azure功能集成:
以下是他们的github回购提供的示例:
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);
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5314 次 |
| 最近记录: |