Prisma ClientFeatures
GraphQL Requests (Go)
Overview
The Prisma client lets you send GraphQL queries and mutations directly to your Prisma service using the GraphQL
method:
GraphQL(query string, variables map[string]interface{}) (map[string]interface{}, error)
As the GraphQL operation is passed untyped (as a regular string), the type returned is map[string]interface{}
Examples
Fetching a single user:
query := `
query {
user(id: "cjcdi63j80adw0146z7r59bn5") {
id
name
}
}
`
result := client.GraphQL(query, nil)
// sample result:
// map[data:[map[user:[map[id:cjcdi63j80adw0146z7r59bn5 name:Sarah]]]]]
Fetching a single user using variables:
query := `
query ($id: ID!){
user(id: $id) {
id
name
}
}
`
variables := map[string]interface{}{
"id": "cjcdi63j80adw0146z7r59bn5",
}
result := client.GraphQL(query, variables)
// sample result:
// map[data:[map[user:[map[id:cjcdi63j80adw0146z7r59bn5 name:Sarah]]]]]
Creating a new user:
mutation := `
mutation ($name: String!){
createUser(name: $name) {
id
name
}
}
`
variables := map[string]interface{}{ "name": "Alice" }
result := client.GraphQL(mutation, variables)
// sample result:
// map[data:[map[createUser:[map[id:cjlhqfbfa003t0a23rhzjragl name:Alice]]]]]