Skip to content

Commit

Permalink
Fix generated list types to allow passing a value directly when a Gra…
Browse files Browse the repository at this point in the history
…phQL list of the value is expected (#5910)
  • Loading branch information
emmatown committed Jun 15, 2021
1 parent 2eabe4d commit 50ad1ce
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .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
Expand Up @@ -120,8 +120,10 @@ const getItems = async ({
}: {
listKey: string;
where?: Record<string, any> | null;
sortBy?: readonly string[] | null;
orderBy?: readonly Record<string, 'asc' | 'desc' | null>[];
sortBy?: string | readonly string[] | null;
orderBy?:
| Record<string, 'asc' | 'desc' | null>
| readonly Record<string, 'asc' | 'desc' | null>[];
first?: number | null;
skip?: number | null;
pageSize?: number;
Expand Down
2 changes: 1 addition & 1 deletion packages-next/keystone/src/lib/schema-type-printer.tsx
Expand Up @@ -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) {
Expand Down
Expand Up @@ -12,22 +12,38 @@ type Scalars = {
};
export type TodoWhereInput = {
readonly AND?: ReadonlyArray<TodoWhereInput> | null;
readonly OR?: ReadonlyArray<TodoWhereInput> | null;
readonly AND?: ReadonlyArray<TodoWhereInput> | TodoWhereInput | null;
readonly OR?: ReadonlyArray<TodoWhereInput> | 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<Scalars['ID'] | null> | null;
readonly id_not_in?: ReadonlyArray<Scalars['ID'] | null> | null;
readonly id_in?:
| ReadonlyArray<Scalars['ID'] | null>
| Scalars['ID']
| null
| null;
readonly id_not_in?:
| ReadonlyArray<Scalars['ID'] | null>
| 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<Scalars['String'] | null> | null;
readonly title_not_in?: ReadonlyArray<Scalars['String'] | null> | null;
readonly title_in?:
| ReadonlyArray<Scalars['String'] | null>
| Scalars['String']
| null
| null;
readonly title_not_in?:
| ReadonlyArray<Scalars['String'] | null>
| Scalars['String']
| null
| null;
};
export type TodoWhereUniqueInput = {
Expand Down Expand Up @@ -84,8 +100,8 @@ export type TodoListTypeInfo = {
args: {
listQuery: {
readonly where?: TodoWhereInput;
readonly sortBy?: ReadonlyArray<SortTodosBy> | null;
readonly orderBy?: ReadonlyArray<TodoOrderByInput>;
readonly sortBy?: ReadonlyArray<SortTodosBy> | SortTodosBy | null;
readonly orderBy?: ReadonlyArray<TodoOrderByInput> | TodoOrderByInput;
readonly first?: Scalars['Int'] | null;
readonly skip?: Scalars['Int'];
};
Expand Down
6 changes: 4 additions & 2 deletions packages-next/types/src/utils.ts
Expand Up @@ -14,8 +14,10 @@ export type BaseGeneratedListTypes = {
readonly search?: string | null;
readonly first?: number | null;
readonly skip?: number | null;
readonly orderBy?: readonly Record<string, 'asc' | 'desc' | null>[];
readonly sortBy?: ReadonlyArray<string> | null;
readonly orderBy?:
| Record<string, 'asc' | 'desc' | null>
| readonly Record<string, 'asc' | 'desc' | null>[];
readonly sortBy?: string | ReadonlyArray<string> | null;
};
};
};
Expand Down

1 comment on commit 50ad1ce

@vercel
Copy link

@vercel vercel bot commented on 50ad1ce Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.