For a more performant solution than virtual endpoints, but a little less usable, this can also be achieved by creating a Tyk HTTP api on top of your GraphQL api. You could then apply body transforms, header transforms and method transforms to expose a REST fascade to your GraphQL APl.
Let’s take the countries.trevorblades.com GraphQL api as an example.
echo -n eyJxdWVyeSI6InF1ZXJ5IHsgY29udGluZW50cyB7IGNvZGUgbmFtZSB9IH0ifQ== | b
ase64 --decode
{"query":"query { continents { code name } }"}
API Definition Snippet
"extended_paths": {
"transform": [
{
"template_data": {
"input_type": "json",
"template_mode": "blob",
"enable_session": false,
"template_source": "eyJxdWVyeSI6InF1ZXJ5IHsgY29udGluZW50cyB7IGNvZGUgbmFtZSB9IH0ifQ==",
"input": "",
"output": ""
},
"path": "/continents",
"method": "GET"
},
{
"template_data": {
"input_type": "json",
"template_mode": "blob",
"enable_session": false,
"template_source": "eyJxdWVyeSI6InF1ZXJ5IHsgY291bnRyaWVzIHsgY29kZSBuYW1lIGNhcGl0YWwgfSB9IiwidmFyaWFibGVzIjp7ImNvZGUiOiJHQiJ9fQ==",
"input": "",
"output": ""
},
"path": "/countries",
"method": "GET"
}
],
"transform_response": [],
"transform_headers": [
{
"delete_headers": [],
"add_headers": {
"Content-Type": "application/json"
},
"path": "/continents",
"method": "GET",
"act_on": false
},
{
"delete_headers": [],
"add_headers": {
"Content-Type": "application/json"
},
"path": "/countries",
"method": "GET",
"act_on": false
}
],
"transform_response_headers": [],
"url_rewrites": [
{
"path": "/continents",
"method": "GET",
"match_pattern": "/continents",
"rewrite_to": "https://countries.trevorblades.com/",
"triggers": []
},
{
"path": "/countries",
"method": "GET",
"match_pattern": "/countries",
"rewrite_to": "https://countries.trevorblades.com/",
"triggers": []
}
],
"method_transforms": [
{
"path": "/continents",
"method": "GET",
"to_method": "POST"
},
{
"path": "/countries",
"method": "GET",
"to_method": "POST"
}
]
}
Example:
curl -s http://localhost:8080/trevorblades/continents | jq
{
"data": {
"continents": [
{
"code": "AF",
"name": "Africa"
},
{
"code": "AN",
"name": "Antarctica"
},
{
"code": "AS",
"name": "Asia"
},
{
"code": "EU",
"name": "Europe"
},
{
"code": "NA",
"name": "North America"
},
{
"code": "OC",
"name": "Oceania"
},
{
"code": "SA",
"name": "South America"
}
]
}
}
You can now apply cache plugins and other middlewares.