GraphQL API
Keystone generates a CRUD (create, read, update, delete) GraphQL API based on the schema definition provided in the system config.
Consider the following system definition:
import { config, createSchema, list } from '@keystone-next/keystone/schema';import { text } from '@keystone-next/fields';export default config({lists: createSchema({User: list({ fields: { name: text() } }),}),/* ... */});
This system will generate the following GraphQL API.
Note: The names and types of the generated queries and mutations are based on the names of the lists and fields in the system config.
type Query {""" Search for the User item with the matching ID. """User(where: UserWhereUniqueInput!): User""" Search for all User items which match the where clause. """allUsers(where: UserWhereInput, search: String, orderBy: [UserOrderByInput!]! = [], first: Int, skip: Int! = 0): [User]""" Perform a meta-query on all User items which match the where clause. """_allUsersMeta(where: UserWhereInput, search: String, orderBy: [UserOrderByInput!]! = [], first: Int, skip: Int! = 0): _QueryMeta}type Mutation {""" Create a single User item. """createUser(data: UserCreateInput): User""" Create multiple User items. """createUsers(data: [UsersCreateInput]): [User]""" Update a single User item by ID. """updateUser(id: ID!, data: UserUpdateInput): User""" Update multiple User items by ID. """updateUsers(data: [UsersUpdateInput]): [User]""" Delete a single User item by ID. """deleteUser(id: ID!): User""" Delete multiple User items by ID. """deleteUsers(ids: [ID!]): [User]}""" A keystone list """type User {id: ID!name: String}input UserWhereInput {AND: [UserWhereInput]OR: [UserWhereInput]id: IDid_not: IDid_lt: IDid_lte: IDid_gt: IDid_gte: IDid_in: [ID]id_not_in: [ID]name: Stringname_not: Stringname_contains: Stringname_not_contains: Stringname_starts_with: Stringname_not_starts_with: Stringname_ends_with: Stringname_not_ends_with: Stringname_i: Stringname_not_i: Stringname_contains_i: Stringname_not_contains_i: Stringname_starts_with_i: Stringname_not_starts_with_i: Stringname_ends_with_i: Stringname_not_ends_with_i: Stringname_in: [String]name_not_in: [String]}input UserWhereUniqueInput {id: ID!}input UserOrderByInput {id: OrderDirectionname: OrderDirection}enum OrderDirection {ascdesc}input UserUpdateInput {name: String}input UsersUpdateInput {id: ID!data: UserUpdateInput}input UserCreateInput {name: String}input UsersCreateInput {data: UserCreateInput}type _QueryMeta {count: Int}
Queries
User
type Query {""" Search for the User item with the matching ID. """User(where: UserWhereUniqueInput!): User}input UserWhereUniqueInput {id: ID!}type User {id: ID!name: String}
allUsers
type Query {""" Search for all User items which match the where clause. """allUsers(where: UserWhereInput, search: String, orderBy: [UserOrderByInput!]! = [], first: Int, skip: Int! = 0): [User]}input UserWhereInput {AND: [UserWhereInput]OR: [UserWhereInput]id: IDid_not: IDid_lt: IDid_lte: IDid_gt: IDid_gte: IDid_in: [ID]id_not_in: [ID]name: Stringname_not: Stringname_contains: Stringname_not_contains: Stringname_starts_with: Stringname_not_starts_with: Stringname_ends_with: Stringname_not_ends_with: Stringname_i: Stringname_not_i: Stringname_contains_i: Stringname_not_contains_i: Stringname_starts_with_i: Stringname_not_starts_with_i: Stringname_ends_with_i: Stringname_not_ends_with_i: Stringname_in: [String]name_not_in: [String]}input UserOrderByInput {id: OrderDirectionname: OrderDirection}enum OrderDirection {ascdesc}type User {id: ID!name: String}
usersCount
type Query {usersCount(where: UserWhereInput! = {}): Int!}input UserWhereInput {AND: [UserWhereInput]OR: [UserWhereInput]id: IDid_not: IDid_lt: IDid_lte: IDid_gt: IDid_gte: IDid_in: [ID]id_not_in: [ID]name: Stringname_not: Stringname_contains: Stringname_not_contains: Stringname_starts_with: Stringname_not_starts_with: Stringname_ends_with: Stringname_not_ends_with: Stringname_i: Stringname_not_i: Stringname_contains_i: Stringname_not_contains_i: Stringname_starts_with_i: Stringname_not_starts_with_i: Stringname_ends_with_i: Stringname_not_ends_with_i: Stringname_in: [String]name_not_in: [String]}input UserOrderByInput {id: OrderDirectionname: OrderDirection}enum OrderDirection {ascdesc}type _QueryMeta {count: Int}
Mutations
createUser
type Mutation {""" Create a single User item. """createUser(data: UserCreateInput): User}input UserCreateInput {name: String}type User {id: ID!name: String}
createUsers
type Mutation {""" Create multiple User items. """createUsers(data: [UsersCreateInput]): [User]}input UsersCreateInput {data: UserCreateInput}input UserCreateInput {name: String}type User {id: ID!name: String}
updateUser
type Mutation {""" Update a single User item by ID. """updateUser(id: ID!, data: UserUpdateInput): User}input UserUpdateInput {name: String}type User {id: ID!name: String}
updateUsers
type Mutation {""" Update multiple User items by ID. """updateUsers(data: [UsersUpdateInput]): [User]}input UsersUpdateInput {id: ID!data: UserUpdateInput}input UserUpdateInput {name: String}type User {id: ID!name: String}
deleteUser
type Mutation {""" Delete a single User item by ID. """deleteUser(id: ID!): User}type User {id: ID!name: String}
deleteUsers
type Mutation {""" Delete multiple User items by ID. """deleteUsers(ids: [ID!]): [User]}type User {id: ID!name: String}