Tired of TodoMVC? So do I.
This is yet another example of GraphQL server. It provides you GraphQL backend, so you can play with queries in the GraphiQL. While implementing this example I was trying to keep backend simple but provide clear and meaningful schema.
- To keep it simple this example uses in-memory storage. Initial data located in data.json file.
- GraphiQL tool enabled and it is a way to play with GraphQL.
- There is no frontend part. (But it would be good to implement example clients using Relay.
react-native
example in progress.)
Let's imagine we are developing tourist guide program.
- There is information about
Countries
our user may plan to visit. - Each
Country
containsCities
. - And each
City
has a bunch ofHotels
.
Wait, what the backend without nice images? We will add Image
to Country
and list of Images
for each City
.
Now we can review the Relations Diagram.
Our schema allow us to fetch any shape of data. For this we need to add entry points for lists and individual entity:
countries
- List ofCountries
. For index page of our application with countries.country(countryID)
- ParticularCountry
by ID. For individualCountry
page.city(cityID)
- ParticularCity
by ID. For individualCity
page.hotel(hotelID)
- ParticularHotel
by ID. For individualHotel
page.
Have you noticed some kind of duplication in country
, city
, hotel
?
For avoiding this Relay provides us ability to use one entry point for all individual entities called node
:
node(ID)
- WhereID
is GraphQL UUID. For more information check this
But in this example I am going to leave all the entry points available.
-
Install dependencies:
npm install
-
Run the server
npm start
-
Go to http://localhost:3000/graphql to open GraphiQL.