Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# graphql-fabbrica
# graphql-codegen-typescript-fabbrica

GraphQL Code Generator Plugin to define mock data factory.

## Installation

```sh
npm install --save-dev @mizdra/graphql-fabbrica
npm install --save-dev @mizdra/graphql-codegen-typescript-fabbrica
```

## Requirements
Expand Down Expand Up @@ -34,7 +34,7 @@ const config: CodegenConfig = {
},
},
'./__generated__/fabbrica.ts': {
plugins: ['@mizdra/graphql-fabbrica'],
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
config: {
typesFile: './types', // required
},
Expand Down Expand Up @@ -385,7 +385,7 @@ const config: CodegenConfig = {
},
},
'./__generated__/fabbrica.ts': {
plugins: ['@mizdra/graphql-fabbrica'],
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
config: {
// ...
skipTypename: true,
Expand Down Expand Up @@ -417,7 +417,7 @@ const config: CodegenConfig = {
},
},
'./__generated__/fabbrica.ts': {
plugins: ['@mizdra/graphql-fabbrica'],
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
config: {
// ...
skipIsAbstractType: false,
Expand Down Expand Up @@ -446,7 +446,7 @@ const config: CodegenConfig = {
},
},
'./__generated__/fabbrica.ts': {
plugins: ['@mizdra/graphql-fabbrica'],
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
config: {
// ...
nonOptionalDefaultFields: true,
Expand All @@ -463,7 +463,7 @@ type: `NamingConvention`, default: `change-case-all#pascalCase`

Allow you to override the naming convention of the output.

This option is compatible with [the one for typescript plugin](https://the-guild.dev/graphql/codegen/docs/config-reference/naming-convention#namingconvention). If you specify it for the typescript plugin, you must set the same value for graphql-fabbrica.
This option is compatible with [the one for typescript plugin](https://the-guild.dev/graphql/codegen/docs/config-reference/naming-convention#namingconvention). If you specify it for the typescript plugin, you must set the same value for graphql-codegen-typescript-fabbrica.

```ts
import { CodegenConfig } from '@graphql-codegen/cli';
Expand All @@ -478,7 +478,7 @@ const config: CodegenConfig = {
// ...
},
'./__generated__/fabbrica.ts': {
plugins: ['@mizdra/graphql-fabbrica'],
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
// ...
},
},
Expand All @@ -492,7 +492,7 @@ type: `string`, default: `''`

Prefixes all the generated types.

This option is compatible with [the one for typescript plugin](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#typesprefix). If you specify it for the typescript plugin, you must set the same value for graphql-fabbrica.
This option is compatible with [the one for typescript plugin](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#typesprefix). If you specify it for the typescript plugin, you must set the same value for graphql-codegen-typescript-fabbrica.

```ts
import { CodegenConfig } from '@graphql-codegen/cli';
Expand All @@ -507,7 +507,7 @@ const config: CodegenConfig = {
// ...
},
'./__generated__/fabbrica.ts': {
plugins: ['@mizdra/graphql-fabbrica'],
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
// ...
},
},
Expand All @@ -521,7 +521,7 @@ type: `string`, default: `''`

Suffixes all the generated types.

This option is compatible with [the one for typescript plugin](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#typessuffix). If you specify it for the typescript plugin, you must set the same value for graphql-fabbrica.
This option is compatible with [the one for typescript plugin](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#typessuffix). If you specify it for the typescript plugin, you must set the same value for graphql-codegen-typescript-fabbrica.

## Troubleshooting

Expand Down Expand Up @@ -579,7 +579,7 @@ const AuthorFactory = defineAuthorFactory({
});
```

### `error TS2307: Cannot find module '@mizdra/graphql-fabbrica/helper' or its corresponding type declarations.`
### `error TS2307: Cannot find module '@mizdra/graphql-codegen-typescript-fabbrica/helper' or its corresponding type declarations.`

Incorrect values for the `moduleResolution` option in `tsconfig.json` cause compile errors.

Expand All @@ -593,9 +593,9 @@ Incorrect values for the `moduleResolution` option in `tsconfig.json` cause comp

```console
$ npx tsc --noEmit
__generated__/1-basic/fabbrica.ts:7:8 - error TS2307: Cannot find module '@mizdra/graphql-fabbrica/helper' or its corresponding type declarations.
__generated__/1-basic/fabbrica.ts:7:8 - error TS2307: Cannot find module '@mizdra/graphql-codegen-typescript-fabbrica/helper' or its corresponding type declarations.

7 } from '@mizdra/graphql-fabbrica/helper';
7 } from '@mizdra/graphql-codegen-typescript-fabbrica/helper';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

Expand All @@ -613,6 +613,6 @@ To resolve this error, set the value of `moduleResolution` to `Bundler`, `Node16

This library is licensed under the MIT license.

The copyright contains two names. The first is [@mizdra](https://github.com/mizdra), author of graphql-fabbrica. The second is [@Quramy](https://github.com/Quramy), author of [prisma-fabbrica](https://github.com/Quramy/prisma-fabbrica).
The copyright contains two names. The first is [@mizdra](https://github.com/mizdra), author of graphql-codegen-typescript-fabbrica. The second is [@Quramy](https://github.com/Quramy), author of [prisma-fabbrica](https://github.com/Quramy/prisma-fabbrica).

The name of the author of prisma-fabbrica is written because graphql-fabbrica reuses some of prisma-fabbrica's code.
The name of the author of prisma-fabbrica is written because graphql-codegen-typescript-fabbrica reuses some of prisma-fabbrica's code.
8 changes: 4 additions & 4 deletions e2e/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const config: CodegenConfig = {
},
'./__generated__/1-basic/fabbrica.ts': {
schema: './1-basic-schema.graphql',
plugins: ['@mizdra/graphql-fabbrica'],
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
config: {
...defaultFabbricaPluginConfig,
namingConvention: {
Expand All @@ -47,7 +47,7 @@ const config: CodegenConfig = {
},
'./__generated__/2-typesPrefix/fabbrica.ts': {
schema: './2-typesPrefix-schema.graphql',
plugins: ['@mizdra/graphql-fabbrica'],
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
config: {
...defaultFabbricaPluginConfig,
typesPrefix: 'Prefix',
Expand All @@ -63,7 +63,7 @@ const config: CodegenConfig = {
},
'./__generated__/3-typesSuffix/fabbrica.ts': {
schema: './3-typesSuffix-schema.graphql',
plugins: ['@mizdra/graphql-fabbrica'],
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
config: {
...defaultFabbricaPluginConfig,
typesSuffix: 'Suffix',
Expand All @@ -78,7 +78,7 @@ const config: CodegenConfig = {
},
'./__generated__/4-non-optional-fields/fabbrica.ts': {
schema: './4-non-optional-fields-schema.graphql',
plugins: ['@mizdra/graphql-fabbrica'],
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
config: {
...defaultFabbricaPluginConfig,
nonOptionalDefaultFields: true,
Expand Down
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"node": ">=18.0.0"
},
"dependencies": {
"@mizdra/graphql-fabbrica": ".."
"@mizdra/graphql-codegen-typescript-fabbrica": ".."
}
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@mizdra/graphql-fabbrica",
"name": "@mizdra/graphql-codegen-typescript-fabbrica",
"description": "GraphQL Code Generator Plugin to define mock data factory.",
"version": "0.2.0",
"type": "commonjs",
"sideEffects": false,
"repository": "https://github.com/mizdra/graphql-fabbrica.git",
"repository": "https://github.com/mizdra/graphql-codegen-typescript-fabbrica.git",
"author": "mizdra <[email protected]>",
"license": "MIT",
"private": false,
Expand Down
4 changes: 2 additions & 2 deletions src/__snapshots__/code-generator.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ exports[`generateCode > generates code 1`] = `
type TypeFactoryInterface,
type DefaultFieldsResolver,
defineTypeFactoryInternal,
} from '@mizdra/graphql-fabbrica/helper';
} from '@mizdra/graphql-codegen-typescript-fabbrica/helper';
import type { Maybe, Book, Author } from './types';

export * from '@mizdra/graphql-fabbrica/helper';
export * from '@mizdra/graphql-codegen-typescript-fabbrica/helper';
export type OptionalBook = {
id: string;
title: string;
Expand Down
4 changes: 2 additions & 2 deletions src/code-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
type TypeFactoryInterface,
type DefaultFieldsResolver,
defineTypeFactoryInternal,
} from '@mizdra/graphql-fabbrica/helper';
} from '@mizdra/graphql-codegen-typescript-fabbrica/helper';
import type { Maybe, ${joinedTypeNames} } from '${config.typesFile}';

export * from '@mizdra/graphql-fabbrica/helper';
export * from '@mizdra/graphql-codegen-typescript-fabbrica/helper';
`.trim();
return `${code}\n`;
}
Expand Down