apollo-server/packages/apollo-server-azure-functions
Sashko Stubailo 2dddbc52b6 1.1.2 (#515)
* 1.1.2

* Add package lock to gitignore

* v1.1.2

* vundefined
2017-08-23 21:34:26 -07:00
..
src Azure Functions bindings (#503) 2017-08-15 09:59:29 +02:00
.npmignore Azure Functions bindings (#503) 2017-08-15 09:59:29 +02:00
package.json 1.1.2 (#515) 2017-08-23 21:34:26 -07:00
README.md Azure Functions bindings (#503) 2017-08-15 09:59:29 +02:00
tsconfig.json Azure Functions bindings (#503) 2017-08-15 09:59:29 +02:00

graphql-server-lambda

This is the Azure Functions integration for the Apollo community GraphQL Server. Read the docs.

Example:

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);
  }
};