https://github.com/devxoul/graphql-codegen-typescript-fixtures
A plugin for graphql-code-generator that generates TypeScript fixtures for testing.
https://github.com/devxoul/graphql-codegen-typescript-fixtures
Last synced: 8 months ago
JSON representation
A plugin for graphql-code-generator that generates TypeScript fixtures for testing.
- Host: GitHub
- URL: https://github.com/devxoul/graphql-codegen-typescript-fixtures
- Owner: devxoul
- License: mit
- Created: 2021-09-19T21:55:58.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-20T12:30:36.000Z (over 3 years ago)
- Last Synced: 2025-02-03T17:55:49.012Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 229 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql-codegen-typescript-fixtures
[](https://badge.fury.io/js/graphql-codegen-typescript-fixtures)
[](https://github.com/devxoul/graphql-codegen-typescript-fixtures/actions/workflows/ci.yml)
A plugin for [graphql-code-generator](https://www.graphql-code-generator.com/) that generates TypeScript fixtures for testing.
## At a Glance
```tsx
import fixture from './generated/graphql-fixtures.ts'
const user = fixture('User')
user.name // ""
user.followers.totalCount // 0
// with Immer.js
const repo = fixture('Repository', repo => {
repo.name = 'my-cool-stuff'
repo.stargazerCount = 1234
})
repo.name // "my-cool-stuff"
repo.stargazerCount // 1234
```
## Features
* 🍭 Strongly typed.

* 🧬 Built-in support for [Immer](https://github.com/immerjs/immer) integration.

## Installation
* Using Yarn:
```console
$ yarn add graphql-codegen-typescript-fixtures --dev
```
* Using npm:
```console
$ npm install graphql-codegen-typescript-fixtures --dev
```
Add lines below in your graphql-codegen configuration file. Check out [Configuration](Configuration) section for more details.
```diff
generates:
src/generated/graphql.ts:
plugins:
- "typescript"
- "typescript-operations"
+ src/generated/graphql-fixtures.ts:
+ plugins:
+ - graphql-codegen-typescript-fixtures
config:
scalars:
Date: string
DateTime: string
+ fixtures:
+ typeDefinitionModule: "path/to/graphql/types.ts"
```
## Configuration
### typeDefinitionModule
*(Required)* A path for the GraphQL type definition module. This value is used to import the GraphQL type definitions.
For example:
```yaml
config:
fixtures:
typeDefinitionModule: "@src/generated/graphql"
```
And the generated code will be:
```ts
// src/generated/graphql-fixtures.ts
import * as types from '@src/generated/graphql'
```
### immer
*(Optional)* Whether to generate [Immer](https://github.com/immerjs/immer) integration.
For example:
```yaml
config:
fixtures:
immer: true
```
Then the second parameter of `fixture()` will become available.
```ts
fixture('User', user => {
user.name = 'Suyeol Jeon'
})
```
### scalarDefaults
*(Optional)* The default values of scalar types. Note that the values are directly written to the TypeScript code so you need to wrap strings with quotes properly.
For example:
```yaml
config:
fixtures:
scalarDefaults:
Date: "'2021-01-01'"
DateTime: "'2021-01-01T00:00:00+00:00'"
Timestamp: 1609426800
```
## License
This project is under MIT license. See the [LICENSE](LICENSE) file for more info.