Schema stitching is the process of creating a single GraphQL schema from multiple underlying GraphQL APIs.
Schema stitching allows you to have one unified API that allows the client to query multiple GraphQL Schemas at the same time, including relations between the schemas.
This demo requires Hasura's GraphQL Engine running with the following schema:
A table called Person with columns id, name, and city.
npm install
HASURA_GRAPHQL_ENGINE_URL=http://localhost:9000 npm start
Change the HASURA_GRAPHQL_ENGINE_URL environment variable to point to a hasura graphql-engine with the person schema. Then, open localhost:8080/graphiql in your web browser, and start exploring with your query.
This demo combines two GraphQL schemas and exposes them on a single API:
- The public GraphQL API of Meta Weather, to fetch the temperature information for a given city. Explore this on Apollo Launchpad
- The Hasura GraphQL API, having a table called
Personwith columnsid,nameandcity.
# Get weather info
query {
cityWeather(city_name: "Bangalore") {
city_name
temp
min_temp
max_temp
applicable_date
}
}
# Get person data from Hasura Data API
query fetch_person {
person {
id
name
city
}
}We can extend the persons city column to include weather information.
extend type person {
city_weather: CityWeather
}Now this can be merged and queried using the same API like:
query {
person {
id
name
city
# fetching weather after schema stitching
city_weather {
city_name
temp
min_temp
max_temp
applicable_date
}
}
}