Go-graphql
在Go中使用GraphQL的简单例子
go run server.go
打开浏览器并转到localhost:8080
在graphiql操场上粘贴以下查询,并使用它们来创建/检索记录:
mutation createCustomer {
createCustomer(input: { name: "João", email: "joao@gmail.com" }) {
id
name
email
}
}
mutation createItem {
createItem(input: { name: "GeForce RTX 3060 TI", price: 599.99 }) {
id
name
price
}
}
mutation createOrder {
createOrder(input: {
customerId: "CUSTOMER_UUID_FROM_CREATE_CUSTOMER_REQUEST",
items: [ {itemId: "ITEM_UUID_FROM_CREATE_ITEM_REQUEST", quantity: 2} ]
}) {
id
total
customer {
id
name
email
}
items {
id
quantity
item {
id
name
price
}
}
}
}
query findCustomers {
customers {
id
name
email
}
}
query findItems {
items {
id
name
price
}
}
query findOrders {
orders {
id
total
items {
id
quantity
item {
id
name
price
}
}
customer {
id
name
}
}
}
query findOrderItems {
orderItems {
id
order {
id
total
}
item {
id
name
price
}
quantity
}
}