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

Fix custom pair fields examples (#8663) #8664

Merged
merged 1 commit into from Jul 4, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/custom-field/3-pair-field-json/index.ts
Expand Up @@ -44,6 +44,7 @@ export function pair<ListTypeInfo extends BaseListTypeInfo>(
config: PairFieldConfig<ListTypeInfo> = {}
): FieldTypeFunc<ListTypeInfo> {
function resolveInput(value: PairInput | null | undefined) {
if (value === undefined) return undefined;
const { left = null, right = null } = value ?? {};
return JSON.stringify({ left, right });
}
Expand Down
1 change: 1 addition & 0 deletions examples/custom-field/3-pair-field-nested/index.ts
Expand Up @@ -44,6 +44,7 @@
config: PairFieldConfig<ListTypeInfo> = {}
): FieldTypeFunc<ListTypeInfo> {
function resolveInput(value: PairInput | null | undefined) {
if (value === undefined) return undefined;
const { left = null, right = null } = value ?? {};
return { left, right };
}
Expand All @@ -59,7 +60,7 @@
if (value.equals === undefined) {
return {};
}
const { left, right } = resolveInput(value.equals);

Check failure on line 63 in examples/custom-field/3-pair-field-nested/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Property 'left' does not exist on type '{ left: string | null; right: string | null; } | undefined'.

Check failure on line 63 in examples/custom-field/3-pair-field-nested/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Property 'right' does not exist on type '{ left: string | null; right: string | null; } | undefined'.
return {
left: { equals: left },
right: { equals: right },
Expand Down Expand Up @@ -95,14 +96,14 @@
create: {
arg: graphql.arg({ type: PairInput }),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
resolve(value, context) {

Check failure on line 99 in examples/custom-field/3-pair-field-nested/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Type '(value: InferValueFromArgs<{ left: Arg<ScalarType<string>, false>; right: Arg<ScalarType<string>, false>; }> | null | undefined, context: KeystoneContext) => { ...; } | undefined' is not assignable to type 'CreateFieldInputResolver<InferValueFromArgs<{ left: Arg<ScalarType<string>, false>; right: Arg<ScalarType<string>, false>; }> | null | undefined, { ...; }>'.
return resolveInput(value);
},
},
update: {
arg: graphql.arg({ type: PairInput }),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
resolve(value, context) {

Check failure on line 106 in examples/custom-field/3-pair-field-nested/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Type '(value: InferValueFromArgs<{ left: Arg<ScalarType<string>, false>; right: Arg<ScalarType<string>, false>; }> | null | undefined, context: KeystoneContext) => { ...; } | undefined' is not assignable to type 'FieldInputResolver<InferValueFromArgs<{ left: Arg<ScalarType<string>, false>; right: Arg<ScalarType<string>, false>; }> | null | undefined, { ...; }, any>'.
return resolveInput(value);
},
},
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-field/3-pair-field/index.ts
Expand Up @@ -26,8 +26,8 @@
config: PairFieldConfig<ListTypeInfo> = {}
): FieldTypeFunc<ListTypeInfo> {
function resolveInput(value: PairInput | null | undefined) {
if (!value) return { left: value, right: value };
if (value === undefined) return undefined;
const [left = '', right = ''] = value.split(' ', 2);

Check failure on line 30 in examples/custom-field/3-pair-field/index.ts

View workflow job for this annotation

GitHub Actions / Linting

'value' is possibly 'null'.
return {
left,
right,
Expand All @@ -47,7 +47,7 @@
if (value.equals === undefined) {
return {};
}
const { left, right } = resolveInput(value.equals);

Check failure on line 50 in examples/custom-field/3-pair-field/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Property 'left' does not exist on type '{ left: string; right: string; } | undefined'.

Check failure on line 50 in examples/custom-field/3-pair-field/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Property 'right' does not exist on type '{ left: string; right: string; } | undefined'.
return {
left: { equals: left },
right: { equals: right },
Expand Down Expand Up @@ -83,14 +83,14 @@
create: {
arg: graphql.arg({ type: PairInput }),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
resolve(value, context) {

Check failure on line 86 in examples/custom-field/3-pair-field/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Type '(value: string | null | undefined, context: KeystoneContext) => { left: string; right: string; } | undefined' is not assignable to type 'CreateFieldInputResolver<string | null | undefined, { kind: "multi"; fields: { left: { kind: "scalar"; mode: "optional"; scalar: "String"; }; right: { kind: "scalar"; mode: "optional"; scalar: "String"; }; }; }>'.
return resolveInput(value);
},
},
update: {
arg: graphql.arg({ type: PairInput }),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
resolve(value, context) {

Check failure on line 93 in examples/custom-field/3-pair-field/index.ts

View workflow job for this annotation

GitHub Actions / Linting

Type '(value: string | null | undefined, context: KeystoneContext) => { left: string; right: string; } | undefined' is not assignable to type 'FieldInputResolver<string | null | undefined, { left: string | null | undefined; right: string | null | undefined; }, any>'.
return resolveInput(value);
},
},
Expand Down