Overview
This endpoint demonstrates KrakenD’s ability to convert GraphQL APIs into REST endpoints, allowing REST clients to consume GraphQL data without knowing the GraphQL query language. HTTP Method:GETEndpoint:
/starwars_films/{movie_id}
Parameters
The Star Wars film ID (1-6). Valid values:
1- The Phantom Menace2- Attack of the Clones3- Revenge of the Sith4- A New Hope5- The Empire Strikes Back6- Return of the Jedi
What It Demonstrates
- GraphQL to REST Conversion: Exposes a GraphQL API as a RESTful endpoint
- GraphQL Query Execution: Executes complex GraphQL queries behind the scenes
- Variable Interpolation: Maps URL path parameters to GraphQL variables
- Target Extraction: Extracts specific fields from nested GraphQL responses
Request Example
Expected Response
Backend Service
- Host:
https://swapi-graphql.netlify.app/ - URL Pattern:
/.netlify/functions/index - Type: GraphQL API
- Target:
data.film(extracts the film object from the GraphQL response)
GraphQL Query
KrakenD executes this GraphQL query behind the scenes:KrakenD Configuration
Key Configuration Options
backend/graphql
Configures the GraphQL integration:
- type:
"query"- Specifies this is a GraphQL query (not a mutation) - query: The GraphQL query string with placeholders
- variables: Maps URL path parameters to GraphQL variables
target
Extracts a specific field from the GraphQL response:
target configuration extracts just the film object, making the response cleaner for REST clients.
Variable Interpolation
{movie_id} with the value from the URL path.
Use Cases
- Legacy Integration: Expose modern GraphQL APIs to legacy REST clients
- Simplified Client Code: Clients don’t need GraphQL libraries or knowledge
- API Gateway Pattern: Provide a unified REST interface to mixed backend types
- Mobile Apps: Reduce client complexity by handling GraphQL on the gateway
- Third-party Integrations: Make GraphQL APIs accessible to partners expecting REST