# graphql-ts-gen

> You put schema.graphql. It make query generator. Yes, this is query generator generator.

Latest version **1.0.11** (published 2019-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-ts-gen
pnpm add graphql-ts-gen
yarn add graphql-ts-gen
bun add graphql-ts-gen
```

Provides the command `graphql-ts-gen`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2019-04-07 |
| First published | 2019-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 52.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Nam SeHyun |
| Maintainers | skatpgusskat |

## Links

- npm: https://www.npmjs.com/package/graphql-ts-gen
- npm.io page: https://npm.io/package/graphql-ts-gen

## Dependencies (4)

- [graphql](https://npm.io/package/graphql.md) ^0.13.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.1
- [typescript](https://npm.io/package/typescript.md) ^3.2.2
- [@types/node](https://npm.io/package/@types/node.md) ^10.12.18

## Recent versions

- 1.0.11 (latest) — 2019-04-07
- 1.0.10 — 2019-04-02
- 1.0.9 — 2019-03-25
- 1.0.8 — 2019-03-24
- 1.0.7 — 2019-02-22
- 1.0.6 — 2019-02-22
- 1.0.5 — 2019-02-22
- 1.0.4 — 2019-02-22
- 1.0.3 — 2019-02-21
- 1.0.2 — 2019-02-21
- 1.0.1 — 2019-02-21
- 1.0.0 — 2019-02-21

## README

# What is it?

You put schema.graphql. It make query generator. Yes, this is query generator generator.

# How it works?

Check `test/expected.ts` please. I will put more description later.

# Example

``` ts
import { ExtractTypeFromGraphQLQuery, Query, Post, User } from "./expected";

const query = Query       // {
  .addPost(1, Post        //   post(postId: 1) {
    .addId()              //     id
    .addWriter(User       //     writer {
      .addId()            //       id
      .addUsername()      //       username
    )                     //     }
    .addComments(Comment  //     comments {
      .addId()            //       id
    )                     //     }
    .addCreatedAt()       //     createdAt
  );                      //   }
                          // }


// Same with ES6 Fetch's option.
const fetchOptions = {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
  },
  // body: // NO!! You don't have to set body. YOU SHOULDN'T SET BODY YOURSELF!
}

// https://graphql.org/learn/serving-over-http/#response
const { data, errors } = await query.fetch('your-graphql-server-url', fetchOptions);

data.post.id;
data.post.title;  // <- typescript error, because you didn't add 'title' on query.
data.post.writer.id;
data.post.writer.username;

// <Scalar - Date>
data.post.createdAt;  // data.post.createdAt instanceof Date === true

// <Array>
data.post.comments[0].id
data.post.comments[123123].id

// true
query.toString() === `{
  post(postId: 1) {
    id
    writer {
      id
      username
    }
    comments {
      id
    }
    createdAt
  }
}`;

const result: GraphQLQueryType<typeof query> = yourQueryResultFromServer;

// No Typescript Compile Error, Yes Intellisense Auto Complete!
result.post;
result.post.id;
result.post.writer;
result.post.writer.id;
result.post.writer.username;
result.post.comments;
result.post.comments[0].id;
result.post.createdAt;

```

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