Note: You will also need basic familiarity with Android development and GraphQL. Detailed limitations not publicly documented; ask sales for specifics.
How does Hygraph manage and blend data from multiple sources in an event app?
Hygraph enables you to connect remote sources (REST or GraphQL APIs) and integrate their data into your content models. In the event app tutorial, event and location data are fetched from PredictHQ via remote sources, while category data is managed directly in Hygraph. This blended data is then served through Hygraph's GraphQL API to your application. Note: Integrating complex or highly-customized external APIs may require additional schema adjustments and custom code.
What data models are required for an event app built with Hygraph?
The event app requires three main data models in Hygraph:
listEvent: Holds event data, including a REST field for PredictHQ events and a description field.
EventLocation: Stores location data, with a REST field for PredictHQ locations and a description field.
EventCategory: Contains event categories as a single line text field (with multiple values allowed).
Note: The exact field configuration may need to be adjusted for different external APIs or app requirements.
How do you set up remote sources and schemas in Hygraph for external APIs?
To set up remote sources in Hygraph:
Navigate to Schema | REMOTE SOURCES and add a new remote source (e.g., PredictHQ).
Set the type to REST and enter the base URL (e.g., https://api.predicthq.com/v1).
Add required headers, such as Authorization (Bearer token) and Content-Type.
Convert the external API's JSON response to Schema Definition Language (SDL), adjust types as needed, and add the schema in the Custom type definition section.
Note: Schema conversion may require manual tweaks for compatibility with Hygraph and your app's language (e.g., changing DateTime to String for Android).
What categories can be used in the event app, and how are they managed?
Categories such as sports, academics, concerts, conferences, expos, and festivals are managed in the EventCategory model in Hygraph. You can add multiple categories as entries and allow multiple values per entry. These categories are then used to filter events in the app. Note: The list of categories is customizable based on your application's needs.
How do you authenticate API requests to Hygraph in an event app?
API requests to Hygraph are authenticated using permanent auth tokens. You can create a token in Project settings | ACCESS | API Access | Permanent Auth Tokens. Assign the required permissions (e.g., Read for Content API) to the token. This token is then included in the Authorization header of your API requests. Note: Keep your auth tokens secure and restrict permissions as needed for your use case.
Where can I find the complete code for the Hygraph event app tutorial?
The complete code for the event app tutorial is available on GitHub. This repository includes all the necessary files and configurations to build and run the app as described in the tutorial. Note: The code may require updates for compatibility with newer versions of dependencies or Hygraph features.
Features & Capabilities
What APIs does Hygraph provide for app development?
Hygraph offers several APIs for different use cases:
GraphQL Content API: For querying and manipulating content programmatically, optimized for high performance and low latency.
Management API: For handling structural elements of a project, accessible via the Management SDK.
Asset Upload API: For uploading assets from your file system or remote URLs.
MCP Server API: For secure communication between AI assistants and Hygraph via the Model Context Protocol.
For more details, see the API Reference documentation. Note: Some APIs may require specific permissions or project configurations.
What integrations are available with Hygraph?
Hygraph supports a wide range of integrations, including:
For a full list, visit the Hygraph Marketplace. Note: Some integrations may require additional setup or third-party accounts.
How does Hygraph perform in terms of API speed and reliability?
Hygraph is optimized for high performance, with improvements to its high-performance endpoints resulting in low latency and high read-throughput. The read-only cache endpoint delivers 3-5x latency improvement for content delivery. Hygraph actively measures GraphQL API performance and provides practical optimization advice. See the performance blog post and GraphQL Report 2024 for details. Note: Actual performance may vary based on project complexity and external integrations.
Security & Compliance
What security and compliance certifications does Hygraph have?
Hygraph holds the following certifications:
SOC 2 Type 2 (achieved August 3, 2022)
ISO 27001 (hosting infrastructure)
GDPR compliance
These certifications demonstrate Hygraph's commitment to secure and compliant content management. For more, see the Secure Features page. Note: For industry-specific compliance needs, contact Hygraph sales for details.
What security features are available in Hygraph?
Hygraph offers:
Granular permissions for access control
SSO integrations (OIDC/LDAP/SAML)
Audit logs for user activity tracking
Encryption in transit and at rest
Regular backups and one-click recovery
Custom API security policies and IP firewalls
All endpoints use SSL certificates. For more, see the Secure Features page. Note: Some features may require enterprise plans or specific configurations.
Implementation & Onboarding
How long does it take to implement Hygraph for a new project?
Implementation time varies by project complexity. For example:
Si Vale: Initial phase completed on aggressive deadlines.
Top Villas: Launched a new project within 2 months.
Voi: Migrated from WordPress to Hygraph in 1-2 months.
Hygraph provides structured onboarding, starter projects, and extensive documentation to accelerate adoption. Note: Highly customized or large-scale migrations may require additional time and planning.
What technical documentation is available for Hygraph?
Integration guides for platforms like Mux, Akeneo, Auth0
AI features documentation
See Hygraph Documentation for all resources. Note: Some documentation is specific to Hygraph Classic or advanced features.
Use Cases & Customer Success
What types of applications and industries can benefit from Hygraph?
Hygraph is used across industries including SaaS, marketplace, education technology, media, healthcare, consumer goods, automotive, fintech, travel, eCommerce, gaming, events, government, and more. It is suitable for building event apps, e-commerce sites, inventory/catalog management, and structured content platforms. For examples, see Hygraph case studies. Note: Highly specialized industry requirements may need custom development or integrations.
Can you share examples of customer success with Hygraph?
Notable customer success stories include:
Samsung: Improved customer engagement by 15% with a scalable, API-first application.
Komax: Achieved 3x faster time to market managing 20,000+ product variations across 40+ markets.
This tutorial demonstrates building an event app using Hygraph headless CMS to manage dynamic data from multiple sources and serve it through GraphQL APIs.
Last updated by Dedan
on Jan 21, 2026
Originally written by Dedan
Building applications with dynamic data retrieved from different sources is a challenging task. Figuring out how to manage, mix, and blend the content as well as choosing which data to display to end users contributes to the complexity. Luckily, headless content management systems (CMS) like Hygraph that separate content from their presentation are able to manage different content while deploying to multiple applications.
For example, a Hygraph e-commerce site enables you to collect and manage customer data, display relevant product ads, and optimize your users' shopping experience on a single API. Or if you need a high-performant inventory and catalog management system, Hygraph offers a controlled environment to house your content while unifying it from different sources. Do you also need structured content that is easy to scale and adaptable to serve different purposes? Then Hygraph really is your one-stop place to provide quality digital experiences for your users.
In this article, you will learn how to build an event app with Hygraph. You'll start by creating models for your content, fetching data from an external API, and combining it with more content on Hygraph to serve your app. You'll then build an application that will consume this data through a GraphQL API.
In this tutorial, you are going to build a mobile app with which a user can search events by category and location.
The app will retrieve content from a Hygraph backend that will contain three models: event data, location data, and category data. Both the events and location data will be fetched from a remote source, PredictHQ, and the category content will be added in Hygraph.
Finally, you will use Hygraph's GraphQL APIs to load the content into your app.
Here's a simple architectural diagram for the project:
You can find the complete app for this tutorial in this GitHub repository.
After you create an account on Hygraph, the next step is to create a project to store and fetch your data. Hygraph offers some starter and schema templates such as a commerce shop and a travel site to speed up your development. However, for this tutorial, you will create a new blank project.
On the Hygraph dashboard, select Add Project, fill in your desired details, and select your region, as shown in the screenshot below:
A remote source is a connector to other REST or GraphQL APIs whose
data you would need to be integrated into your model.
The first thing you need to do is figure out which data the PredictHQ events API contains. PredictHQ offers two endpoints that you can hit to analyze their responses. To access these APIs, you need an access token, which you can acquire by following these instructions.
Using Postman, make a GET request to the events endpoint. You should receive a response similar to the screenshot below:
You need to transform the above response into a schema that GraphQL can understand, namely Schema Definition Language (SDL). You can use this tool to convert the JSON above to an SDL.
However, the generated SDL needs a few tweaks before it can be used in Hygraph. Update the generated SDL as follows:
Replace all instances of JSON with Json.
Rename the ROOT type to EventsResult and the Result to Event. This is to make your schema more readable.
Replace all instances of DateTime with String.
Note: Hygraph does support DateTime. However, to use this schema on an Android app, you need to write custom code to consume it. Changing it to String makes things easier.
The final SDL schema should be as follows:
typeEntity{
entity_id:String
formatted_address:String
name:String
type:String
}
typeGeometry{
coordinates:[Float]
type:String
}
typeGeo{
geometry:Geometry
placekey:String
}
typeParentEvent{
parent_event_id:String
}
typeEvent{
aviation_rank:Int
brand_safe:Boolean
category:String
country:String
description:String
duration:Int
end:String
entities:[Entity]
first_seen:String
geo:Geo
id:String
labels:[String]
local_rank:Int
location:[Float]
parent_event:ParentEvent
phq_attendance:Int
place_hierarchies:[[String]]
private:Boolean
rank:Int
relevance:Int
scope:String
start:String
state:String
timezone:String
title:String
updated:String
}
typeEventsResult{
count:Int
next:String
overflow:Boolean
previous:Json
results:[Event]
}
You can now add the schema to your Hygraph project. Navigate to Schema | REMOTE SOURCES and press the Add button.
Fill in the details of the remote source and select the type as REST. Next, add https://api.predicthq.com/v1 as the base URL. In the Headers section, add the following:
"Authorization":"Bearer<The access token you created in predictHQ>
"Content-Type":"application/json;charset=utf-8"
Here's a screenshot of how that will look like:
Lastly, in the Custom type definition section, add the schemas generated above.
Since your app will filter events by location, PredictHQ provides another endpoint to get location identifiers. Repeat the Postman procedure above to get the data format and convert the JSON into an SDL. Tweak the generated SDL as follows:
Replace all instances of JSON with Json.
Rename the ROOT type to LocationsResult and the Result to Location. This is to make your schema more readable.
The final SDL schema should be as shown below:
typeLocation{
country:String
country_alpha2:String
country_alpha3:String
county:Json
id:String
location:[Float]
name:String
region:String
type:String
}
typeLocationsResult{
count:Int
next:Json
previous:Json
results:[Location]
}
Since both endpoints share the same base URL, you will not create a new remote source. Add the above schema to the previous remote source and save.
Models are the building blocks for your data. They define the data contained in your content and its types.
Events data model
To add an events model, navigate to Schema | MODELS and press Add. Fill in the name of the model—in this case, listEvent—and save.
On the resulting screen, you need to add fields that will hold your data. The events model will hold a REST field type and a String. Scroll down on the pane on your right until you find the REST field type and select it.
In the window that pops up, add the details about the endpoint. Please note that the Method will be GET and the return type will be EventsResult. This endpoint also takes in arguments that should be added in the Input arguments section. Finally, set the path of the remote source, making sure to include all arguments. In the end, your form should resemble the screenshots below:
Lastly, add a Single line text field and name it desc.
Your model dashboard should resemble the following screenshot:
Location data model
Repeating the same steps as above, create a new model named EventLocation with a REST field named Places and a Single line text field named desc.
The REST field should have a GET method with the return type being LocationsResult and a single argument. The bottom part of the form should resemble the screenshot below:
Category model
Your events app will filter events based on category. You must define these categories as a model on Hygraph.
Create a new model named EventCategory with a Single line text field named categories. Since there are many categories to use, make sure to tick the Allow multiple values checkbox and save.
You can now access your Hygraph project contents from a single API. However, to make sure only authorized apps make requests, you need to set up authorization.
Navigate to Project settings | ACCESS | API Access | Permanent Auth Tokens to create an authentication token.
After you create a token, the permissions screen will pop up. In the Content API section, click Add Permission. Select the Read permission, as shown below, and save.
This will allow only read requests on all your models at all stages.
You are going to build an Android app that will query content from Hygraph and display it to users.
Follow these steps to set up an Android project on Android Studio:
Open Android Studio and create an Empty Compose Activity project.
Provide the name of the app—in this case Events—press Finish, and wait for the project to load.
Add project dependencies
To query a GraphQL API, you can use the Apollo GraphQL library, which assists you in writing GraphQL queries and generating data models for their responses.
To handle making API requests asynchronously, you also need to add the Kotlin coroutine dependencies. Open the app/build.gradle file and add the following dependencies:
In the same file, update the plugins section to include the Apollo library. The section should be similar to this:
plugins{
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id("com.apollographql.apollo3").version("3.7.5")
}
Finally, you need to configure where the Apollo library will store its generated files. To do this, add the following code at the bottom of the app/build.gradle file:
apollo {
service("service"){
packageName.set("com.example.events.models")
}
}
Add internet permissions
Since the application will be making API requests over the Internet, you need to specify this permission so that the Android framework can request the user for it.
To do this, navigate to the AndroidManifest.xml file and add the internet permission shown below:
The Apollo library needs to know the type of data you intend to query and the available fields to generate the necessary code. Create a new schema.graphqls file in app/src/main/graphql/, which will hold the GraphQL schema of the Hygraph content.
You need to add the SDL schema generated in the Add Remote Source section to the new file. Your file should now contain the following:
typeLocation{
country:String
country_alpha2:String
country_alpha3:String
county:String
id:String
location:[Float]
name:String
region:String
type:String
}
typeLocationsResult{
count:Int
next:Int
previous:Int
results:[Location]
}
typeEntity{
entity_id:String
formatted_address:String
name:String
type:String
}
typeGeometry{
coordinates:[Float]
type:String
}
typeGeo{
geometry:Geometry
placekey:String
}
typeParentEvent{
parent_event_id:String
}
typeEvent{
aviation_rank:Int
brand_safe:Boolean
category:String
country:String
description:String
duration:Int
end:String
entities:[Entity]
first_seen:String
geo:Geo
id:String
labels:[String]
local_rank:Int
location:[Float]
parent_event:ParentEvent
phq_attendance:Int
place_hierarchies:[[String]]
private:Boolean
rank:Int
relevance:Int
scope:String
start:String
state:String
timezone:String
title:String
updated:String
}
typeEventsResult{
count:Int
next:String
overflow:Boolean
previous:Int
results:[Event]
}
With the above schema, the Apollo library will understand the kind of content that your GraphQL API returns when queried.
Write GraphQL queries
With the schema ready, you can now write some queries to fetch data from the Hygraph endpoint.
The Hygraph API Playground
Hygraph provides a handy API playground where you can write and test queries while viewing their response. You can tweak various fields to return only the content you need.
For instance, to query events, you need to pass in the category as well as the location_id to get a result. You can write a query similar to the screenshot below in the API playground, which will return events with only the defined subset of fields.
Write app GraphQL queries
After testing your queries in the playground, you can add them to the app.
Create a new file named AppQuery.graphql on the same level as your schema file. Save the file in app/src/main/graphql/. Add the following queries for query event categories, locations, and filter events:
After you add the above queries, Android Studio will display some compilation errors. This is because the previous schema file does not contain all the fields that the queries have. To solve this, you need to update the schema file with the following content:
With the above schema and query, the Apollo library can generate code that you can use to make requests. To generate the code, build your project again.
Note: Every time you change your schema and queries, rebuild the code so that the Apollo library can regenerate the code.
Build the events screen
The content and queries are all ready. How about enabling users to search and view events around them? This section discusses just that.
Set up the Apollo Client
You need to initialize and configure an ApolloClient that you will use in the app to make GraphQL requests. You will need the API endpoint from Hygraph, which you can get by navigating to Project Settings | ACCESS | API Access in the Content API section. You also need the access token created in the previous section.
In your com/project_org/project_name folder, create a file named ApolloClient.kt and add the following code to it:
The code above contains an interceptor and okHttpClient, which are used to manipulate the requests as well as log the response. The ApolloClient has an addHTTPHeader function that is used to add the authorization token.
Build the ViewModel
Your Android app will use a ViewModel to make an API request and update the screen once a response is received. In your com/project_org/project_name/viewmodels folder, create a file named MainViewModel.kt and add the following code to it:
The code above renders a user interface where users can select the category and location of events they would like to see. The app makes an API request to Hygraph with the chosen filters and returns a filtered result that is presented to the user.
With this in place, you can now build your app to test and validate the content.
You can find the complete app for this tutorial in this GitHub repository. Here's a video of how the app works:
In this article, you have learned how to model data to SDL schemas that can be used in GraphQL queries. You have also learned how to write GraphQL queries and fetch only the required data for your application needs. Lastly, you have used Hygraph to host your content and built an Android application to display it to users using GraphQL APIs.
Hygraph's GraphQL approach to collating and managing content enables you to build diverse, high-performant, and scalable applications with minimal friction between data sources. Its ability to handle remote sources lets you blend data from different providers into a single source of truth, leading to more stable and resilient applications. Create a free forever account now and take this project for a spin.
Blog Author
Dedan Ndungu
Technical Writer
Dedan Ndungu is a software engineer with experience in mobile app development using Java, Kotlin, and Flutter. He's also experienced integrating Firebase services to deliver quality and scalable mobile applications.
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.
This tutorial demonstrates building an event app using Hygraph headless CMS to manage dynamic data from multiple sources and serve it through GraphQL APIs.
Last updated by Dedan
on Jan 21, 2026
Originally written by Dedan
Building applications with dynamic data retrieved from different sources is a challenging task. Figuring out how to manage, mix, and blend the content as well as choosing which data to display to end users contributes to the complexity. Luckily, headless content management systems (CMS) like Hygraph that separate content from their presentation are able to manage different content while deploying to multiple applications.
For example, a Hygraph e-commerce site enables you to collect and manage customer data, display relevant product ads, and optimize your users' shopping experience on a single API. Or if you need a high-performant inventory and catalog management system, Hygraph offers a controlled environment to house your content while unifying it from different sources. Do you also need structured content that is easy to scale and adaptable to serve different purposes? Then Hygraph really is your one-stop place to provide quality digital experiences for your users.
In this article, you will learn how to build an event app with Hygraph. You'll start by creating models for your content, fetching data from an external API, and combining it with more content on Hygraph to serve your app. You'll then build an application that will consume this data through a GraphQL API.
In this tutorial, you are going to build a mobile app with which a user can search events by category and location.
The app will retrieve content from a Hygraph backend that will contain three models: event data, location data, and category data. Both the events and location data will be fetched from a remote source, PredictHQ, and the category content will be added in Hygraph.
Finally, you will use Hygraph's GraphQL APIs to load the content into your app.
Here's a simple architectural diagram for the project:
You can find the complete app for this tutorial in this GitHub repository.
After you create an account on Hygraph, the next step is to create a project to store and fetch your data. Hygraph offers some starter and schema templates such as a commerce shop and a travel site to speed up your development. However, for this tutorial, you will create a new blank project.
On the Hygraph dashboard, select Add Project, fill in your desired details, and select your region, as shown in the screenshot below:
A remote source is a connector to other REST or GraphQL APIs whose
data you would need to be integrated into your model.
The first thing you need to do is figure out which data the PredictHQ events API contains. PredictHQ offers two endpoints that you can hit to analyze their responses. To access these APIs, you need an access token, which you can acquire by following these instructions.
Using Postman, make a GET request to the events endpoint. You should receive a response similar to the screenshot below:
You need to transform the above response into a schema that GraphQL can understand, namely Schema Definition Language (SDL). You can use this tool to convert the JSON above to an SDL.
However, the generated SDL needs a few tweaks before it can be used in Hygraph. Update the generated SDL as follows:
Replace all instances of JSON with Json.
Rename the ROOT type to EventsResult and the Result to Event. This is to make your schema more readable.
Replace all instances of DateTime with String.
Note: Hygraph does support DateTime. However, to use this schema on an Android app, you need to write custom code to consume it. Changing it to String makes things easier.
The final SDL schema should be as follows:
typeEntity{
entity_id:String
formatted_address:String
name:String
type:String
}
typeGeometry{
coordinates:[Float]
type:String
}
typeGeo{
geometry:Geometry
placekey:String
}
typeParentEvent{
parent_event_id:String
}
typeEvent{
aviation_rank:Int
brand_safe:Boolean
category:String
country:String
description:String
duration:Int
end:String
entities:[Entity]
first_seen:String
geo:Geo
id:String
labels:[String]
local_rank:Int
location:[Float]
parent_event:ParentEvent
phq_attendance:Int
place_hierarchies:[[String]]
private:Boolean
rank:Int
relevance:Int
scope:String
start:String
state:String
timezone:String
title:String
updated:String
}
typeEventsResult{
count:Int
next:String
overflow:Boolean
previous:Json
results:[Event]
}
You can now add the schema to your Hygraph project. Navigate to Schema | REMOTE SOURCES and press the Add button.
Fill in the details of the remote source and select the type as REST. Next, add https://api.predicthq.com/v1 as the base URL. In the Headers section, add the following:
"Authorization":"Bearer<The access token you created in predictHQ>
"Content-Type":"application/json;charset=utf-8"
Here's a screenshot of how that will look like:
Lastly, in the Custom type definition section, add the schemas generated above.
Since your app will filter events by location, PredictHQ provides another endpoint to get location identifiers. Repeat the Postman procedure above to get the data format and convert the JSON into an SDL. Tweak the generated SDL as follows:
Replace all instances of JSON with Json.
Rename the ROOT type to LocationsResult and the Result to Location. This is to make your schema more readable.
The final SDL schema should be as shown below:
typeLocation{
country:String
country_alpha2:String
country_alpha3:String
county:Json
id:String
location:[Float]
name:String
region:String
type:String
}
typeLocationsResult{
count:Int
next:Json
previous:Json
results:[Location]
}
Since both endpoints share the same base URL, you will not create a new remote source. Add the above schema to the previous remote source and save.
Models are the building blocks for your data. They define the data contained in your content and its types.
Events data model
To add an events model, navigate to Schema | MODELS and press Add. Fill in the name of the model—in this case, listEvent—and save.
On the resulting screen, you need to add fields that will hold your data. The events model will hold a REST field type and a String. Scroll down on the pane on your right until you find the REST field type and select it.
In the window that pops up, add the details about the endpoint. Please note that the Method will be GET and the return type will be EventsResult. This endpoint also takes in arguments that should be added in the Input arguments section. Finally, set the path of the remote source, making sure to include all arguments. In the end, your form should resemble the screenshots below:
Lastly, add a Single line text field and name it desc.
Your model dashboard should resemble the following screenshot:
Location data model
Repeating the same steps as above, create a new model named EventLocation with a REST field named Places and a Single line text field named desc.
The REST field should have a GET method with the return type being LocationsResult and a single argument. The bottom part of the form should resemble the screenshot below:
Category model
Your events app will filter events based on category. You must define these categories as a model on Hygraph.
Create a new model named EventCategory with a Single line text field named categories. Since there are many categories to use, make sure to tick the Allow multiple values checkbox and save.
You can now access your Hygraph project contents from a single API. However, to make sure only authorized apps make requests, you need to set up authorization.
Navigate to Project settings | ACCESS | API Access | Permanent Auth Tokens to create an authentication token.
After you create a token, the permissions screen will pop up. In the Content API section, click Add Permission. Select the Read permission, as shown below, and save.
This will allow only read requests on all your models at all stages.
You are going to build an Android app that will query content from Hygraph and display it to users.
Follow these steps to set up an Android project on Android Studio:
Open Android Studio and create an Empty Compose Activity project.
Provide the name of the app—in this case Events—press Finish, and wait for the project to load.
Add project dependencies
To query a GraphQL API, you can use the Apollo GraphQL library, which assists you in writing GraphQL queries and generating data models for their responses.
To handle making API requests asynchronously, you also need to add the Kotlin coroutine dependencies. Open the app/build.gradle file and add the following dependencies:
In the same file, update the plugins section to include the Apollo library. The section should be similar to this:
plugins{
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id("com.apollographql.apollo3").version("3.7.5")
}
Finally, you need to configure where the Apollo library will store its generated files. To do this, add the following code at the bottom of the app/build.gradle file:
apollo {
service("service"){
packageName.set("com.example.events.models")
}
}
Add internet permissions
Since the application will be making API requests over the Internet, you need to specify this permission so that the Android framework can request the user for it.
To do this, navigate to the AndroidManifest.xml file and add the internet permission shown below:
The Apollo library needs to know the type of data you intend to query and the available fields to generate the necessary code. Create a new schema.graphqls file in app/src/main/graphql/, which will hold the GraphQL schema of the Hygraph content.
You need to add the SDL schema generated in the Add Remote Source section to the new file. Your file should now contain the following:
typeLocation{
country:String
country_alpha2:String
country_alpha3:String
county:String
id:String
location:[Float]
name:String
region:String
type:String
}
typeLocationsResult{
count:Int
next:Int
previous:Int
results:[Location]
}
typeEntity{
entity_id:String
formatted_address:String
name:String
type:String
}
typeGeometry{
coordinates:[Float]
type:String
}
typeGeo{
geometry:Geometry
placekey:String
}
typeParentEvent{
parent_event_id:String
}
typeEvent{
aviation_rank:Int
brand_safe:Boolean
category:String
country:String
description:String
duration:Int
end:String
entities:[Entity]
first_seen:String
geo:Geo
id:String
labels:[String]
local_rank:Int
location:[Float]
parent_event:ParentEvent
phq_attendance:Int
place_hierarchies:[[String]]
private:Boolean
rank:Int
relevance:Int
scope:String
start:String
state:String
timezone:String
title:String
updated:String
}
typeEventsResult{
count:Int
next:String
overflow:Boolean
previous:Int
results:[Event]
}
With the above schema, the Apollo library will understand the kind of content that your GraphQL API returns when queried.
Write GraphQL queries
With the schema ready, you can now write some queries to fetch data from the Hygraph endpoint.
The Hygraph API Playground
Hygraph provides a handy API playground where you can write and test queries while viewing their response. You can tweak various fields to return only the content you need.
For instance, to query events, you need to pass in the category as well as the location_id to get a result. You can write a query similar to the screenshot below in the API playground, which will return events with only the defined subset of fields.
Write app GraphQL queries
After testing your queries in the playground, you can add them to the app.
Create a new file named AppQuery.graphql on the same level as your schema file. Save the file in app/src/main/graphql/. Add the following queries for query event categories, locations, and filter events:
After you add the above queries, Android Studio will display some compilation errors. This is because the previous schema file does not contain all the fields that the queries have. To solve this, you need to update the schema file with the following content:
With the above schema and query, the Apollo library can generate code that you can use to make requests. To generate the code, build your project again.
Note: Every time you change your schema and queries, rebuild the code so that the Apollo library can regenerate the code.
Build the events screen
The content and queries are all ready. How about enabling users to search and view events around them? This section discusses just that.
Set up the Apollo Client
You need to initialize and configure an ApolloClient that you will use in the app to make GraphQL requests. You will need the API endpoint from Hygraph, which you can get by navigating to Project Settings | ACCESS | API Access in the Content API section. You also need the access token created in the previous section.
In your com/project_org/project_name folder, create a file named ApolloClient.kt and add the following code to it:
The code above contains an interceptor and okHttpClient, which are used to manipulate the requests as well as log the response. The ApolloClient has an addHTTPHeader function that is used to add the authorization token.
Build the ViewModel
Your Android app will use a ViewModel to make an API request and update the screen once a response is received. In your com/project_org/project_name/viewmodels folder, create a file named MainViewModel.kt and add the following code to it:
The code above renders a user interface where users can select the category and location of events they would like to see. The app makes an API request to Hygraph with the chosen filters and returns a filtered result that is presented to the user.
With this in place, you can now build your app to test and validate the content.
You can find the complete app for this tutorial in this GitHub repository. Here's a video of how the app works:
In this article, you have learned how to model data to SDL schemas that can be used in GraphQL queries. You have also learned how to write GraphQL queries and fetch only the required data for your application needs. Lastly, you have used Hygraph to host your content and built an Android application to display it to users using GraphQL APIs.
Hygraph's GraphQL approach to collating and managing content enables you to build diverse, high-performant, and scalable applications with minimal friction between data sources. Its ability to handle remote sources lets you blend data from different providers into a single source of truth, leading to more stable and resilient applications. Create a free forever account now and take this project for a spin.
Blog Author
Dedan Ndungu
Technical Writer
Dedan Ndungu is a software engineer with experience in mobile app development using Java, Kotlin, and Flutter. He's also experienced integrating Firebase services to deliver quality and scalable mobile applications.
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.