Creating a grid resolver
The beginning
Knowing that it had to be an overview of all the articles, I started out by creating a resolver which would specifically group the specific data that I needed. In this case, articles & projects.
So I added the createResolvers function to my gatsby-node file, and created a resolver specific for my ContentfulSectionGrid content model. Here, I would add create a return name for the projects and articles.
This return value, would be the value of the gridResolver visible bellow. As an argument, this function would define the dataType I will be using to query for specific pages as my page structure has a field which defines what kind of page it is.
The resolver
The resolver itself is very straight forward.
It defines a type, which is the expected return type, in our case ContentfulPage.
Next, we resolve our function by running a query for all entries with type ContentfulPage and then filter based on the mentioned pageType above. Followed by a sort on the title field in ascending order.
The final query
Now all we have left to do is query our ContentfulSectionGrid and we will be able to see our initialProjects and initialArticles field ready to query!
Want to have a chat or create an awesome website together? Feel free to contact me!
+32 494 35 04 21

Jonathan Lauwers
Web developer

Do not miss any new posts!

By clicking "subscribe", you agree to our privacy policy