常见用例
最后更新于
mutation MyQuery {
# mysql创建数据
mysql_createOneTodo(data: {title: "test"}) {
id
}
# mysql删除数据
mysql_deleteOneTodo(where: {id: 10}) {
id
}
# pgsql删除数据
pgsql_deleteOneTodo(where: {id: 10}) {
id
}
}mutation MyQuery @transaction {
rb_createOneT(data: { name: "22211122"}) {
id
name
}
rb_createOneRole(data: {code: "a111111", name: "1111"}) {
code
name
}
} query GetTodoList(
$take: Int = 10, $skip: Int = 0, # 分页 skip=(page-1)*take
$orderBy: [todo_TodoOrderByWithRelationInput], # 排序
$query: todo_TodoWhereInput) { # 查询条件,支持模糊搜索
# 获取列表
data: todo_findManyTodo(skip: $skip take: $take orderBy: $orderBy where: {AND: $query}) {
id
title
completed
createdAt
}
# 获取记录数
total: todo_aggregateTodo(where: {AND: $query}) @transform(get: "_count.id") {
_count {
id
}
}
}query MyQuery($title: String, $skip: Int!) {
todo_findFirstTodo(skip: $skip, take: 10, where: {title: {contains: $title}}) {
createdAt
completed
id
title
}
}grquery MyQuery {
rb_findFirstUser {
name
uid
Role {
code
name
}
}
}# 更新用户$name的同时,更新其profile的$bio字段。
mutation MyQuery( $id: Int!, $name: String, $bio: String) {
mysql_updateOneUser(
data: {name: {set: $name}, Profile: {update: {bio: {set: $bio}}}}
where: {id: $id}
) {
id
}
}model T {
id Int @id @unique
name String
des String? // 注意,这里的?
}# 方法1
query MyQuery {
rb_findManyT(where: {des: null}) {
des
id
}
}
# 方法2,不推荐使用
query MyQuery {
rb_findManyT(where: {des: {equals: null}}) {
des
id
}
}query MyQuery {
rb_findManyT(where: {des: {not:null}}) {
des
id
}
}mutation MyQuery($des: String = null) {
rb_updateOneT(data: {des: {set: $des}}, where: {id: 10}) {
id
des
}
}# 用法1:界面上语法会报错,但实际上支持
mutation MyQuery($id:Int=1) {
todo_queryRaw(query: "SELECT *,rowid \"NAVICAT_ROWID\" FROM \"main\".\"Todo\" WHERE id=$1", parameters: [$id])
}
# 用法2
mutation MyQuery($parameters: todo_Json = [1]) {
todo_queryRaw(
query: "SELECT *,rowid \"NAVICAT_ROWID\" FROM \"main\".\"Todo\" WHERE id=$1"
parameters: $parameters
)
}# 用法1:界面上语法会报错,但实际上支持
mutation MyQuery($title: String = "beijing",$id:Int=1) {
todo_executeRaw(
query: "UPDATE \"main\".\"Todo\" SET \"title\" = $1 WHERE id=$2"
parameters: [$title,$id]
)
}
# 用法2
mutation MyQuery($parameters: todo_Json = ["beijing", 1]) {
todo_executeRaw(
query: "UPDATE \"main\".\"Todo\" SET \"title\" = $1 WHERE id=$2"
parameters: $parameters
)
}query MyQuery($skip: Int = 0 ) {
rb_findManyUser(skip: $skip, take: 10) {
uid
name
}
}query MyQuery($skip: Int! ) {
rb_findManyUser(skip: $skip, take: 10) {
uid
name
}
}