apollo-server/packages/apollo-server-azure-functions
Jesse Rosenberger f8ca710279 Use named arrow functions for all middlewares, including GraphiQL.
As originally reported in [0], this should make debugging performance issues
easier, since the name of the function will be properly displayed/shown in
flame-graphs.

[0]: https://github.com/apollographql/apollo-server/pull/827
2018-04-18 10:41:04 +03: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.4 2018-03-28 13:57:11 -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,
  );
}