GraphQL Integration
This tutorial will demonstrate how you can consume GraphQL services in Pathom, making it part of the attribute system.
Star Wars API
To demonstrate this integration we are going to use the Star Wars GraphQL API
Federating over multiple GraphQL services
In this part we will see how we can use Pathom to connect data leveraging multiple GraphQL services.
In this example we are going to use the TMDB which is an open GraphQL service for movie data.
Although the SWAPI has some data about the movies, the TMDB has more data, like overview, images, budget...
So how can we leverage this data to augment the information we have from the SWAPI?
The first thing we need is a way to associate the SWAPI video instance, with a Movie entry on TMDB.
For this example I'll use a simple table mapping, that maps ids from SWAPI to TMDB.
note
I got the TMDB id's by manually searching for the Star Wars movies there. You could as an exercise try to make this more automatic, maybe by using the movie number or name to search from TMDB.
Now let's include the TMDB setup in our environment and integrate the mapping:
Using Pathom Viz, we can use the auto-complete to explore our new possibilities:
note
The reason we see other types like TVShow
is due to the fact the entry point for an
entity in TMDB is a generic type called Node
, which means any type that implements
this interface might be a valid option here, and in this case Pathom will offer all the possible
options.
Pathom will automatically group the attributes when sending to GraphQL using the
... on TYPE { attr attr2 }
syntax, and since in Pathom we have the full type name on
each attribute that grouping is based on looking at the last namespace part in the
attribute name.
An example query getting the title from SWAPI, while overview and budget from TMDB:
note
In this scenario we see an N+1 issue. In the future this should be optimized internally and the same process should be resolved with just one request for each GraphQL service.
You can track this at: https://github.com/wilkerlucio/pathom3-graphql/issues/11