Skip to content

Commit

Permalink
Merge pull request #88 from mizdra/fix-composite-bug
Browse files Browse the repository at this point in the history
Fix compile errors caused by `--composite` of TypeScript
  • Loading branch information
mizdra authored Sep 15, 2024
2 parents 339d748 + 5c68c53 commit 83066a8
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 3 deletions.
3 changes: 3 additions & 0 deletions e2e/composite/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Options required to reproduce https://github.com/mizdra/graphql-codegen-typescript-fabbrica/issues/85
install-links=true
package-lock=false
24 changes: 24 additions & 0 deletions e2e/composite/codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
schema: './schema.graphql',
generates: {
// The files other than those matching includes cannot be read when using `compisite`.
// Therefore, fabbrica artifacts are also output under `src/`.
'src/__generated__/types.ts': {
plugins: ['typescript'],
config: {
enumsAsTypes: true, // required
avoidOptionals: true, // required
},
},
'src/__generated__/fabbrica.ts': {
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
config: {
typesFile: './types.js', // required
},
},
},
};

export default config;
17 changes: 17 additions & 0 deletions e2e/composite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "e2e-composite",
"type": "module",
"scripts": {
"start": "run-s clean _install gen build",
"clean": "node -e \"require('fs').rmSync('node_modules', { recursive: true, force: true })\"",
"_install": "npm install",
"gen": "graphql-codegen-esm",
"build": "tsc"
},
"engines": {
"node": ">=18.0.0"
},
"dependencies": {
"@mizdra/graphql-codegen-typescript-fabbrica": "../.."
}
}
4 changes: 4 additions & 0 deletions e2e/composite/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type Book {
id: ID!
title: String!
}
9 changes: 9 additions & 0 deletions e2e/composite/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineBookFactory, dynamic } from './__generated__/fabbrica.js';

export const BookFactory = defineBookFactory({
defaultFields: {
__typename: 'Book',
id: dynamic(({ seq }) => `Book-${seq}`),
title: 'Yuyushiki',
},
});
12 changes: 12 additions & 0 deletions e2e/composite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.json",
"include": ["./src"],
"exclude": ["node_modules"],
"compilerOptions": {
"composite": true,
"declaration": true,
"noEmit": false,
"outDir": "dist",
"rootDir": "src"
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
"lint:prettier": "prettier --check .",
"test": "vitest",
"pree2e": "npm run build",
"e2e": "npm -w e2e/esm -w e2e/cjs run start"
"e2e": "run-s -c e2e:*",
"e2e:esm": "npm -w e2e/esm run start",
"e2e:cjs": "npm -w e2e/cjs run start",
"e2e:composite": "npm --prefix e2e/composite run start"
},
"prettier": "@mizdra/prettier-config-mizdra",
"devDependencies": {
Expand Down
10 changes: 8 additions & 2 deletions src/helper/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export { dynamic } from './field-resolver.js';
export { dynamic, Dynamic } from './field-resolver.js';
export { resetAllSequence, resetSequence } from './sequence.js';
export { DefineTypeFactoryInterface, DefineTypeFactoryInterfaceRequired, defineTypeFactory } from './factory.js';
export {
DefineTypeFactoryInterface,
DefineTypeFactoryInterfaceRequired,
defineTypeFactory,
Traits,
TypeFactoryInterface,
} from './factory.js';

0 comments on commit 83066a8

Please sign in to comment.