Skip to content

Latest commit

 

History

History
139 lines (116 loc) · 3.08 KB

README.md

File metadata and controls

139 lines (116 loc) · 3.08 KB

Playing with GraphQL

Install

go get github.com/michurin/playground-graphql-go

Setup

$GOPATH/src/github.com/michurin/playground-graphql-go/database_init.sh

By the way, you can easily view db using database_show.sh.

Run

$GOPATH/bin/playground-graphql-go

or

go run $GOPATH/src/github.com/michurin/playground-graphql-go/main.go

Enjoy

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"
                            }
                        ]
                    }
                }
            ]
        }
    }
}

GraphQL schema

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
}

Database schema

                Ride
Driver          +-------------+
+-----------+   | ride_id     |   Customer
| driver_id |--<| driver_id   |   +-------------+
| name      |   | customer_id |>--| customer_id |
+-----------+   | destination |   | name        |
                +-------------+   +-------------+

More details in database_init.sh script.

Related tools