mirror of
https://github.com/vale981/apollo-server
synced 2025-03-10 13:06:39 -04:00

* Setup prettier and precommit hooks * Format code with prettier * Use husky because it works... * Move prettier config to .prettierrc file * Implement fixing markdown file formatting when running lint-fix script * Format markdown files * Add .json file formatting * Fixes json file formatting * Add pretteir linting step * Remove tslint * Use gitignore for prettier * Fix linting errors * Ignore submodule folder
53 lines
1.6 KiB
Markdown
Executable file
53 lines
1.6 KiB
Markdown
Executable file
---
|
|
title: Azure Functions
|
|
description: Setting up Apollo Server with Azure Functions
|
|
---
|
|
|
|
[](https://badge.fury.io/js/apollo-server-core) [](https://travis-ci.org/apollographql/apollo-server) [](https://coveralls.io/github/apollographql/apollo-server?branch=master) [](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/)
|
|
|
|
## Example:
|
|
|
|
```js
|
|
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);
|
|
}
|
|
};
|
|
```
|