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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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',
})(context, request);
} else if (request.method === 'GET') {
return server.graphiqlAzureFunctions({
endpointURL: '/api/graphql',
})(context, request);
}
};
Edit on GitHub