apollo-server/packages/apollo-server-azure-functions
David Glasser b32e89c060 v1.3.6
2018-04-24 11:35:14 -07:00
..
src Use named arrow functions for all middlewares, including GraphiQL. 2018-04-18 10:41:04 +03:00
.npmignore include readme for npm packages 2017-10-23 15:13:31 -07:00
package.json v1.3.6 2018-04-24 11:35:14 -07:00
README.md Azure Functions now returns correct response body (#753) 2018-04-17 21:39:06 +03: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.

Sample Code

GraphQL:

const { graphqlAzureFunctions } = require('apollo-server-azure-functions');
const { makeExecutableSchema } = 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 = makeExecutableSchema({
  typeDefs,
  resolvers,
});

module.exports = function run(context, request) {
  graphqlAzureFunctions({ schema })(context, request);
};

GraphiQL

const { graphiqlAzureFunctions } = require('apollo-server-azure-functions');

export function run(context, request) {
  let query = `
    {
      rands {
        id
        rand
      }
    }
  `;

  // End point points to the path to the GraphQL API function
  graphiqlAzureFunctions({ endpointURL: '/api/graphql', query })(
    context,
    request,
  );
}