Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Code-Hex/graphql-codegen-typescript-validation-schema
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.6.1
Choose a base ref
...
head repository: Code-Hex/graphql-codegen-typescript-validation-schema
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.6.2
Choose a head ref
  • 16 commits
  • 6 files changed
  • 4 contributors

Commits on Sep 3, 2022

  1. Copy the full SHA
    8e1f154 View commit details

Commits on Sep 5, 2022

  1. Copy the full SHA
    d019504 View commit details

Commits on Sep 6, 2022

  1. Copy the full SHA
    07b5aeb View commit details

Commits on Sep 8, 2022

  1. Copy the full SHA
    fcba66b View commit details

Commits on Sep 9, 2022

  1. Copy the full SHA
    76d04bb View commit details

Commits on Sep 10, 2022

  1. Copy the full SHA
    f622e71 View commit details

Commits on Sep 11, 2022

  1. Copy the full SHA
    b879720 View commit details

Commits on Sep 12, 2022

  1. Copy the full SHA
    7df944e View commit details
  2. Copy the full SHA
    f01a345 View commit details
  3. Copy the full SHA
    f152d63 View commit details

Commits on Sep 13, 2022

  1. Copy the full SHA
    15fb857 View commit details

Commits on Sep 14, 2022

  1. Copy the full SHA
    9ffd8bf View commit details
  2. Copy the full SHA
    e5afa14 View commit details

Commits on Sep 15, 2022

  1. Copy the full SHA
    da8a426 View commit details

Commits on Sep 18, 2022

  1. Merge pull request #185 from elijaholmos/patch-falsy-directive-values

    fix(directive): dropping falsy directive args
    Code-Hex authored Sep 18, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2820f7b View commit details
  2. v0.6.2

    Code-Hex committed Sep 18, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    Code-Hex Kei Kamikawa
    Copy the full SHA
    18bc46d View commit details
Showing with 551 additions and 370 deletions.
  1. +9 −9 package.json
  2. +1 −1 src/directive.ts
  3. +34 −0 tests/myzod.spec.ts
  4. +34 −0 tests/yup.spec.ts
  5. +34 −0 tests/zod.spec.ts
  6. +439 −360 yarn.lock
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-codegen-typescript-validation-schema",
"version": "0.6.1",
"version": "0.6.2",
"description": "GraphQL Code Generator plugin to generate form validation schema from your GraphQL schema",
"respository": {
"type": "git",
@@ -47,18 +47,18 @@
"@graphql-codegen/cli": "2.12.0",
"@graphql-codegen/typescript": "2.7.3",
"@tsconfig/recommended": "1.0.1",
"@types/jest": "29.0.0",
"@typescript-eslint/eslint-plugin": "5.36.1",
"@typescript-eslint/parser": "5.36.1",
"eslint": "8.23.0",
"jest": "29.0.1",
"@types/jest": "29.0.3",
"@typescript-eslint/eslint-plugin": "5.37.0",
"@typescript-eslint/parser": "5.37.0",
"eslint": "8.23.1",
"jest": "29.0.3",
"myzod": "1.8.8",
"npm-run-all": "4.1.5",
"prettier": "2.7.1",
"ts-jest": "28.0.8",
"typescript": "4.8.2",
"ts-jest": "29.0.1",
"typescript": "4.8.3",
"yup": "0.32.11",
"zod": "3.18.0"
"zod": "3.19.1"
},
"dependencies": {
"@graphql-codegen/plugin-helpers": "^2.3.2",
2 changes: 1 addition & 1 deletion src/directive.ts
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@ const applyArgToApiSchemaTemplate = (template: string, apiArgs: any[]): string =
const placeholder = match[0]; // `$1`
const idx = parseInt(match[1], 10) - 1; // start with `1 - 1`
const apiArg = apiArgs[idx];
if (!apiArg) {
if (apiArg === undefined) {
template = template.replace(placeholder, '');
continue;
}
34 changes: 34 additions & 0 deletions tests/myzod.spec.ts
Original file line number Diff line number Diff line change
@@ -539,4 +539,38 @@ describe('myzod', () => {
}
});
});

it('properly generates custom directive values', async () => {
const schema = buildSchema(/* GraphQL */ `
input UserCreateInput {
name: String! @constraint(startsWith: "Sir")
age: Int! @constraint(min: 0, max: 100)
}
directive @constraint(startsWith: String, min: Int, max: Int) on INPUT_FIELD_DEFINITION
`);
const result = await plugin(
schema,
[],
{
schema: 'myzod',
directives: {
constraint: {
min: 'min',
max: 'max',
startsWith: ['pattern', '/^$1/'],
},
},
},
{}
);
const wantContains = [
// User Create Input
'export function UserCreateInputSchema(): myzod.Type<UserCreateInput> {',
'name: myzod.string().pattern(/^Sir/),',
'age: myzod.number().min(0).max(100)',
];
for (const wantContain of wantContains) {
expect(result.content).toContain(wantContain);
}
});
});
34 changes: 34 additions & 0 deletions tests/yup.spec.ts
Original file line number Diff line number Diff line change
@@ -452,4 +452,38 @@ describe('yup', () => {
}
});
});

it('properly generates custom directive values', async () => {
const schema = buildSchema(/* GraphQL */ `
input UserCreateInput {
name: String! @constraint(startsWith: "Sir")
age: Int! @constraint(min: 0, max: 100)
}
directive @constraint(startsWith: String, min: Int, max: Int) on INPUT_FIELD_DEFINITION
`);
const result = await plugin(
schema,
[],
{
schema: 'yup',
directives: {
constraint: {
min: 'min',
max: 'max',
startsWith: ['matches', '/^$1/'],
},
},
},
{}
);
const wantContains = [
// User Create Input
'export function UserCreateInputSchema(): yup.SchemaOf<UserCreateInput> {',
'name: yup.string().defined().matches(/^Sir/),',
'age: yup.number().defined().min(0).max(100)',
];
for (const wantContain of wantContains) {
expect(result.content).toContain(wantContain);
}
});
});
34 changes: 34 additions & 0 deletions tests/zod.spec.ts
Original file line number Diff line number Diff line change
@@ -637,4 +637,38 @@ describe('zod', () => {
}
});
});

it('properly generates custom directive values', async () => {
const schema = buildSchema(/* GraphQL */ `
input UserCreateInput {
name: String! @constraint(startsWith: "Sir")
age: Int! @constraint(min: 0, max: 100)
}
directive @constraint(startsWith: String, min: Int, max: Int) on INPUT_FIELD_DEFINITION
`);
const result = await plugin(
schema,
[],
{
schema: 'zod',
directives: {
constraint: {
min: 'min',
max: 'max',
startsWith: ['regex', '/^$1/'],
},
},
},
{}
);
const wantContains = [
// User Create Input
'export function UserCreateInputSchema(): z.ZodObject<Properties<UserCreateInput>> {',
'name: z.string().regex(/^Sir/),',
'age: z.number().min(0).max(100)',
];
for (const wantContain of wantContains) {
expect(result.content).toContain(wantContain);
}
});
});
799 changes: 439 additions & 360 deletions yarn.lock

Large diffs are not rendered by default.