# apollo-server-micro

> Production-ready Node.js GraphQL server for Micro

Latest version **3.13.0** (published 2023-11-14) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install apollo-server-micro
pnpm add apollo-server-micro
yarn add apollo-server-micro
bun add apollo-server-micro
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.13.0 |
| Published | 2023-11-14 |
| First published | 2017-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 29.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 13954 |
| Author | Apollo |
| Maintainers | apollo-bot |
| Keywords | GraphQL, Apollo, Micro, Server, Javascript, ZEIT |

## Links

- npm: https://www.npmjs.com/package/apollo-server-micro
- Repository: https://github.com/apollographql/apollo-server
- Homepage: https://github.com/apollographql/apollo-server#readme
- Issues: https://github.com/apollographql/apollo-server/issues
- npm.io page: https://npm.io/package/apollo-server-micro

## Dependencies (4)

- [type-is](https://npm.io/package/type-is.md) ^1.6.18
- [@hapi/accept](https://npm.io/package/@hapi/accept.md) ^5.0.2
- [apollo-server-core](https://npm.io/package/apollo-server-core.md) ^3.13.0
- [apollo-server-types](https://npm.io/package/apollo-server-types.md) ^3.8.0

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 3.13.0 (latest) — 2023-11-14
- 2.26.2 (v2) — 2023-08-30
- 3.6.0-alpha.1 (alpha) — 2021-12-28
- 3.2.0 (next) — 2021-08-23
- 3.0.0-rc.1 (rc) — 2021-07-02
- 3.0.0-preview.4 (preview) — 2021-06-30
- 3.0.0-html.2 (html) — 2021-05-25
- 3.0.0-lambda.0 (alphalambda) — 2021-05-13
- 2.23.1-unified2.3 (unified) — 2021-04-27
- 3.0.0-alpha.3 (next-v3) — 2020-08-12
- 3.12.1 — 2023-08-30
- 3.12.0 — 2023-03-02
- 3.11.1 — 2022-11-03
- 3.11.0 — 2022-11-02
- 3.10.4 — 2022-10-31
- … 278 more at https://npm.io/package/apollo-server-micro/versions

## README

[![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-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-server)
[![Join the community forum](https://img.shields.io/badge/join%20the%20community-forum-blueviolet)](https://community.apollographql.com)
[![Read CHANGELOG](https://img.shields.io/badge/read-changelog-blue)](https://github.com/apollographql/apollo-server/blob/HEAD/CHANGELOG.md)


This is the [Micro](https://github.com/zeit/micro) integration for the Apollo community GraphQL Server. [Read the docs.](https://www.apollographql.com/docs/apollo-server/) [Read the CHANGELOG.](https://github.com/apollographql/apollo-server/blob/main/CHANGELOG.md)

A full example of how to use `apollo-server-micro` can be found in [the docs](https://www.apollographql.com/docs/apollo-server/integrations/middleware/#apollo-server-micro).

## CORS Example

This example demonstrates how to setup a simple Micro + CORS + GraphQL
microservice, using [`micro-cors`](https://github.com/possibilities/micro-cors):

1) Package installation.

```shell
npm install micro micro-cors apollo-server-micro graphql
```

2) `index.js`

```js
const cors = require('micro-cors')(); // highlight-line
const { ApolloServer, gql } = require('apollo-server-micro');
const { send } = require('micro');

const typeDefs = gql`
  type Query {
    sayHello: String
  }
`;

const resolvers = {
  Query: {
    sayHello(parent, args, context) {
      return 'Hello World!';
    },
  },
};

const apolloServer = new ApolloServer({ typeDefs, resolvers });
module.exports = apolloServer.start().then(() => {
  const handler = apolloServer.createHandler();
  return cors((req, res) => req.method === 'OPTIONS' ? send(res, 200, 'ok') : handler(req, res))
});
```

3) `package.json`

```json
{
  "main": "index.js",
  "scripts": {
    "start": "micro"
  }
}
```

4) After an `npm start`, access `http://localhost:3000/graphql` in your
browser to run queries using
[`graphql-playground`](https://github.com/prismagraphql/graphql-playground),
or send GraphQL requests directly to the same URL.

## Custom GraphQL Path Example

This example shows how to setup a simple Micro + GraphQL microservice, that
uses a custom GraphQL endpoint path:

1) Package installation.

```shell
npm install micro apollo-server-micro graphql
```

2) `index.js`

```js
const { ApolloServer, gql } = require('apollo-server-micro');

const typeDefs = gql`
  type Query {
    sayHello: String
  }
`;

const resolvers = {
  Query: {
    sayHello(parent, args, context) {
      return 'Hello World!';
    },
  },
};

const apolloServer = new ApolloServer({ typeDefs, resolvers });
module.exports = apolloServer.start().then(() => {
  return apolloServer.createHandler({ path: '/data' });  // highlight-line
});
```

3) `package.json`

```json
{
  "main": "index.js",
  "scripts": {
    "start": "micro"
  }
}
```

4) After an `npm start`, access `http://localhost:3000/data` in your
browser to run queries using
[`graphql-playground`](https://github.com/prismagraphql/graphql-playground),
or send GraphQL requests directly to the same URL.

## Fully Custom Routing Example

This example demonstrates how to setup a simple Micro + GraphQL microservice,
that uses [`micro-router`](https://github.com/pedronauck/micro-router) for
fully custom routing:

1) Package installation.

```shell
npm install micro microrouter apollo-server-micro graphql
```

2) `index.js`

```js{1,21-26}
const { router, get, post, options } = require('microrouter');
const { ApolloServer, gql } = require('apollo-server-micro');

const typeDefs = gql`
  type Query {
    sayHello: String
  }
`;

const resolvers = {
  Query: {
    sayHello(parent, args, context) {
      return 'Hello World!';
    },
  },
};

const apolloServer = new ApolloServer({ typeDefs, resolvers });
module.exports = apolloServer.start().then(() => {
  const graphqlPath = '/data';
  const graphqlHandler = apolloServer.createHandler({ path: graphqlPath });
  return router(
    get('/', (req, res) => 'Welcome!'),
    post(graphqlPath, graphqlHandler),
    get(graphqlPath, graphqlHandler),
  );
});
```

3) `package.json`

```json
{
  "main": "index.js",
  "scripts": {
    "start": "micro"
  }
}
```

4) After an `npm start`, access `http://localhost:3000/data` in your
browser to run queries using
[`graphql-playground`](https://github.com/prismagraphql/graphql-playground),
or send GraphQL requests directly to the same URL.

---
_Source: https://npm.io/package/apollo-server-micro · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
