Playing with GraphQL
go get github.com/michurin/playground-graphql-go
$GOPATH/src/github.com/michurin/playground-graphql-go/database_init.sh
By the way, you can easily view db using database_show.sh
.
$GOPATH/bin/playground-graphql-go
or
go run $GOPATH/src/github.com/michurin/playground-graphql-go/main.go
Q='query {x_customer(id: 200) {name rides {destination driver {rides {destination customer{name}}}}}}'
curl -XPOST http://localhost:8080/gql -H 'Content-Type: application/graphql' -d "$Q"
{
"data": {
"x_customer": {
"name": "Customer_200",
"rides": [
{
"destination": "Address_for_ride_2",
"driver": {
"rides": [
{
"customer": {
"name": "Customer_100"
},
"destination": "Adderss_for_ride_1"
},
{
"customer": {
"name": "Customer_200"
},
"destination": "Address_for_ride_2"
}
]
}
},
{
"destination": "Address_for_ride_3",
"driver": {
"rides": [
{
"customer": {
"name": "Customer_200"
},
"destination": "Address_for_ride_3"
}
]
}
}
]
}
}
}
type Query {
x_customer(id: Int!): Customer
x_ride(id: Int!): Ride
x_rides(ids: [Int!]!): [Ride]
}
type Customer {
deep_rides: [Ride!]!
id: Int!
name: String!
rides: [Ride!]!
}
type Driver {
id: Int!
name: String!
rides: [Ride!]!
}
type Ride {
customer: Customer!
destination: String!
driver: Driver!
id: Int!
}
input RideInput {
customer_id: Int!
driver_id: Int!
destination: String!
}
type Mutation {
add_ride(params: RideInput!): Ride
}
Ride
Driver +-------------+
+-----------+ | ride_id | Customer
| driver_id |--<| driver_id | +-------------+
| name | | customer_id |>--| customer_id |
+-----------+ | destination | | name |
+-------------+ +-------------+
More details in database_init.sh
script.