apollo-server/packages/apollo-server-azure-functions
2018-06-11 12:13:03 +02:00
..
src Update devDependencies, including typescript 2018-06-11 12:13:03 +02:00
.npmignore include readme for npm packages 2017-10-23 15:13:31 -07:00
package.json Update devDependencies, including typescript 2018-06-11 12:13:03 +02:00
README.md Azure Functions now returns correct response body (#753) 2018-04-17 21:39:06 +03:00
tsconfig.json tsconfig: remove typeRoots from tsconfig and automatic retreival of node types 2018-05-21 15:29:37 -07: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,
  );
}