Overview
The Universal Data Graph (UDG) lets you combine multiple APIs into one universal interface. With the help of GraphQL you’re able to access multiple APIs with a single query. It’s important to note that you don’t even have to build your own GraphQL server. If you have existing REST APIs all you have to do is configure the UDG. With the Universal Data Graph Tyk becomes your central integration point for all your internal as well as external APIs. In addition to this, the UDG benefits from all existing solutions that already come with your Tyk installation. That is, your Data Graph will be secure from the start and there’s a large array of middleware you can build on to power your Graph.
- REST
- GraphQL
- SOAP (through the REST datasource)
-
Kafka
To start creating your first Universal Data Graph in Tyk Dashboard, go to “Data Graphs” section of the menu.
Key Concepts
Universal Data Graph
The Universal Data Graph (UDG) introduces a few concepts you should fully understand in order to make full use of it. UDG comes with a fully spec compliant GraphQL engine that you don’t have to code, you just have to configure it. For that you have to define your “DataSources” and might want to add “Field Mappings” as well as “Arguments” to your configuration. Read on in the sub sections to understand the full picture to use UDG to its full potential. To help you, we have put together the following video.DataSources
In most GraphQL implementations you have the concept of Resolvers. Resolvers are functions that take optional parameters and return (resolve) some data. Each resolver is attached to a specific type and field. DataSources are similar in that they are responsible for loading the data for a certain field and type. The difference is that with DataSources you simply configure how the engine should fetch the data whereas with traditional GraphQL frameworks you have to implement the function on your own. DataSources can be internal as well as external. Internal DataSources are APIs that are already managed by Tyk, such as REST or SOAP services configured through the Dashboard. You can take advantage of Tyk’s rich middleware ecosystem to validate and transform requests and responses for these internal DataSources. External DataSources are APIs that you’re not currently managing through Tyk. For simplicity, you can add them to your data graph without first configuring them as dedicated APIs in Tyk. If you later decide to apply middleware or other policies, you can easily transition an external DataSource into a managed internal API. Head over to the connect data source section to learn about the supported data sources and how to connect them to Tyk.Arguments
Looking back at the example from the “Field Mappings”, you might wonder how to use the “id” argument from the GraphQL query to make the correct REST API call to the user service. Here’s the schema again:{
) will produce a dropdown that contains all available fields and arguments.

Field Mappings
Universal Data Graph can automatically resolve where data source information should go in the GraphQL response as long as the GraphQL schema mirrors the data source response structure. Let’s assume you have a REST API with a user resource like this:http://example.com/users/:id
The following is an example response:
user(id: Int!)
query, UDG will be able to automatically resolve where id
and name
values should be in UDG response. In this case no field mapping is necessary.
GraphQL does not support field names with hyphens (e.g.
"user-name"
). This can be resolved by using field mappings as described below.[]
like this:
id
, name
and phone-number
and fields mapping needs to be used as well. To get the response from inside the brackets the following syntax has to be used in field mapping: [0]
.
It is also possible to use this syntax for nested paths. For example: [0].user.phone-number
Field mapping in Tyk Dashboard
See below how to configure the field mapping for each individual field.
Field mapping in Tyk API definition
If you’re working with raw Tyk API definition the field mapping settings look like this:Reusing response fields
When using the UDG, there may be a situation where you want to access an API with data coming from another API. Consider the following REST APIs:- REST API for people:
https://people-api.dev/people
- REST API for a specific person:
https://people-api.dev/people/{person_id}
- REST API for driver licenses:
https://driver-license-api.dev/driver-licenses/{driver_license_id}
driverLicenseID
from the People API to obtain the driver license data from the Driver License API.
You also want to design the schema so that it represents the relationship between a person and a driver license.
As the person object is referencing a driver license by its ID, it means that we will need to define the driver license inside the person object as a field.
Consequently, a schema representing such a relationship might look like this:
Defining the data source URLs
Now it’s all about defining the data source URLs. For the fieldQuery.people
, you can simply use the URL to the API:
Query.person
field needs to use its id
argument to call the correct API endpoint.
See Concept: Arguments to learn more about it.
driverLicenseID
from the Person
object. As we defined the driver license data source on the Person
object, you can now access all properties from the Person
object by using the .object
placeholder.
If you want to access data from the object on which the data source is defined, use the
.object
placeholder (e.g: .object.id
to access the id
property from an object).
Result
A query like:Header management
With Tyk v5.2 the possibilities of managing headers for Universal Data Graph and all associated data sources have been extended.Global headers for UDG
Global headers can be configured via Tyk API Definition. The correct place to do that is withingraphql.engine.global_headers
section. For example:
Data source headers
Data source headers can be configured via Tyk API Definition and via Tyk Dashboard UI. The correct place to do that is withingraphql.engine.datasources.config.headers
section. For example: