# vtex-graphql-builder

> Helper for building vtex apps with graphql resolvers

Latest version **0.0.5** (published 2017-03-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install vtex-graphql-builder
pnpm add vtex-graphql-builder
yarn add vtex-graphql-builder
bun add vtex-graphql-builder
```

## 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.0.5 |
| Published | 2017-03-08 |
| First published | 2017-03-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mairatma |
| Maintainers | mairatma |
| Keywords | data, graphql |

## Links

- npm: https://www.npmjs.com/package/vtex-graphql-builder
- Repository: https://github.com/vtex/vtex-graphql-builder
- Homepage: https://github.com/vtex/vtex-graphql-builder#readme
- Issues: https://github.com/vtex/vtex-graphql-builder/issues
- npm.io page: https://npm.io/package/vtex-graphql-builder

## Dependencies (1)

- [co-body](https://npm.io/package/co-body.md) ^4.2.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

- 0.0.5 (latest) — 2017-03-08
- 0.0.4 — 2017-03-08
- 0.0.3 — 2017-03-08
- 0.0.2 — 2017-03-08
- 0.0.1 — 2017-03-08

## README

# vtex-graphql-builder

Helper for building vtex apps with graphql resolvers

## Usage

When creating an app for [masterdata-graphql](https://github.com/vtex/masterdata-graphql), some
annoying common boilerplate is needed for the colossus resolvers, such as:

* Parsing the request's body with a module like `co-body`.
* Manually selecting what resolver to run based on the request's path.
* Building error responses in the right format (i.e. `{error: 'Error message here'}`).
* Setting the final response's status code and type

This tool can help minimize this boilerplate, letting you just define the actual resolver logic you need.

For example, let's say you have the following schema:

```gql
type Book {
  id: String
  name: String
  author: String
}

type Query {
  books: [Book]
  book(id: String): Book
}

type Mutation {
  deleteBook(id: String): Boolean
}
```

Then, with `vtex-graphql-builder` you can build resolvers for these by having a file
like this at `service/main.js`:

```js
const {buildResolvers} = require('vtex-graphql-builder')

export default buildResolvers({
    Query: {
        book: async ({data, root, cookie}, {account, workspace}, originalReq) => {
            // Handle the `book` query here and return the results as {data}.
            return {data: results}
        },

        books: async ({data, root, cookie}, {account, workspace}, originalReq) => {
            // Handle the `books` query here and return the results as {data}.
            return {data: results}
        }
    },
    Mutation: {
        deleteBook: async ({data, root, cookie}, {account, workspace}, originalReq) => {
            // Handle the `deleteBook` mutation here and return the results as {data}.
            return {data: results}
        }
    },
})
```

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