Skip to content

Commit

Permalink
add test case for #85
Browse files Browse the repository at this point in the history
  • Loading branch information
mizdra committed Sep 15, 2024
1 parent 339d748 commit 6008b4d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 1 deletion.
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

0 comments on commit 6008b4d

Please sign in to comment.