-
Notifications
You must be signed in to change notification settings - Fork 13
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
Nullable input type #55
Comments
You have to wrap input field with const GraphQLUpdateCharacterInput = t.inputObjectType({
name: "UpdateCharacterInput",
fields: () => ({
editHash: t.arg(t.NonNullInput(t.String)),
updates: t.arg(t.NonNullInput(GraphQLCharacterUpdateFields)),
}),
}); |
@emcell Did this resolve your question? |
Thank you for your answer. I understand it, but have not tried it yet. I'm working on this project in the next week again. |
@sikanhe Is the distinction between |
@n1ru4l that'd be nice. I'm currently trying to wrap gqtx's api into an api which is more pleasing and with better defaults (imo) ex: string: <T extends boolean = false>(opts?: {
nullable: T;
}): T extends true ? Scalar<string | null> : OutputType<Context, string> => {
if (opts?.nullable === true) return t.String;
return t.NonNull(t.String);
},
list: <Src>(ofType: OutputType<Context, Src>): OutputType<Context, Src[]> =>
t.NonNull(t.List(ofType)), problem is I cant use either |
I'm not great with complex types, but I explored it for a little bit with a type that would be returned by .List and .NonNull export type AllType<Ctx, Src, IsInput extends boolean> = IsInput extends true
? InputType<Src>
: OutputType<Ctx, Src>; in the end I couldn't get it to work, which is always my frustration when trying to do complicated TS stuff |
here's the fork if anyone's interested Ericnr@d37c034 |
fields: () => ({
asdf: {
type: t.NonNullInput(t.String),
description: 'asdf',
},
}), Is this a valid way of defining? I need to explicitly return an array for |
Here my worked code, I expect help: import type { Field } from 'gqtx';
import { createTypesFactory } from 'gqtx';
import type { GraphQLContext } from '~/entities/graphql';
import type { Color as ColorName } from '~/entities/ui';
type Color = { name: ColorName; value: string | null };
export type Fields = [
Field<GraphQLContext, unknown, any, {}>,
...Field<GraphQLContext, unknown, any, {}>[],
];
export const typesFactory = createTypesFactory<GraphQLContext>();
export const ColorNameEnum = typesFactory.enumType<ColorName>({
name: 'ColorName',
values: [
{ name: 'pink', value: 'pink' },
{ name: 'purple', value: 'purple' },
{ name: 'blue', value: 'blue' },
{ name: 'green', value: 'green' },
{ name: 'yellow', value: 'yellow' },
{ name: 'custom', value: 'custom' },
],
});
export const ColorType = typesFactory.objectType<Color>({
name: 'Color',
description: 'A color',
fields: () => [
typesFactory.field({
name: 'name',
type: typesFactory.NonNull(ColorNameEnum),
}),
typesFactory.field({
name: 'value',
type: typesFactory.String,
}),
],
});
// Here the example you need
export const ColorInputType = typesFactory.inputObjectType<Color>({
name: 'ColorInput',
fields: () => ({
name: {
type: typesFactory.NonNullInput(ColorNameEnum),
},
value: {
type: typesFactory.String,
},
}),
}); |
I don't understand how to create a nullable input field
Am I missing something or is the function or type
t.Input(t.String),
just missing?The text was updated successfully, but these errors were encountered: