2017-12-11 23:11:11 -08:00
|
|
|
---
|
|
|
|
title: Azure Functions
|
|
|
|
description: Setting up Apollo Server with Azure Functions
|
|
|
|
---
|
2017-08-15 09:59:29 +02:00
|
|
|
|
2018-03-28 14:03:32 -07:00
|
|
|
[](https://badge.fury.io/js/apollo-server-core) [](https://circleci.com/gh/apollographql/apollo-cache-control-js) [](https://coveralls.io/github/apollographql/apollo-server?branch=master) [](https://www.apollographql.com/#slack)
|
2017-12-11 23:11:11 -08:00
|
|
|
|
|
|
|
This is the Azure Functions integration for the Apollo community GraphQL Server. [Read the docs.](https://www.apollographql.com/docs/apollo-server/)
|
2017-08-15 09:59:29 +02:00
|
|
|
|
|
|
|
## Example:
|
|
|
|
|
|
|
|
```js
|
2018-01-09 00:08:01 +01:00
|
|
|
const server = require('apollo-server-azure-functions');
|
|
|
|
const graphqlTools = require('graphql-tools');
|
2017-08-15 09:59:29 +02:00
|
|
|
|
|
|
|
const typeDefs = `
|
|
|
|
type Random {
|
|
|
|
id: Int!
|
|
|
|
rand: String
|
|
|
|
}
|
|
|
|
|
|
|
|
type Query {
|
|
|
|
rands: [Random]
|
|
|
|
rand(id: Int!): Random
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2018-01-09 00:08:01 +01:00
|
|
|
const rands = [{ id: 1, rand: 'random' }, { id: 2, rand: 'modnar' }];
|
2017-08-15 09:59:29 +02:00
|
|
|
|
|
|
|
const resolvers = {
|
|
|
|
Query: {
|
|
|
|
rands: () => rands,
|
2018-01-09 00:08:01 +01:00
|
|
|
rand: (_, { id }) => rands.find(rand => rand.id === id),
|
|
|
|
},
|
2017-08-15 09:59:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const schema = graphqlTools.makeExecutableSchema({
|
|
|
|
typeDefs,
|
2018-01-09 00:08:01 +01:00
|
|
|
resolvers,
|
2017-08-15 09:59:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = function run(context, request) {
|
2018-01-09 00:08:01 +01:00
|
|
|
if (request.method === 'POST') {
|
2017-08-15 09:59:29 +02:00
|
|
|
server.graphqlAzureFunctions({
|
2018-01-09 00:08:01 +01:00
|
|
|
endpointURL: '/api/graphql',
|
2018-03-12 12:33:13 -04:00
|
|
|
schema: schema,
|
2017-08-15 09:59:29 +02:00
|
|
|
})(context, request);
|
2018-01-09 00:08:01 +01:00
|
|
|
} else if (request.method === 'GET') {
|
2017-08-15 09:59:29 +02:00
|
|
|
return server.graphiqlAzureFunctions({
|
2018-01-09 00:08:01 +01:00
|
|
|
endpointURL: '/api/graphql',
|
2017-08-15 09:59:29 +02:00
|
|
|
})(context, request);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
```
|
2018-03-27 09:22:13 -07:00
|
|
|
|
|
|
|
[Read the CHANGELOG.](https://github.com/apollographql/apollo-server/blob/master/CHANGELOG.md)
|