List & Non-Null Types
List Types
Section titled “List Types”GraphQL list types represent a list of values of a specific type. In @graphql-ts/schema, you can create a list type by calling the g.list function with the type of the list as the argument. They can be used in both input and output types.
const const Query: GObjectType<unknown, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
Query = const g: GWithContext<{ fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
g.object: <unknown>(youOnlyNeedToPassATypeParameterToThisFunctionYouPassTheActualRuntimeArgsOnTheResultOfThisFunction?: { youOnlyNeedToPassATypeParameterToThisFunctionYouPassTheActualRuntimeArgsOnTheResultOfThisFunction: true;}) => <Fields, Interfaces>(config: { fields: Fields | (() => Fields); interfaces?: [...Interfaces];} & Omit<GraphQLObjectTypeConfig<unknown, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>, "fields" | "interfaces">) => GObjectType<unknown, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
object()({ name: string
name: "Query", fields: { users: GField<unknown, { ids: GArg<GNonNull<GList<GNonNull<GScalarType<string, string>>>>, false>; }, GList<GObjectType<UserSource, { fetchUsers: (ids: string[]) => Promise<UserSource[]>; }>>, unknown, { fetchUsers: (ids: string[]) => Promise<UserSource[]>; }>;} | (() => { users: GField<unknown, { ids: GArg<GNonNull<GList<GNonNull<GScalarType<string, string>>>>, false>; }, GList<GObjectType<UserSource, { fetchUsers: (ids: string[]) => Promise<UserSource[]>; }>>, unknown, { fetchUsers: (ids: string[]) => Promise<UserSource[]>; }>;})
fields: { users: GField<unknown, { ids: GArg<GNonNull<GList<GNonNull<GScalarType<string, string>>>>, false>;}, GList<GObjectType<UserSource, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>>, unknown, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
users: const g: GWithContext<{ fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
g.field: <unknown, GList<GObjectType<UserSource, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>>, (_: unknown, args: { readonly ids: string[];}, context: { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}) => Promise<UserSource[]>, { ids: GArg<GNonNull<GList<GNonNull<GScalarType<string, string>>>>, false>;}>(field: FieldFuncArgs<unknown, { ids: GArg<GNonNull<GList<GNonNull<GScalarType<string, string>>>>, false>;}, GList<...>, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}> & { ...;}) => GField<...>
field({ type: GList<GObjectType<UserSource, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>>
type: const g: GWithContext<{ fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
g.list: <GObjectType<UserSource, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>>(of: GObjectType<UserSource, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>) => GList<GObjectType<UserSource, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>>
list(const User: GObjectType<UserSource, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
User), args?: { ids: GArg<GNonNull<GList<GNonNull<GScalarType<string, string>>>>, false>;}
args: { ids: GArg<GNonNull<GList<GNonNull<GScalarType<string, string>>>>, false>
ids: const g: GWithContext<{ fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
g.arg: <GNonNull<GList<GNonNull<GScalarType<string, string>>>>, undefined>(arg: { type: GNonNull<GList<GNonNull<GScalarType<string, string>>>>; description?: Maybe<string>; extensions?: (Readonly<GraphQLInputFieldExtensions> & Readonly<GraphQLArgumentExtensions>) | null | undefined; astNode?: Maybe<InputValueDefinitionNode>; deprecationReason?: Maybe<...>;} & { ...;}) => GArg<...>
arg({ type: GNonNull<GList<GNonNull<GScalarType<string, string>>>>
type: const g: GWithContext<{ fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
g.nonNull: <GList<GNonNull<GScalarType<string, string>>>>(of: GList<GNonNull<GScalarType<string, string>>>) => GNonNull<GList<GNonNull<GScalarType<string, string>>>>
nonNull(const g: GWithContext<{ fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
g.list: <GNonNull<GScalarType<string, string>>>(of: GNonNull<GScalarType<string, string>>) => GList<GNonNull<GScalarType<string, string>>>
list(const g: GWithContext<{ fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
g.nonNull: <GScalarType<string, string>>(of: GScalarType<string, string>) => GNonNull<GScalarType<string, string>>
nonNull(const g: GWithContext<{ fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>
g.type ID: GScalarType<string, string>
ID))) }), }, resolve: ((source: unknown, args: { readonly ids: string[];}, context: { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}, info: GraphQLResolveInfo) => InferValueFromOutputType<GList<GObjectType<UserSource, { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}>>>) & ((_: unknown, args: { readonly ids: string[];}, context: { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}) => Promise<UserSource[]>)
resolve(_: unknown
_, args: { readonly ids: string[];}
args, context: { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}
context) { return context: { fetchUsers: (ids: string[]) => Promise<UserSource[]>;}
context.fetchUsers: (ids: string[]) => Promise<UserSource[]>
fetchUsers(args: { readonly ids: string[];}
args.ids: string[]
ids); }, }), },});type Query { users(ids: [ID!]!): [User]}
type User { id: ID! name: String!}Non-Null Types
Section titled “Non-Null Types”In GraphQL, by default every type can also be null (and in the case of input types, undefined as well). You can make a type non-null by wrapping it in the g.nonNull function. Non-null types can be used in both input and output types.
type type UserSource = { id: string; name: string;}
UserSource = { id: string
id: string; name: string
name: string };const const User: GObjectType<UserSource, { fetchUser: (id: string) => Promise<UserSource | null>;}>
User = const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.object: <UserSource>(youOnlyNeedToPassATypeParameterToThisFunctionYouPassTheActualRuntimeArgsOnTheResultOfThisFunction?: { youOnlyNeedToPassATypeParameterToThisFunctionYouPassTheActualRuntimeArgsOnTheResultOfThisFunction: true;}) => <Fields, Interfaces>(config: { fields: Fields | (() => Fields); interfaces?: [...Interfaces];} & Omit<GraphQLObjectTypeConfig<UserSource, { fetchUser: (id: string) => Promise<UserSource | null>;}>, "fields" | "interfaces">) => GObjectType<...>
object<type UserSource = { id: string; name: string;}
UserSource>()({ name: string
name: "User", fields: { id: GField<UserSource, any, GNonNull<GScalarType<string, string>>, ImpliedResolver<any, GNonNull<GScalarType<string, string>>, { fetchUser: (id: string) => Promise<UserSource | null>; }>, { fetchUser: (id: string) => Promise<UserSource | null>; }>; name: GField<UserSource, any, GNonNull<GScalarType<string, string>>, ImpliedResolver<any, GNonNull<GScalarType<string, string>>, { fetchUser: (id: string) => Promise<UserSource | null>; }>, { fetchUser: (id: string) => Promise<UserSource | null>; }>;} | (() => { id: GField<UserSource, any, GNonNull<GScalarType<string, string>>, ImpliedResolver<any, GNonNull<GScalarType<string, string>>, { fetchUser: (id: string) => Promise<UserSource | null>; }>, { fetchUser: (id: string) => Promise<UserSource | null>; }>; name: GField<UserSource, any, GNonNull<GScalarType<string, string>>, ImpliedResolver<any, GNonNull<GScalarType<string, string>>, { fetchUser: (id: string) => Promise<UserSource | null>; }>, { fetchUser: (id: string) => Promise<UserSource | null>; }>;})
fields: { id: GField<UserSource, any, GNonNull<GScalarType<string, string>>, ImpliedResolver<any, GNonNull<GScalarType<string, string>>, { fetchUser: (id: string) => Promise<UserSource | null>;}>, { fetchUser: (id: string) => Promise<UserSource | null>;}>
id: const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.field: <UserSource, GNonNull<GScalarType<string, string>>, unknown, any>(field: FieldFuncArgs<UserSource, any, GNonNull<GScalarType<string, string>>, { fetchUser: (id: string) => Promise<UserSource | null>;}> & { resolve?: (source: UserSource, args: {}, context: { fetchUser: (id: string) => Promise<UserSource | null>; }, info: GraphQLResolveInfo) => InferValueFromOutputType<GNonNull<GScalarType<string, string>>>;}) => GField<...>
field({ type: GNonNull<GScalarType<string, string>>
type: const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.nonNull: <GScalarType<string, string>>(of: GScalarType<string, string>) => GNonNull<GScalarType<string, string>>
nonNull(const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.type ID: GScalarType<string, string>
ID) }), name: GField<UserSource, any, GNonNull<GScalarType<string, string>>, ImpliedResolver<any, GNonNull<GScalarType<string, string>>, { fetchUser: (id: string) => Promise<UserSource | null>;}>, { fetchUser: (id: string) => Promise<UserSource | null>;}>
name: const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.field: <UserSource, GNonNull<GScalarType<string, string>>, unknown, any>(field: FieldFuncArgs<UserSource, any, GNonNull<GScalarType<string, string>>, { fetchUser: (id: string) => Promise<UserSource | null>;}> & { resolve?: (source: UserSource, args: {}, context: { fetchUser: (id: string) => Promise<UserSource | null>; }, info: GraphQLResolveInfo) => InferValueFromOutputType<GNonNull<GScalarType<string, string>>>;}) => GField<...>
field({ type: GNonNull<GScalarType<string, string>>
type: const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.nonNull: <GScalarType<string, string>>(of: GScalarType<string, string>) => GNonNull<GScalarType<string, string>>
nonNull(const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.type String: GScalarType<string, string>
String) }), },});
const const Query: GObjectType<unknown, { fetchUser: (id: string) => Promise<UserSource | null>;}>
Query = const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.object: <unknown>(youOnlyNeedToPassATypeParameterToThisFunctionYouPassTheActualRuntimeArgsOnTheResultOfThisFunction?: { youOnlyNeedToPassATypeParameterToThisFunctionYouPassTheActualRuntimeArgsOnTheResultOfThisFunction: true;}) => <Fields, Interfaces>(config: { fields: Fields | (() => Fields); interfaces?: [...Interfaces];} & Omit<GraphQLObjectTypeConfig<unknown, { fetchUser: (id: string) => Promise<UserSource | null>;}>, "fields" | "interfaces">) => GObjectType<unknown, { fetchUser: (id: string) => Promise<UserSource | null>;}>
object()({ name: string
name: "Query", fields: { user: GField<unknown, { id: GArg<GNonNull<GScalarType<string, string>>, false>; }, GObjectType<UserSource, { fetchUser: (id: string) => Promise<UserSource | null>; }>, unknown, { fetchUser: (id: string) => Promise<UserSource | null>; }>;} | (() => { user: GField<unknown, { id: GArg<GNonNull<GScalarType<string, string>>, false>; }, GObjectType<UserSource, { fetchUser: (id: string) => Promise<UserSource | null>; }>, unknown, { fetchUser: (id: string) => Promise<UserSource | null>; }>;})
fields: { user: GField<unknown, { id: GArg<GNonNull<GScalarType<string, string>>, false>;}, GObjectType<UserSource, { fetchUser: (id: string) => Promise<UserSource | null>;}>, unknown, { fetchUser: (id: string) => Promise<UserSource | null>;}>
user: const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.field: <unknown, GObjectType<UserSource, { fetchUser: (id: string) => Promise<UserSource | null>;}>, (_: unknown, args: { readonly id: string;}, context: { fetchUser: (id: string) => Promise<UserSource | null>;}) => Promise<UserSource | null>, { id: GArg<GNonNull<GScalarType<string, string>>, false>;}>(field: FieldFuncArgs<unknown, { id: GArg<GNonNull<GScalarType<string, string>>, false>;}, GObjectType<UserSource, { fetchUser: (id: string) => Promise<UserSource | null>;}>, { fetchUser: (id: string) => Promise<UserSource | null>;}> & { ...;}) => GField<...>
field({ type: GObjectType<UserSource, { fetchUser: (id: string) => Promise<UserSource | null>;}>
type: const User: GObjectType<UserSource, { fetchUser: (id: string) => Promise<UserSource | null>;}>
User, args?: { id: GArg<GNonNull<GScalarType<string, string>>, false>;}
args: { id: GArg<GNonNull<GScalarType<string, string>>, false>
id: const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.arg: <GNonNull<GScalarType<string, string>>, undefined>(arg: { type: GNonNull<GScalarType<string, string>>; description?: Maybe<string>; extensions?: (Readonly<GraphQLInputFieldExtensions> & Readonly<GraphQLArgumentExtensions>) | null | undefined; astNode?: Maybe<InputValueDefinitionNode>; deprecationReason?: Maybe<string>;} & { defaultValue?: undefined;}) => GArg<GNonNull<GScalarType<...>>, false>
arg({ type: GNonNull<GScalarType<string, string>>
type: const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.nonNull: <GScalarType<string, string>>(of: GScalarType<string, string>) => GNonNull<GScalarType<string, string>>
nonNull(const g: GWithContext<{ fetchUser: (id: string) => Promise<UserSource | null>;}>
g.type ID: GScalarType<string, string>
ID) }), }, resolve: ((source: unknown, args: { readonly id: string;}, context: { fetchUser: (id: string) => Promise<UserSource | null>;}, info: GraphQLResolveInfo) => InferValueFromOutputType<GObjectType<UserSource, { fetchUser: (id: string) => Promise<UserSource | null>;}>>) & ((_: unknown, args: { readonly id: string;}, context: { fetchUser: (id: string) => Promise<UserSource | null>;}) => Promise<UserSource | null>)
resolve(_: unknown
_, args: { readonly id: string;}
args, context: { fetchUser: (id: string) => Promise<UserSource | null>;}
context) { return context: { fetchUser: (id: string) => Promise<UserSource | null>;}
context.fetchUser: (id: string) => Promise<UserSource | null>
fetchUser(args: { readonly id: string;}
args.id: string
id); }, }), },});type Query { user(id: ID!): User}
type User { id: ID! name: String!}