From b696a9579b503db86f42776381e247c4e1a7409f Mon Sep 17 00:00:00 2001 From: Mitchell Hamilton Date: Fri, 6 Aug 2021 10:36:35 +1000 Subject: [PATCH] Rename first to take (#6266) --- .changeset/curvy-dolphins-watch.md | 32 +++++++++++++++++++ examples-staging/assets-cloud/schema.graphql | 6 ++-- examples-staging/assets-local/schema.graphql | 6 ++-- examples-staging/auth/schema.graphql | 2 +- examples-staging/basic/schema.graphql | 10 +++--- examples-staging/basic/schema.ts | 2 +- examples-staging/ecommerce/schema.graphql | 24 +++++++------- .../embedded-nextjs/schema.graphql | 2 +- .../graphql-api-endpoint/schema.graphql | 12 +++---- examples-staging/playground/schema.graphql | 2 +- examples-staging/roles/schema.graphql | 10 +++--- examples-staging/sandbox/schema.graphql | 6 ++-- examples/blog/schema.graphql | 6 ++-- examples/custom-admin-ui-logo/schema.graphql | 6 ++-- .../custom-admin-ui-navigation/schema.graphql | 6 ++-- examples/custom-admin-ui-pages/schema.graphql | 6 ++-- examples/custom-field-view/schema.graphql | 6 ++-- examples/custom-field/schema.graphql | 6 ++-- examples/default-values/schema.graphql | 6 ++-- examples/document-field/schema.graphql | 6 ++-- examples/extend-graphql-schema/README.md | 2 +- .../extend-graphql-schema/custom-schema.ts | 2 +- examples/extend-graphql-schema/schema.graphql | 6 ++-- examples/json/schema.graphql | 6 ++-- examples/task-manager/schema.graphql | 6 ++-- examples/testing/schema.graphql | 6 ++-- examples/virtual-field/README.md | 2 +- examples/virtual-field/schema.graphql | 6 ++-- examples/virtual-field/schema.ts | 2 +- examples/with-auth/schema.graphql | 6 ++-- .../relationship/tests/implementation.test.ts | 4 +-- .../relationship/views/RelationshipSelect.tsx | 16 +++++----- .../admin-ui/pages/ListPage/index.tsx | 6 ++-- .../src/lib/core/queries/resolvers.ts | 18 +++++------ .../keystone/src/lib/core/types-for-lists.ts | 2 +- .../__snapshots__/artifacts.test.ts.snap | 2 +- .../fixtures/basic-project/schema.graphql | 2 +- packages/types/src/next-fields.ts | 2 +- packages/types/src/utils.ts | 2 +- tests/api-tests/queries/limits.test.ts | 8 ++--- .../relationships/filtering/nested.test.ts | 2 +- tests/test-projects/basic/schema.graphql | 6 ++-- 42 files changed, 154 insertions(+), 122 deletions(-) create mode 100644 .changeset/curvy-dolphins-watch.md diff --git a/.changeset/curvy-dolphins-watch.md b/.changeset/curvy-dolphins-watch.md new file mode 100644 index 00000000000..a180d43bb72 --- /dev/null +++ b/.changeset/curvy-dolphins-watch.md @@ -0,0 +1,32 @@ +--- +'@keystone-next/fields': major +'@keystone-next/keystone': major +'@keystone-next/types': major +--- + +Renamed `first` argument in find many queries to `take` to align with Prisma. + +```graphql +type Query { + users( + where: UserWhereInput! = {} + orderBy: [UserOrderByInput!]! = [] + # previously was first: Int + take: Int + skip: Int! = 0 + ): [User!] + # ... +} + +type User { + # ... + posts( + where: PostWhereInput! = {} + orderBy: [PostOrderByInput!]! = [] + # previously was first: Int + take: Int + skip: Int! = 0 + ): [Post!] + # ... +} +``` diff --git a/examples-staging/assets-cloud/schema.graphql b/examples-staging/assets-cloud/schema.graphql index b2b130fdb47..c409e2d98ca 100644 --- a/examples-staging/assets-cloud/schema.graphql +++ b/examples-staging/assets-cloud/schema.graphql @@ -169,7 +169,7 @@ type Author { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] postsCount(where: PostWhereInput! = {}): Int @@ -270,7 +270,7 @@ type Query { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] post(where: PostWhereUniqueInput!): Post @@ -278,7 +278,7 @@ type Query { authors( where: AuthorWhereInput! = {} orderBy: [AuthorOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Author!] author(where: AuthorWhereUniqueInput!): Author diff --git a/examples-staging/assets-local/schema.graphql b/examples-staging/assets-local/schema.graphql index a174bdfed03..697006184f5 100644 --- a/examples-staging/assets-local/schema.graphql +++ b/examples-staging/assets-local/schema.graphql @@ -147,7 +147,7 @@ type Author { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] postsCount(where: PostWhereInput! = {}): Int @@ -248,7 +248,7 @@ type Query { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] post(where: PostWhereUniqueInput!): Post @@ -256,7 +256,7 @@ type Query { authors( where: AuthorWhereInput! = {} orderBy: [AuthorOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Author!] author(where: AuthorWhereUniqueInput!): Author diff --git a/examples-staging/auth/schema.graphql b/examples-staging/auth/schema.graphql index ab34231511a..3c4ce2e4b23 100644 --- a/examples-staging/auth/schema.graphql +++ b/examples-staging/auth/schema.graphql @@ -133,7 +133,7 @@ type Query { users( where: UserWhereInput! = {} orderBy: [UserOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [User!] user(where: UserWhereUniqueInput!): User diff --git a/examples-staging/basic/schema.graphql b/examples-staging/basic/schema.graphql index b3a2ec16f98..0ef3e4bbfa8 100644 --- a/examples-staging/basic/schema.graphql +++ b/examples-staging/basic/schema.graphql @@ -10,14 +10,14 @@ type User { phoneNumbers( where: PhoneNumberWhereInput! = {} orderBy: [PhoneNumberOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [PhoneNumber!] phoneNumbersCount(where: PhoneNumberWhereInput! = {}): Int posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] postsCount(where: PostWhereInput! = {}): Int @@ -424,7 +424,7 @@ type Query { users( where: UserWhereInput! = {} orderBy: [UserOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [User!] user(where: UserWhereUniqueInput!): User @@ -432,7 +432,7 @@ type Query { phoneNumbers( where: PhoneNumberWhereInput! = {} orderBy: [PhoneNumberOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [PhoneNumber!] phoneNumber(where: PhoneNumberWhereUniqueInput!): PhoneNumber @@ -440,7 +440,7 @@ type Query { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] post(where: PostWhereUniqueInput!): Post diff --git a/examples-staging/basic/schema.ts b/examples-staging/basic/schema.ts index 0e053b105dd..ea795626295 100644 --- a/examples-staging/basic/schema.ts +++ b/examples-staging/basic/schema.ts @@ -156,7 +156,7 @@ export const lists = createSchema({ kind: 'prop', listKey: 'User', many: true, - selection: `posts(first: 10) { + selection: `posts(take: 10) { title }`, }, diff --git a/examples-staging/ecommerce/schema.graphql b/examples-staging/ecommerce/schema.graphql index d918cf69b1d..3e09137697e 100644 --- a/examples-staging/ecommerce/schema.graphql +++ b/examples-staging/ecommerce/schema.graphql @@ -6,14 +6,14 @@ type User { cart( where: CartItemWhereInput! = {} orderBy: [CartItemOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [CartItem!] cartCount(where: CartItemWhereInput! = {}): Int orders( where: OrderWhereInput! = {} orderBy: [OrderOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Order!] ordersCount(where: OrderWhereInput! = {}): Int @@ -21,7 +21,7 @@ type User { products( where: ProductWhereInput! = {} orderBy: [ProductOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Product!] productsCount(where: ProductWhereInput! = {}): Int @@ -581,7 +581,7 @@ type Order { items( where: OrderItemWhereInput! = {} orderBy: [OrderItemOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [OrderItem!] itemsCount(where: OrderItemWhereInput! = {}): Int @@ -674,7 +674,7 @@ type Role { assignedTo( where: UserWhereInput! = {} orderBy: [UserOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [User!] assignedToCount(where: UserWhereInput! = {}): Int @@ -913,7 +913,7 @@ type Query { users( where: UserWhereInput! = {} orderBy: [UserOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [User!] user(where: UserWhereUniqueInput!): User @@ -921,7 +921,7 @@ type Query { products( where: ProductWhereInput! = {} orderBy: [ProductOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Product!] product(where: ProductWhereUniqueInput!): Product @@ -929,7 +929,7 @@ type Query { productImages( where: ProductImageWhereInput! = {} orderBy: [ProductImageOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [ProductImage!] productImage(where: ProductImageWhereUniqueInput!): ProductImage @@ -937,7 +937,7 @@ type Query { cartItems( where: CartItemWhereInput! = {} orderBy: [CartItemOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [CartItem!] cartItem(where: CartItemWhereUniqueInput!): CartItem @@ -945,7 +945,7 @@ type Query { orderItems( where: OrderItemWhereInput! = {} orderBy: [OrderItemOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [OrderItem!] orderItem(where: OrderItemWhereUniqueInput!): OrderItem @@ -953,7 +953,7 @@ type Query { orders( where: OrderWhereInput! = {} orderBy: [OrderOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Order!] order(where: OrderWhereUniqueInput!): Order @@ -961,7 +961,7 @@ type Query { roles( where: RoleWhereInput! = {} orderBy: [RoleOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Role!] role(where: RoleWhereUniqueInput!): Role diff --git a/examples-staging/embedded-nextjs/schema.graphql b/examples-staging/embedded-nextjs/schema.graphql index 4aeb0f138f9..5b97caf3b1d 100644 --- a/examples-staging/embedded-nextjs/schema.graphql +++ b/examples-staging/embedded-nextjs/schema.graphql @@ -90,7 +90,7 @@ type Query { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] post(where: PostWhereUniqueInput!): Post diff --git a/examples-staging/graphql-api-endpoint/schema.graphql b/examples-staging/graphql-api-endpoint/schema.graphql index 13fde63066a..0ccdc0b6cdd 100644 --- a/examples-staging/graphql-api-endpoint/schema.graphql +++ b/examples-staging/graphql-api-endpoint/schema.graphql @@ -6,7 +6,7 @@ type User { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] postsCount(where: PostWhereInput! = {}): Int @@ -126,7 +126,7 @@ type Post { tags( where: TagWhereInput! = {} orderBy: [TagOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Tag!] tagsCount(where: TagWhereInput! = {}): Int @@ -247,7 +247,7 @@ type Tag { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] postsCount(where: PostWhereInput! = {}): Int @@ -382,7 +382,7 @@ type Query { users( where: UserWhereInput! = {} orderBy: [UserOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [User!] user(where: UserWhereUniqueInput!): User @@ -390,7 +390,7 @@ type Query { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] post(where: PostWhereUniqueInput!): Post @@ -398,7 +398,7 @@ type Query { tags( where: TagWhereInput! = {} orderBy: [TagOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Tag!] tag(where: TagWhereUniqueInput!): Tag diff --git a/examples-staging/playground/schema.graphql b/examples-staging/playground/schema.graphql index f7dd94aea96..a2cd92780f6 100644 --- a/examples-staging/playground/schema.graphql +++ b/examples-staging/playground/schema.graphql @@ -70,7 +70,7 @@ type Query { notes( where: NoteWhereInput! = {} orderBy: [NoteOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Note!] note(where: NoteWhereUniqueInput!): Note diff --git a/examples-staging/roles/schema.graphql b/examples-staging/roles/schema.graphql index be44e3407d0..c23f6a33680 100644 --- a/examples-staging/roles/schema.graphql +++ b/examples-staging/roles/schema.graphql @@ -86,7 +86,7 @@ type Person { tasks( where: TodoWhereInput! = {} orderBy: [TodoOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Todo!] tasksCount(where: TodoWhereInput! = {}): Int @@ -194,7 +194,7 @@ type Role { assignedTo( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] assignedToCount(where: PersonWhereInput! = {}): Int @@ -359,7 +359,7 @@ type Query { todos( where: TodoWhereInput! = {} orderBy: [TodoOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Todo!] todo(where: TodoWhereUniqueInput!): Todo @@ -367,7 +367,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person @@ -375,7 +375,7 @@ type Query { roles( where: RoleWhereInput! = {} orderBy: [RoleOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Role!] role(where: RoleWhereUniqueInput!): Role diff --git a/examples-staging/sandbox/schema.graphql b/examples-staging/sandbox/schema.graphql index 66117bc9d9a..dde53c7a6a9 100644 --- a/examples-staging/sandbox/schema.graphql +++ b/examples-staging/sandbox/schema.graphql @@ -111,7 +111,7 @@ type User { tasks( where: TodoWhereInput! = {} orderBy: [TodoOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Todo!] tasksCount(where: TodoWhereInput! = {}): Int @@ -238,7 +238,7 @@ type Query { todos( where: TodoWhereInput! = {} orderBy: [TodoOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Todo!] todo(where: TodoWhereUniqueInput!): Todo @@ -246,7 +246,7 @@ type Query { users( where: UserWhereInput! = {} orderBy: [UserOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [User!] user(where: UserWhereUniqueInput!): User diff --git a/examples/blog/schema.graphql b/examples/blog/schema.graphql index 1cd125ef525..056cbeeafe7 100644 --- a/examples/blog/schema.graphql +++ b/examples/blog/schema.graphql @@ -107,7 +107,7 @@ type Author { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] postsCount(where: PostWhereInput! = {}): Int @@ -208,7 +208,7 @@ type Query { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] post(where: PostWhereUniqueInput!): Post @@ -216,7 +216,7 @@ type Query { authors( where: AuthorWhereInput! = {} orderBy: [AuthorOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Author!] author(where: AuthorWhereUniqueInput!): Author diff --git a/examples/custom-admin-ui-logo/schema.graphql b/examples/custom-admin-ui-logo/schema.graphql index 49a0f225167..d27b1cc4d9b 100644 --- a/examples/custom-admin-ui-logo/schema.graphql +++ b/examples/custom-admin-ui-logo/schema.graphql @@ -103,7 +103,7 @@ type Person { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] tasksCount(where: TaskWhereInput! = {}): Int @@ -194,7 +194,7 @@ type Query { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] task(where: TaskWhereUniqueInput!): Task @@ -202,7 +202,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person diff --git a/examples/custom-admin-ui-navigation/schema.graphql b/examples/custom-admin-ui-navigation/schema.graphql index 49a0f225167..d27b1cc4d9b 100644 --- a/examples/custom-admin-ui-navigation/schema.graphql +++ b/examples/custom-admin-ui-navigation/schema.graphql @@ -103,7 +103,7 @@ type Person { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] tasksCount(where: TaskWhereInput! = {}): Int @@ -194,7 +194,7 @@ type Query { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] task(where: TaskWhereUniqueInput!): Task @@ -202,7 +202,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person diff --git a/examples/custom-admin-ui-pages/schema.graphql b/examples/custom-admin-ui-pages/schema.graphql index 49a0f225167..d27b1cc4d9b 100644 --- a/examples/custom-admin-ui-pages/schema.graphql +++ b/examples/custom-admin-ui-pages/schema.graphql @@ -103,7 +103,7 @@ type Person { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] tasksCount(where: TaskWhereInput! = {}): Int @@ -194,7 +194,7 @@ type Query { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] task(where: TaskWhereUniqueInput!): Task @@ -202,7 +202,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person diff --git a/examples/custom-field-view/schema.graphql b/examples/custom-field-view/schema.graphql index 049042c59fb..15248b53e42 100644 --- a/examples/custom-field-view/schema.graphql +++ b/examples/custom-field-view/schema.graphql @@ -106,7 +106,7 @@ type Person { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] tasksCount(where: TaskWhereInput! = {}): Int @@ -197,7 +197,7 @@ type Query { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] task(where: TaskWhereUniqueInput!): Task @@ -205,7 +205,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person diff --git a/examples/custom-field/schema.graphql b/examples/custom-field/schema.graphql index bce900c79cd..87baf953b9b 100644 --- a/examples/custom-field/schema.graphql +++ b/examples/custom-field/schema.graphql @@ -119,7 +119,7 @@ type Author { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] postsCount(where: PostWhereInput! = {}): Int @@ -220,7 +220,7 @@ type Query { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] post(where: PostWhereUniqueInput!): Post @@ -228,7 +228,7 @@ type Query { authors( where: AuthorWhereInput! = {} orderBy: [AuthorOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Author!] author(where: AuthorWhereUniqueInput!): Author diff --git a/examples/default-values/schema.graphql b/examples/default-values/schema.graphql index 49a0f225167..d27b1cc4d9b 100644 --- a/examples/default-values/schema.graphql +++ b/examples/default-values/schema.graphql @@ -103,7 +103,7 @@ type Person { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] tasksCount(where: TaskWhereInput! = {}): Int @@ -194,7 +194,7 @@ type Query { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] task(where: TaskWhereUniqueInput!): Task @@ -202,7 +202,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person diff --git a/examples/document-field/schema.graphql b/examples/document-field/schema.graphql index 0c1e7ab5741..763f53cfc9a 100644 --- a/examples/document-field/schema.graphql +++ b/examples/document-field/schema.graphql @@ -115,7 +115,7 @@ type Author { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] postsCount(where: PostWhereInput! = {}): Int @@ -223,7 +223,7 @@ type Query { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] post(where: PostWhereUniqueInput!): Post @@ -231,7 +231,7 @@ type Query { authors( where: AuthorWhereInput! = {} orderBy: [AuthorOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Author!] author(where: AuthorWhereUniqueInput!): Author diff --git a/examples/extend-graphql-schema/README.md b/examples/extend-graphql-schema/README.md index 82ffce5897d..5047e37b0d4 100644 --- a/examples/extend-graphql-schema/README.md +++ b/examples/extend-graphql-schema/README.md @@ -105,7 +105,7 @@ We add a custom type to our schema using `type Statisics` in the `typeDefs`, and }); const { posts } = await context.lists.Author.findOne({ where: { id }, - query: 'posts(first: 1, orderBy: { publishDate: desc }) { id }', + query: 'posts(take: 1, orderBy: { publishDate: desc }) { id }', }); return { draft, published, latestPostId: posts ? posts[0].id : null }; }, diff --git a/examples/extend-graphql-schema/custom-schema.ts b/examples/extend-graphql-schema/custom-schema.ts index 42a9f9482f1..c4edd1bf356 100644 --- a/examples/extend-graphql-schema/custom-schema.ts +++ b/examples/extend-graphql-schema/custom-schema.ts @@ -59,7 +59,7 @@ export const extendGraphqlSchema = graphQLSchemaExtension({ }); const { posts } = await context.lists.Author.findOne({ where: { id }, - query: 'posts(first: 1, orderBy: { publishDate: desc }) { id }', + query: 'posts(take: 1, orderBy: { publishDate: desc }) { id }', }); return { draft, published, latestPostId: posts ? posts[0].id : null }; }, diff --git a/examples/extend-graphql-schema/schema.graphql b/examples/extend-graphql-schema/schema.graphql index 65fa2e55582..b56b56c4930 100644 --- a/examples/extend-graphql-schema/schema.graphql +++ b/examples/extend-graphql-schema/schema.graphql @@ -107,7 +107,7 @@ type Author { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] postsCount(where: PostWhereInput! = {}): Int @@ -222,7 +222,7 @@ type Query { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] post(where: PostWhereUniqueInput!): Post @@ -230,7 +230,7 @@ type Query { authors( where: AuthorWhereInput! = {} orderBy: [AuthorOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Author!] author(where: AuthorWhereUniqueInput!): Author diff --git a/examples/json/schema.graphql b/examples/json/schema.graphql index 32862af1084..52b910d644b 100644 --- a/examples/json/schema.graphql +++ b/examples/json/schema.graphql @@ -80,7 +80,7 @@ type Person { packages( where: PackageWhereInput! = {} orderBy: [PackageOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Package!] packagesCount(where: PackageWhereInput! = {}): Int @@ -174,7 +174,7 @@ type Query { packages( where: PackageWhereInput! = {} orderBy: [PackageOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Package!] package(where: PackageWhereUniqueInput!): Package @@ -182,7 +182,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person diff --git a/examples/task-manager/schema.graphql b/examples/task-manager/schema.graphql index 49a0f225167..d27b1cc4d9b 100644 --- a/examples/task-manager/schema.graphql +++ b/examples/task-manager/schema.graphql @@ -103,7 +103,7 @@ type Person { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] tasksCount(where: TaskWhereInput! = {}): Int @@ -194,7 +194,7 @@ type Query { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] task(where: TaskWhereUniqueInput!): Task @@ -202,7 +202,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person diff --git a/examples/testing/schema.graphql b/examples/testing/schema.graphql index 8a707c22288..d18c2e45c7e 100644 --- a/examples/testing/schema.graphql +++ b/examples/testing/schema.graphql @@ -105,7 +105,7 @@ type Person { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] tasksCount(where: TaskWhereInput! = {}): Int @@ -251,7 +251,7 @@ type Query { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] task(where: TaskWhereUniqueInput!): Task @@ -259,7 +259,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person diff --git a/examples/virtual-field/README.md b/examples/virtual-field/README.md index 71b53de5e52..fd452f6068f 100644 --- a/examples/virtual-field/README.md +++ b/examples/virtual-field/README.md @@ -108,7 +108,7 @@ relatedPosts: virtual({ // this could have some logic to get posts that are actually related to this one somehow // this is a just a naive "get the three latest posts that aren't this one" return context.db.lists.Post.findMany({ - first: 3, + take: 3, where: { id_not: item.id, status: 'published' }, orderBy: [{ publishDate: 'desc' }], }); diff --git a/examples/virtual-field/schema.graphql b/examples/virtual-field/schema.graphql index 70b0feee8a5..869993a7171 100644 --- a/examples/virtual-field/schema.graphql +++ b/examples/virtual-field/schema.graphql @@ -117,7 +117,7 @@ type Author { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] postsCount(where: PostWhereInput! = {}): Int @@ -219,7 +219,7 @@ type Query { posts( where: PostWhereInput! = {} orderBy: [PostOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Post!] post(where: PostWhereUniqueInput!): Post @@ -227,7 +227,7 @@ type Query { authors( where: AuthorWhereInput! = {} orderBy: [AuthorOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Author!] author(where: AuthorWhereUniqueInput!): Author diff --git a/examples/virtual-field/schema.ts b/examples/virtual-field/schema.ts index c96eb7ead8b..3dbba311fae 100644 --- a/examples/virtual-field/schema.ts +++ b/examples/virtual-field/schema.ts @@ -102,7 +102,7 @@ export const lists = createSchema({ where: { id: item.id.toString() }, query: `posts( orderBy: { publishDate: desc } - first: 1 + take: 1 ) { id }`, }); if (posts.length > 0) { diff --git a/examples/with-auth/schema.graphql b/examples/with-auth/schema.graphql index 8a707c22288..d18c2e45c7e 100644 --- a/examples/with-auth/schema.graphql +++ b/examples/with-auth/schema.graphql @@ -105,7 +105,7 @@ type Person { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] tasksCount(where: TaskWhereInput! = {}): Int @@ -251,7 +251,7 @@ type Query { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] task(where: TaskWhereUniqueInput!): Task @@ -259,7 +259,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person diff --git a/packages/fields/src/types/relationship/tests/implementation.test.ts b/packages/fields/src/types/relationship/tests/implementation.test.ts index ea93d65957f..54de9fd8d69 100644 --- a/packages/fields/src/types/relationship/tests/implementation.test.ts +++ b/packages/fields/src/types/relationship/tests/implementation.test.ts @@ -123,7 +123,7 @@ describe('Type Generation', () => { expect(printType(schema.getType('Test')!)).toMatchInlineSnapshot(` "type Test { id: ID! - foo(where: ZipWhereInput! = {}, orderBy: [ZipOrderByInput!]! = [], first: Int, skip: Int! = 0): [Zip!] + foo(where: ZipWhereInput! = {}, orderBy: [ZipOrderByInput!]! = [], take: Int, skip: Int! = 0): [Zip!] fooCount(where: ZipWhereInput! = {}): Int }" `); @@ -135,7 +135,7 @@ describe('Type Generation', () => { expect(printType(schema.getType('Test')!)).toMatchInlineSnapshot(` "type Test { id: ID! - foo(where: ZipWhereInput! = {}, orderBy: [ZipOrderByInput!]! = [], first: Int, skip: Int! = 0): [Zip!] + foo(where: ZipWhereInput! = {}, orderBy: [ZipOrderByInput!]! = [], take: Int, skip: Int! = 0): [Zip!] }" `); }); diff --git a/packages/fields/src/types/relationship/views/RelationshipSelect.tsx b/packages/fields/src/types/relationship/views/RelationshipSelect.tsx index 44446e7bdd1..6f0a6980c26 100644 --- a/packages/fields/src/types/relationship/views/RelationshipSelect.tsx +++ b/packages/fields/src/types/relationship/views/RelationshipSelect.tsx @@ -105,10 +105,10 @@ export const RelationshipSelect = ({ const QUERY: TypedDocumentNode< { items: { [idField]: string; [labelField]: string | null }[]; count: number }, - { where: Record; first: number; skip: number } + { where: Record; take: number; skip: number } > = gql` - query RelationshipSelect($where: ${list.gqlNames.whereInputName}!, $first: Int!, $skip: Int!) { - items: ${list.gqlNames.listQueryName}(where: $where, first: $first, skip: $skip) { + query RelationshipSelect($where: ${list.gqlNames.whereInputName}!, $take: Int!, $skip: Int!) { + items: ${list.gqlNames.listQueryName}(where: $where, take: $take, skip: $skip) { ${idField}: id ${labelField}: ${list.labelField} ${extraSelection} @@ -121,7 +121,7 @@ export const RelationshipSelect = ({ const { data, error, loading, fetchMore } = useQuery(QUERY, { fetchPolicy: 'network-only', - variables: { where, first: initialItemsToLoad, skip: 0 }, + variables: { where, take: initialItemsToLoad, skip: 0 }, }); const count = data?.count || 0; @@ -146,10 +146,10 @@ export const RelationshipSelect = ({ if (!loading && isIntersecting && options.length < count) { const QUERY: TypedDocumentNode< { items: { [idField]: string; [labelField]: string | null }[] }, - { where: Record; first: number; skip: number } + { where: Record; take: number; skip: number } > = gql` - query RelationshipSelectMore($where: ${list.gqlNames.whereInputName}!, $first: Int!, $skip: Int!) { - items: ${list.gqlNames.listQueryName}(where: $where, first: $first, skip: $skip) { + query RelationshipSelectMore($where: ${list.gqlNames.whereInputName}!, $take: Int!, $skip: Int!) { + items: ${list.gqlNames.listQueryName}(where: $where, take: $take, skip: $skip) { ${labelField}: ${list.labelField} ${idField}: id ${extraSelection} @@ -160,7 +160,7 @@ export const RelationshipSelect = ({ query: QUERY, variables: { where, - first: subsequentItemsToLoad, + take: subsequentItemsToLoad, skip: data!.items.length, }, updateQuery: (prev, { fetchMoreResult }) => { diff --git a/packages/keystone/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/index.tsx b/packages/keystone/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/index.tsx index e3b977c8737..95283432d99 100644 --- a/packages/keystone/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/index.tsx +++ b/packages/keystone/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/index.tsx @@ -176,12 +176,12 @@ const ListPage = ({ listKey }: ListPageProps) => { }) .join('\n'); return gql` - query ($where: ${list.gqlNames.whereInputName}, $first: Int!, $skip: Int!, $orderBy: [${ + query ($where: ${list.gqlNames.whereInputName}, $take: Int!, $skip: Int!, $orderBy: [${ list.gqlNames.listOrderName }!]) { items: ${ list.gqlNames.listQueryName - }(where: $where,first: $first, skip: $skip, orderBy: $orderBy) { + }(where: $where,take: $take, skip: $skip, orderBy: $orderBy) { ${ // TODO: maybe namespace all the fields instead of doing this selectedFields.has('id') ? '' : 'id' @@ -197,7 +197,7 @@ const ListPage = ({ listKey }: ListPageProps) => { errorPolicy: 'all', variables: { where: filters.where, - first: pageSize, + take: pageSize, skip: (currentPage - 1) * pageSize, orderBy: sort ? [{ [sort.field]: sort.direction.toLowerCase() }] : undefined, }, diff --git a/packages/keystone/src/lib/core/queries/resolvers.ts b/packages/keystone/src/lib/core/queries/resolvers.ts index 35e421b4e26..dcfcae416cb 100644 --- a/packages/keystone/src/lib/core/queries/resolvers.ts +++ b/packages/keystone/src/lib/core/queries/resolvers.ts @@ -86,7 +86,7 @@ export async function findOne( } export async function findMany( - { where, first, skip, orderBy: rawOrderBy }: FindManyArgsValue, + { where, take, skip, orderBy: rawOrderBy }: FindManyArgsValue, list: InitialisedList, context: KeystoneContext, info: GraphQLResolveInfo, @@ -94,7 +94,7 @@ export async function findMany( ): Promise { const orderBy = await resolveOrderBy(rawOrderBy, list, context); - applyEarlyMaxResults(first, list); + applyEarlyMaxResults(take, list); let resolvedWhere = await resolveWhereInput(where || {}, list); resolvedWhere = await accessControlledFilter(list, context, resolvedWhere); @@ -103,7 +103,7 @@ export async function findMany( model.findMany({ where: extraFilter === undefined ? resolvedWhere : { AND: [resolvedWhere, extraFilter] }, orderBy, - take: first ?? undefined, + take: take ?? undefined, skip, }) ); @@ -186,16 +186,16 @@ export async function count( return count; } -function applyEarlyMaxResults(_first: number | null | undefined, list: InitialisedList) { - const first = _first ?? Infinity; +function applyEarlyMaxResults(_take: number | null | undefined, list: InitialisedList) { + const take = _take ?? Infinity; // We want to help devs by failing fast and noisily if limits are violated. // Unfortunately, we can't always be sure of intent. - // E.g., if the query has a "first: 10", is it bad if more results could come back? + // E.g., if the query has a "take: 10", is it bad if more results could come back? // Maybe yes, or maybe the dev is just paginating posts. // But we can be sure there's a problem in two cases: - // * The query explicitly has a "first" that exceeds the limit - // * The query has no "first", and has more results than the limit - if (first < Infinity && first > list.maxResults) { + // * The query explicitly has a "take" that exceeds the limit + // * The query has no "take", and has more results than the limit + if (take < Infinity && take > list.maxResults) { throw limitsExceededError({ list: list.listKey, type: 'maxResults', limit: list.maxResults }); } } diff --git a/packages/keystone/src/lib/core/types-for-lists.ts b/packages/keystone/src/lib/core/types-for-lists.ts index 18ab3c6b78d..518d102c14b 100644 --- a/packages/keystone/src/lib/core/types-for-lists.ts +++ b/packages/keystone/src/lib/core/types-for-lists.ts @@ -165,7 +165,7 @@ export function initialiseLists( defaultValue: [], }), // TODO: non-nullable when max results is specified in the list with the default of max results - first: schema.arg({ type: schema.Int }), + take: schema.arg({ type: schema.Int }), skip: schema.arg({ type: schema.nonNull(schema.Int), defaultValue: 0 }), }; diff --git a/packages/keystone/src/scripts/tests/__snapshots__/artifacts.test.ts.snap b/packages/keystone/src/scripts/tests/__snapshots__/artifacts.test.ts.snap index d82fd130fba..32b5afc6057 100644 --- a/packages/keystone/src/scripts/tests/__snapshots__/artifacts.test.ts.snap +++ b/packages/keystone/src/scripts/tests/__snapshots__/artifacts.test.ts.snap @@ -94,7 +94,7 @@ export type TodoListTypeInfo = { listQuery: { readonly where?: TodoWhereInput; readonly orderBy?: ReadonlyArray | TodoOrderByInput; - readonly first?: Scalars['Int'] | null; + readonly take?: Scalars['Int'] | null; readonly skip?: Scalars['Int']; }; }; diff --git a/packages/keystone/src/scripts/tests/fixtures/basic-project/schema.graphql b/packages/keystone/src/scripts/tests/fixtures/basic-project/schema.graphql index 2f3cfe2ec31..595ad86b9f2 100644 --- a/packages/keystone/src/scripts/tests/fixtures/basic-project/schema.graphql +++ b/packages/keystone/src/scripts/tests/fixtures/basic-project/schema.graphql @@ -70,7 +70,7 @@ type Query { todos( where: TodoWhereInput! = {} orderBy: [TodoOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Todo!] todo(where: TodoWhereUniqueInput!): Todo diff --git a/packages/types/src/next-fields.ts b/packages/types/src/next-fields.ts index 349b815ed91..c897df91bb9 100644 --- a/packages/types/src/next-fields.ts +++ b/packages/types/src/next-fields.ts @@ -398,7 +398,7 @@ export type FindManyArgs = { schema.NonNullType>>, Record[] >; - first: schema.Arg; + take: schema.Arg; skip: schema.Arg, number>; }; diff --git a/packages/types/src/utils.ts b/packages/types/src/utils.ts index b6aee7d0508..7100c4c35f8 100644 --- a/packages/types/src/utils.ts +++ b/packages/types/src/utils.ts @@ -11,7 +11,7 @@ export type BaseGeneratedListTypes = { args: { listQuery: { readonly where?: GraphQLInput | null; - readonly first?: number | null; + readonly take?: number | null; readonly skip?: number; readonly orderBy?: | Record diff --git a/tests/api-tests/queries/limits.test.ts b/tests/api-tests/queries/limits.test.ts index c4a9e343d46..3f3b78edb4b 100644 --- a/tests/api-tests/queries/limits.test.ts +++ b/tests/api-tests/queries/limits.test.ts @@ -90,11 +90,11 @@ describe('maxResults Limit', () => { expect(data).toHaveProperty('usersCount'); expect(data.usersCount).toBe(users.length); - // This query is only okay because of the "first" parameter + // This query is only okay because of the "take" parameter data = await context.graphql.run({ query: ` query { - users(first: 1) { + users(take: 1) { name } } @@ -118,13 +118,13 @@ describe('maxResults Limit', () => { expectLimitsExceededError(errors, [{ path: ['users'] }]); - // The query results don't break the limits, but the "first" parameter does + // The query results don't break the limits, but the "take" parameter does ({ errors } = await context.graphql.raw({ query: ` query { users( where: { name: "Nope" }, - first: 100000 + take: 100000 ) { name } diff --git a/tests/api-tests/relationships/filtering/nested.test.ts b/tests/api-tests/relationships/filtering/nested.test.ts index 9679c5122b8..74a3a09eeba 100644 --- a/tests/api-tests/relationships/filtering/nested.test.ts +++ b/tests/api-tests/relationships/filtering/nested.test.ts @@ -63,7 +63,7 @@ describe('relationship filtering', () => { }); const users = await context.lists.User.findMany({ - query: 'id posts(first: 1, orderBy: { content: asc }) { id }', + query: 'id posts(take: 1, orderBy: { content: asc }) { id }', }); expect(users).toContainEqual({ id: user.id, posts: [ids[0]] }); expect(users).toContainEqual({ id: user2.id, posts: [ids[0]] }); diff --git a/tests/test-projects/basic/schema.graphql b/tests/test-projects/basic/schema.graphql index 49a0f225167..d27b1cc4d9b 100644 --- a/tests/test-projects/basic/schema.graphql +++ b/tests/test-projects/basic/schema.graphql @@ -103,7 +103,7 @@ type Person { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] tasksCount(where: TaskWhereInput! = {}): Int @@ -194,7 +194,7 @@ type Query { tasks( where: TaskWhereInput! = {} orderBy: [TaskOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Task!] task(where: TaskWhereUniqueInput!): Task @@ -202,7 +202,7 @@ type Query { people( where: PersonWhereInput! = {} orderBy: [PersonOrderByInput!]! = [] - first: Int + take: Int skip: Int! = 0 ): [Person!] person(where: PersonWhereUniqueInput!): Person