apollo-server/packages/apollo-server-azure-functions/README.md
David Glasser 0f7c1c53b4
Update CHANGELOG for all releases back to v1.1.3 (#915)
There were many missing releases and bullet points as well as inaccurate
ones. For example, it was impossible to figure out that users of Hapi 16 who
want to use Apollo Cache Control needed to use precisely version 1.2.0 of
apollo-server-hapi (which wasn't even mentioned).

Link to CHANGELOG from all READMEs. Add READMEs for the graphql-server-*
packages. Add an explanation of our versioning system to the top of
CHANGELOG.md.
2018-03-27 09:22:13 -07:00

1.7 KiB
Executable file

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

Read the CHANGELOG.