Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a dual package #64

Merged
merged 6 commits into from
Mar 10, 2024
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
9 changes: 1 addition & 8 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
const { join } = require('node:path');

/** @type {import('eslint').Linter.BaseConfig} */
module.exports = {
Expand All @@ -15,13 +14,7 @@ module.exports = {
},
rules: {
'no-use-before-define': 'off',
'import/no-extraneous-dependencies': [
'error',
{
includeTypes: true,
packageDir: [__dirname, join(__dirname, 'e2e')],
},
],
'import/no-extraneous-dependencies': 'off', // false positive
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ dist

# User
/dist
/e2e/__generated__
__generated__
10 changes: 10 additions & 0 deletions e2e/cjs/1-basic-schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type Book {
id: ID!
title: String!
author: Author!
}
type Author {
id: ID!
name: String!
books: [Book!]!
}
33 changes: 33 additions & 0 deletions e2e/cjs/codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { CodegenConfig } from '@graphql-codegen/cli';

const defaultTypeScriptPluginConfig = {
nonOptionalTypename: true,
enumsAsTypes: true,
avoidOptionals: true,
skipTypename: true,
};
const defaultFabbricaPluginConfig = {
typesFile: './types.js',
skipTypename: true,
};

const config: CodegenConfig = {
generates: {
'__generated__/1-basic/types.ts': {
schema: './1-basic-schema.graphql',
plugins: ['typescript'],
config: {
...defaultTypeScriptPluginConfig,
},
},
'./__generated__/1-basic/fabbrica.ts': {
schema: './1-basic-schema.graphql',
plugins: ['@mizdra/graphql-codegen-typescript-fabbrica'],
config: {
...defaultFabbricaPluginConfig,
},
},
},
};

module.exports = config;
43 changes: 43 additions & 0 deletions e2e/cjs/index.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { it } from 'node:test';
import { defineAuthorFactory, defineBookFactory, dynamic } from './__generated__/1-basic/fabbrica.js';
import assert from 'node:assert/strict';

it('integration test', async () => {
const BookFactory = defineBookFactory({
defaultFields: {
id: dynamic(({ seq }) => `Book-${seq}`),
title: dynamic(({ seq }) => `ゆゆ式 ${seq}巻`),
author: undefined,
},
});
const AuthorFactory = defineAuthorFactory({
defaultFields: {
id: dynamic(({ seq }) => `Author-${seq}`),
name: dynamic(({ seq }) => `${seq}上小又`),
books: undefined,
},
});
let book = await BookFactory.build({
author: await AuthorFactory.build(),
});

assert.deepEqual(book, {
id: 'Book-0',
title: 'ゆゆ式 0巻',
author: {
id: 'Author-0',
name: '0上小又',
books: undefined,
},
});
const _book: {
id: string;
title: string;
author: {
id: string;
name: string;
books: undefined;
};
} = book;
book = _book;
});
17 changes: 17 additions & 0 deletions e2e/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "e2e-cjs",
"type": "commonjs",
"scripts": {
"start": "run-s gen lint test",
"gen": "graphql-codegen",
"lint": "run-s -c lint:*",
"lint:tsc": "tsc",
"test": "node --import tsx --test index.e2e.ts"
},
"engines": {
"node": ">=18.0.0"
},
"dependencies": {
"@mizdra/graphql-codegen-typescript-fabbrica": ".."
}
}
File renamed without changes.
4 changes: 4 additions & 0 deletions e2e/cjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"exclude": ["node_modules"]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion e2e/codegen.ts → e2e/esm/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ const config: CodegenConfig = {
},
};

module.exports = config;
export default config;
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions e2e/package.json → e2e/esm/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "e2e",
"name": "e2e-esm",
"type": "module",
"scripts": {
"start": "run-s gen lint test",
"gen": "graphql-codegen",
"gen": "graphql-codegen-esm",
"lint": "run-s -c lint:*",
"lint:tsc": "tsc",
"test": "vitest"
"test": "vitest --run"
},
"engines": {
"node": ">=18.0.0"
Expand Down
6 changes: 6 additions & 0 deletions e2e/esm/test/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { randomInt } from 'node:crypto';

export function oneOf<const T>(items: T[]): T {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return items[randomInt(items.length)]!;
}
4 changes: 4 additions & 0 deletions e2e/esm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"exclude": ["node_modules"]
}
File renamed without changes.
4 changes: 0 additions & 4 deletions e2e/tsconfig.json

This file was deleted.

Loading
Loading