apollo-server/packages/apollo-server-azure-functions
Sashko Stubailo 281392c3f0 Update to graphql@0.12 (#726)
* Update peer deps and tests for 0.12
* v1.3.2
2018-03-13 17:10:37 +02:00
..
src Setup prettier (#724) 2018-01-08 15:08:01 -08:00
.npmignore include readme for npm packages 2017-10-23 15:13:31 -07:00
package.json Update to graphql@0.12 (#726) 2018-03-13 17:10:37 +02:00
README.md Fix sample in Azure function README.md (#747) 2018-03-12 18:33:13 +02:00
tsconfig.json Setup prettier (#724) 2018-01-08 15:08:01 -08:00

title description
Azure Functions Setting up Apollo Server with Azure Functions

npm version Build Status Coverage Status Get on Slack

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',
      schema: schema,
    })(context, request);
  } else if (request.method === 'GET') {
    return server.graphiqlAzureFunctions({
      endpointURL: '/api/graphql',
    })(context, request);
  }
};