Edit

Share via


Query multiple data sources in Fabric API for GraphQL

In Fabric API for GraphQL, you can expose many data sources through a single API item. This feature allows you to issue a single query that retrieves data across multiple data sources.

A multi-data source query is a sequence of queries that perform operations against different data sources.

This functionality enhances application performance by reducing the number of round trips between your application and the API for GraphQL.

Note

A multi-data source request fans out individual requests to data sources. You can't create relationships across types that span multiple data sources. Additionally, there isn't a guarantee on the order the individual requests execute.

Query example

The following example shows a query that spans both the ContosoSales and ContosoInventory data sources:

query {
  customers (first: 1) {
    items {
      FirstName
      LastName
    }
  }
  inventories (first: 1) {
    items {
      Name
    }
  }
}

This request retrieves the first node from the customers query derived from the ContosoSales data source, and the first node from the inventories query derived from the ContosoInventory data source.

The output for the request is:

{
  "data": {
    "customers": {
      "items": [
        {
          "FirstName": "Orlando",
          "LastName": "Gee"
        }
      ]
    },
    "inventories": {
      "items": [
        {
          "Name": "AWC Logo Cap"
        }
      ]
    }
  }
}

The output has two parts: The first section, "data", contains the output of the customers query, and the second section, "inventories", contains the output of the inventories query.

This is how the query view looks when you execute this request:

Screenshot of the editor screen showing a query spanning two data sources.