# graphql-typeorm-error-parser

> A utility for parsing graphql errors into form field errors

Latest version **1.1.1** (published 2020-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-typeorm-error-parser
pnpm add graphql-typeorm-error-parser
yarn add graphql-typeorm-error-parser
bun add graphql-typeorm-error-parser
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2020-03-28 |
| First published | 2020-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jim Schuster |
| Maintainers | yis4yimmy |
| Keywords | graphql, typeorm, class-validator, error |

## Links

- npm: https://www.npmjs.com/package/graphql-typeorm-error-parser
- Repository: https://github.com/yis4yimmy/graphql-typeorm-error-parser
- Homepage: https://github.com/yis4yimmy/graphql-typeorm-error-parser#readme
- Issues: https://github.com/yis4yimmy/graphql-typeorm-error-parser/issues
- npm.io page: https://npm.io/package/graphql-typeorm-error-parser

## Dependencies (3)

- [graphql](https://npm.io/package/graphql.md) ^14.6.0
- [apollo-client](https://npm.io/package/apollo-client.md) ^2.6.8
- [pg-error-constants](https://npm.io/package/pg-error-constants.md) ^1.0.0

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.1.1 (latest) — 2020-03-28
- 2.0.0-beta.1 (beta) — 2020-12-20
- 1.1.0 — 2020-03-28
- 1.0.0 — 2020-03-28

## README

# graphql-typeorm-error-parser

A utility for parsing graphql errors into form field errors

## Motivation

Writing validations in Typeorm with class-validator is very easy.
When it came to writing the front-end, it felt silly to me to have
to re-write my validations, especially custom validations.

The main problem I faced was that the validation errors come back
deeply nested within the GraphqlError. I found myself wishing for
the ease of Ruby on Rails, where I could simply get the errors for
each field of a form.

This utility aims to parse those deeply nested GraphQLErrors into
something useful for doing field level validation in the UI.

## Usage

### Installation

#### yarn

```bash
yarn add graphql-typeorm-error-parser
```

#### npm

```bash
npm i graphql-typeorm-error-parser
```

### Example

The getFieldErrors method is intended to be used with the `catch` of a `try/catch` block.
Your GraphQL backend should simply throw any errors from class-validator, the typeorm query failing, or other errors.

```javascript
import { getFieldErrors } from "graphql-typeorm-error-parser";

try {
  await useRegisterMutation({
    variables: {
      email: "joe@email.com",
      password: "weak",
    },
  });
} catch (gqlError) {
  const errors = getFieldErrors(gqlError, {
    fieldErrorValues: {
      as: "string",
      format: "sentence-case",
    },
  });

  console.log(errors);
  /**
   * { password: "Password must be at least 6 characters, Password must include a special character" }
   */
}
```

## Roadmap

- [x] Ability to parse validation errors from class-validator
- [x] Ability to parse query errors from postgres
- [x] Add basic options for the format errors are returned in

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