diff --git a/.changeset/funny-mice-drum.md b/.changeset/funny-mice-drum.md new file mode 100644 index 00000000000..5f8ad96430a --- /dev/null +++ b/.changeset/funny-mice-drum.md @@ -0,0 +1,6 @@ +--- +'@keystone-next/keystone': patch +'@keystone-next/types': patch +--- + +Fixed generated list types to allow passing a value directly when a GraphQL list of the value is expected diff --git a/packages-next/keystone/src/lib/context/server-side-graphql-client.ts b/packages-next/keystone/src/lib/context/server-side-graphql-client.ts index 82b9ddd0883..a82ea05da6e 100644 --- a/packages-next/keystone/src/lib/context/server-side-graphql-client.ts +++ b/packages-next/keystone/src/lib/context/server-side-graphql-client.ts @@ -120,8 +120,10 @@ const getItems = async ({ }: { listKey: string; where?: Record | null; - sortBy?: readonly string[] | null; - orderBy?: readonly Record[]; + sortBy?: string | readonly string[] | null; + orderBy?: + | Record + | readonly Record[]; first?: number | null; skip?: number | null; pageSize?: number; diff --git a/packages-next/keystone/src/lib/schema-type-printer.tsx b/packages-next/keystone/src/lib/schema-type-printer.tsx index 30fa286c8f0..2f04b993321 100644 --- a/packages-next/keystone/src/lib/schema-type-printer.tsx +++ b/packages-next/keystone/src/lib/schema-type-printer.tsx @@ -29,7 +29,7 @@ function printInputTypesFromSchema( let ast = parse(schema); let printTypeNodeWithoutNullable = (node: ListTypeNode | NamedTypeNode): string => { if (node.kind === 'ListType') { - return `ReadonlyArray<${printTypeNode(node.type)}>`; + return `ReadonlyArray<${printTypeNode(node.type)}> | ${printTypeNode(node.type)}`; } let name = node.name.value; if (schemaObj.getType(name) instanceof GraphQLScalarType) { diff --git a/packages-next/keystone/src/scripts/tests/__snapshots__/artifacts.test.ts.snap b/packages-next/keystone/src/scripts/tests/__snapshots__/artifacts.test.ts.snap index 629295120f3..657078459f7 100644 --- a/packages-next/keystone/src/scripts/tests/__snapshots__/artifacts.test.ts.snap +++ b/packages-next/keystone/src/scripts/tests/__snapshots__/artifacts.test.ts.snap @@ -12,22 +12,38 @@ type Scalars = { }; export type TodoWhereInput = { - readonly AND?: ReadonlyArray | null; - readonly OR?: ReadonlyArray | null; + readonly AND?: ReadonlyArray | TodoWhereInput | null; + readonly OR?: ReadonlyArray | TodoWhereInput | null; readonly id?: Scalars['ID'] | null; readonly id_not?: Scalars['ID'] | null; readonly id_lt?: Scalars['ID'] | null; readonly id_lte?: Scalars['ID'] | null; readonly id_gt?: Scalars['ID'] | null; readonly id_gte?: Scalars['ID'] | null; - readonly id_in?: ReadonlyArray | null; - readonly id_not_in?: ReadonlyArray | null; + readonly id_in?: + | ReadonlyArray + | Scalars['ID'] + | null + | null; + readonly id_not_in?: + | ReadonlyArray + | Scalars['ID'] + | null + | null; readonly title?: Scalars['String'] | null; readonly title_not?: Scalars['String'] | null; readonly title_contains?: Scalars['String'] | null; readonly title_not_contains?: Scalars['String'] | null; - readonly title_in?: ReadonlyArray | null; - readonly title_not_in?: ReadonlyArray | null; + readonly title_in?: + | ReadonlyArray + | Scalars['String'] + | null + | null; + readonly title_not_in?: + | ReadonlyArray + | Scalars['String'] + | null + | null; }; export type TodoWhereUniqueInput = { @@ -84,8 +100,8 @@ export type TodoListTypeInfo = { args: { listQuery: { readonly where?: TodoWhereInput; - readonly sortBy?: ReadonlyArray | null; - readonly orderBy?: ReadonlyArray; + readonly sortBy?: ReadonlyArray | SortTodosBy | null; + readonly orderBy?: ReadonlyArray | TodoOrderByInput; readonly first?: Scalars['Int'] | null; readonly skip?: Scalars['Int']; }; diff --git a/packages-next/types/src/utils.ts b/packages-next/types/src/utils.ts index 1a9507f3657..a5d7e4b27f4 100644 --- a/packages-next/types/src/utils.ts +++ b/packages-next/types/src/utils.ts @@ -14,8 +14,10 @@ export type BaseGeneratedListTypes = { readonly search?: string | null; readonly first?: number | null; readonly skip?: number | null; - readonly orderBy?: readonly Record[]; - readonly sortBy?: ReadonlyArray | null; + readonly orderBy?: + | Record + | readonly Record[]; + readonly sortBy?: string | ReadonlyArray | null; }; }; };