apollo-server/packages/apollo-server-azure-functions/README.md

57 lines
1.8 KiB
Markdown
Raw Normal View History

---
title: Azure Functions
description: Setting up Apollo Server with Azure Functions
---
2017-08-15 09:59:29 +02:00
[![npm version](https://badge.fury.io/js/apollo-server-core.svg)](https://badge.fury.io/js/apollo-server-core) [![Build Status](https://circleci.com/gh/apollographql/apollo-cache-control-js.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-cache-control-js) [![Coverage Status](https://coveralls.io/repos/github/apollographql/apollo-server/badge.svg?branch=master)](https://coveralls.io/github/apollographql/apollo-server?branch=master) [![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://www.apollographql.com/#slack)
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
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
}
`;
const rands = [{ id: 1, rand: 'random' }, { id: 2, rand: 'modnar' }];
2017-08-15 09:59:29 +02:00
const resolvers = {
Query: {
rands: () => rands,
rand: (_, { id }) => rands.find(rand => rand.id === id),
},
2017-08-15 09:59:29 +02:00
};
const schema = graphqlTools.makeExecutableSchema({
typeDefs,
resolvers,
2017-08-15 09:59:29 +02:00
});
module.exports = function run(context, request) {
if (request.method === 'POST') {
2017-08-15 09:59:29 +02:00
server.graphqlAzureFunctions({
endpointURL: '/api/graphql',
schema: schema,
2017-08-15 09:59:29 +02:00
})(context, request);
} else if (request.method === 'GET') {
2017-08-15 09:59:29 +02:00
return server.graphiqlAzureFunctions({
endpointURL: '/api/graphql',
2017-08-15 09:59:29 +02:00
})(context, request);
}
};
```
[Read the CHANGELOG.](https://github.com/apollographql/apollo-server/blob/master/CHANGELOG.md)