# apollo-resolver-gcs

> A resolver function for Apollo Server which loads serialized data from Google Cloud Storage

Latest version **0.1.1** (published 2018-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install apollo-resolver-gcs
pnpm add apollo-resolver-gcs
yarn add apollo-resolver-gcs
bun add apollo-resolver-gcs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2018-12-17 |
| First published | 2018-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | paulmelnikow |
| Keywords | apollo, apollo-server, google-cloud-storage, google-cloud, gcs |

## Links

- npm: https://www.npmjs.com/package/apollo-resolver-gcs
- npm.io page: https://npm.io/package/apollo-resolver-gcs

## Dependencies (3)

- [dotenv](https://npm.io/package/dotenv.md) ^6.1.0
- [graphql](https://npm.io/package/graphql.md) ^14.0.2
- [@google-cloud/storage](https://npm.io/package/@google-cloud/storage.md) ^2.3.1

## 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

- 0.1.1 (latest) — 2018-12-17
- 0.1.0 — 2018-11-17

## README

# apollo-resolver-gcs

[![version](https://img.shields.io/npm/v/apollo-resolver-gcs.svg?style=flat-square)][npm]
[![license](https://img.shields.io/npm/l/apollo-resolver-gcs.svg?style=flat-square)][npm]
[![build](https://img.shields.io/circleci/project/github/metabolize/apollo-resolver-gcs.svg?style=flat-square)][build]
[![code style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)][prettier]

[npm]: https://npmjs.com/apollo-resolver-gcs/
[build]: https://circleci.com/gh/metabolize/apollo-resolver-gcs/tree/master
[prettier]: https://prettier.io/

A resolver function for [Apollo Server][] which loads serialized data from
Google Cloud Storage.

This is intended for loading static data backed by S3 but may be useful for
other functions as well.

Based on the example server in the Apollo Server 2 [Getting Started][] guide.

[apollo server]: https://www.apollographql.com/docs/apollo-server/
[getting started]: https://www.apollographql.com/docs/apollo-server/getting-started.html

## Usage

```js
const { ApolloServer } = require('apollo-server')
const { createResolver } = require('apollo-resolver-gcs')

const typeDefs = ...

const getBook = createResolver({
  projectId: 'sandbox-123545',
  bucketName: 'all-my-books',
  argsToKey: ({ slug }) => `${slug}.json`,
})

const resolvers = {
  Query: {
    getBook,
  },
}

const server = new ApolloServer({ typeDefs, resolvers })

await server.listen()
```

In this example, `getBook(slug: "harry-potter")` returns the deserialized
contents of `gcs://all-my-books/harry-potter.json`.

## Authentication

Follow the [Google Cloud Storage quickstart][quickstart]. In particular, you
must [set up authentication][auth] using `gcloud auth login` and
`gcloud auth application-default login`, or using a service account and
setting the `GOOGLE_APPLICATION_CREDENTIALS` access variable.

[quickstart]: https://github.com/googleapis/nodejs-storage#quickstart
[auth]: https://cloud.google.com/docs/authentication/getting-started

## Running the example server

1. Designate a bucket for the example server.
2. Copy `example.env` to `.env` and set the relevant variables.
3. Run `npm run load-server-fixtures` to load the fixtures into the bucket.
4. Run `npm start` to start the server.
5. Open `https://localhost:4000/`. You should see the GraphQL Playground
   explorer tool.
6. Run a query:

```gql
{
  getBook(slug: "harry-potter") {
    title
    author
  }
}
```

You should see the result:

```json
{
  "data": {
    "getBook": {
      "title": "Harry Potter and the Chamber of Secrets",
      "author": "J.K. Rowling"
    }
  }
}
```

## Running the tests

1. Designate a bucket for the example server.
2. Copy `example.env` to `.env` and set the relevant variables.
3. Run `npm test`.

## License

This project is licensed under the MIT license.

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