# @mediamartin/ts-gql-sdk

> Generate a complete GraphQL SDK from schema, generating all queries/mutations/subscriptions along the way.

Latest version **1.0.11** (published 2021-09-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mediamartin/ts-gql-sdk
pnpm add @mediamartin/ts-gql-sdk
yarn add @mediamartin/ts-gql-sdk
bun add @mediamartin/ts-gql-sdk
```

Provides the command `tsgqlsdk`.

## 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 | 2021-09-30 |
| First published | 2021-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 17.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | shotor |
| Maintainers | mediamartin |

## Links

- npm: https://www.npmjs.com/package/@mediamartin/ts-gql-sdk
- Repository: https://github.com/mediamartin/ts-gql-sdk-gen
- Homepage: https://github.com/mediamartin/ts-gql-sdk-gen#readme
- Issues: https://github.com/mediamartin/ts-gql-sdk-gen/issues
- npm.io page: https://npm.io/package/@mediamartin/ts-gql-sdk

## Dependencies (9)

- [graphql](https://npm.io/package/graphql.md) 15.5.1
- [commander](https://npm.io/package/commander.md) 8.0.0
- [gql-generator](https://npm.io/package/gql-generator.md) 1.0.12
- [@graphql-tools/load](https://npm.io/package/@graphql-tools/load.md) 6.2.8
- [@graphql-codegen/core](https://npm.io/package/@graphql-codegen/core.md) 1.17.10
- [@graphql-codegen/typescript](https://npm.io/package/@graphql-codegen/typescript.md) 1.22.4
- [@graphql-tools/graphql-file-loader](https://npm.io/package/@graphql-tools/graphql-file-loader.md) 6.2.7
- [@graphql-codegen/typescript-operations](https://npm.io/package/@graphql-codegen/typescript-operations.md) 1.18.3
- [@graphql-codegen/typescript-graphql-request](https://npm.io/package/@graphql-codegen/typescript-graphql-request.md) 3.2.4

## Recent versions

- 1.0.11 (latest) — 2021-09-30
- 1.0.10 — 2021-09-30

## README

# ts-gql-sdk-gen

Generate a complete GraphQL SDK from schema, generating all queries/mutations/subscriptions along the way.

Basically hacks the following two great packages together:

- [GraphQL Code Generator](https://www.graphql-code-generator.com/)
- [GQL Generator](https://github.com/timqian/gql-generator)

## Usage

### Install

```sh
yarn global add @shotor/tsgqlsdk

# or install locally
yarn add -D @shotor/tsgqlsdk
```

### Run

Given schema file

```graphql
# Sample schema
type Query {
  user(id: Int!): User!
}

type User {
  id: Int!
  username: String!
  email: String!
  createdAt: String!
}
```

Run the program

```sh
tsgqlsdk /path/to/schema.graphql /path/to/destination
```

In the destination folder you will find the following folder structure

```
- /queries
- /mutations
- /subscriptions
- gql-sdk.ts
```

Make sure `graphql-request` is installed in your project.

```sh
yarn add graphql-request
```

Then import and use the `gql-sdk.ts` and use fully typed API:

```ts
import { GraphQLClient } from 'graphql-request'
import { getSdk } from '/path/to/destination/gql-sdk.ts'

const sdk = getSdk(new GraphQLClient('http://example.org/graphql'))

desribe('test user', () => {
  it('gets user', async () => {
    const ID = 300
    const result = await sdk.user({
      id: ID,
    })

    expect(result.id).toBe(ID)
  })
})
```

## License

MIT

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