Mastering GraphQL in Trackunit Iris

Mastering GraphQL in Trackunit Iris

Table of Contents

  1. Introduction
  2. Prerequisites
  3. Exploring GraphQL Explorer
  4. Fetching Interesting Data
  5. Creating Custom Queries
  6. Exporting the GraphQL API
  7. Integrating with Track Units
  8. Using Custom React Hooks
  9. Generating Required Files
  10. Displaying Fetched Data
  11. Conclusion

Integrating Track Units GraphQL API with Iris: A Step-by-Step Guide

Introduction

As a developer, You may be tasked with integrating Track Units' GraphQL API with Iris. This can be a daunting task, especially if you are new to GraphQL. But fear not, in this guide, we will take you through the process of integrating Track Units' GraphQL API with Iris. By the end of this guide, you will have a solid understanding of how to export the GraphQL API, Create custom queries, and display the fetched data inside of your Iris app.

Prerequisites

Before we get started, there are some prerequisites that you need to have. You should have a basic app and extension already set up and have npm installed. You also need to have GraphQL tools installed. If you haven't already, go through the getting started guide and come back to this guide later.

Exploring GraphQL Explorer

The first thing we want to do is navigate to the GraphQL Explorer. This can be done by opening your browser and heading over to the URL that you see on your screen. Here We Are met with our panel to the left where we can browse the available schema. On this right panel, we can cyber query, but we prefer picking the fields that we want from the left panel and have to explore our Auto generate the query for us.

Fetching Interesting Data

Say we want to fetch asset information, such as the brand, model, and production year of the assets. We can call our query something Meaningful and remember the name as it will be very important later. Now press on the run button to execute the query.

Creating Custom Queries

The easiest way to get a token is from the traffic manager by looking for it in the calls the app makes to the API. When you have it, paste it in and Rerun the query, and it should work. Now that we are happy with our query, we should prepare the app to use Track Units' custom React hooks for GraphQL.

Exporting the GraphQL API

Open your dev environment and navigate to the project.json file and add the GraphQL hooks to the targets mode. Assuming you've already installed the required library, run the command in your terminal to do so right now. Finally, you can create a GraphQL file in your Source folder, paste in the queries with built-in explorer.

Integrating with Track Units

Now we'll use the target we defined earlier to generate all the files we need by running the following command. It generated this file for us, which includes a bunch of useful interfaces and hooks. Most notably, it auto-generated a function called use get first asset query that uses the Apollo library to run our query against the GraphQL API. Notice that the naming scheme it uses has the form use your query query. Remember this so you know what function to call in your app, which is also what we'll try out right now.

Using Custom React Hooks

Navigate to your app.tsx, import the function, and use it in your code.

Generating Required Files

Now finally, let's head over to our app and see the results of our query. Here we've got the brand name, model, and production. Perfect.

Displaying Fetched Data

If you followed along to this point, you should have a good understanding of how to explode the GraphQL API, generate a query fitting your business case, auto-generate code that interfaces your app with the API, and finally, how to put it all together and integrate the available data into your app.

Conclusion

We've tried to make it as simple as possible to work with the data, and if you want to dig even deeper on how it all works, we can recommend checking out the relay specification, which our graphical solution is following somewhat closely. It is also advised to play around with the data in the Explorer to understand the domain model and available data structures better.

Highlights

  • Integrate Track Units' GraphQL API with Iris
  • Explore the GraphQL Explorer to fetch interesting data
  • Create custom queries and export the GraphQL API
  • Use Track Units' custom React hooks for GraphQL
  • Auto-generate code that interfaces your app with the API
  • Display fetched data inside of your Iris app

FAQ

Q: What are the prerequisites to integrate Track Units GraphQL API with Iris? A: You should have a basic app and extension already set up and have npm installed. You also need to have GraphQL tools installed.

Q: How can I fetch asset information using GraphQL? A: You can call your query something meaningful and remember the name as it will be very important later. Now press on the run button to execute the query.

Q: How can I generate the required files for integrating with Track Units' GraphQL API? A: You can use the target we defined earlier to generate all the files we need by running the following command.

Q: What is the naming scheme used for generating the functions? A: The naming scheme it uses has the form use your query query. Remember this so you know what function to call in your app.

Q: How can I display the fetched data inside of my Iris app ? A: You can use the auto-generated function called use get first asset query that uses the Apollo library to run our query against the GraphQL API to display the fetched data.

Find AI tools in Toolify

Join TOOLIFY to find the ai tools

Get started

Sign Up
App rating
4.9
AI Tools
20k+
Trusted Users
5000+
No complicated
No difficulty
Free forever
Browse More Content