lura
lura copied to clipboard
Rest to graphql
Hello, We are interested in using the transformation from rest to graphql, so far we were able to perform the consumption with a configuration similar to this: `{ "version": 3, "host": ["http://127.0.0.1:8081"], "extra_config": { "telemetry/logging": { "level": "DEBUG", "prefix": "[KRAKEND]", "syslog": false, "stdout": true, "format": "custom", "custom_format": "%{message}" } }, "endpoints": [ { "endpoint": "/v1/endpoint/{var}", "method": "GET", "extra_config": { "qos/ratelimit/router": { "max_rate": 5000 } }, "input_query_strings": [ "var", "page_size", "page_number" ], "encoding": "json", "output_encoding": "no-op",
"backend": [
{
"disable_host_sanitize": true,
"sd":"static",
"encoding": "json",
"url_pattern": "/query",
"extra_config": {
"modifier/martian": {
"header.Modifier": {
"scope": ["request","response" ],
"name": "Content-Type",
"value": "application/json"
}
},
"backend/graphql": {
"method":"POST",
"type": "query",
"query_path": "./graphql/test.graphql",
"variables": {
"var":"{var}"
}
}
}
}
]
}
]
}`
One of the benefits of graphql is that it is not necessary to consume all the fields always, only based on the request, this implies that the variables are sometimes present in the url and others are not, we havent been able to implement that scenario in which the variables may not be present if var its not present int the request url we get errorrs so :
1- Is it possible to perform the transformation from rest to graphql with optional variables?
2- Is there an example for this case?
3-It is possible to use the transformation with calls of the type: /endpoint?var1=value&var2=value?
Thanks in advance
@salvadorcea have you found any solution to this? I am also looking for a similar solution.
you can change the endpoint method to POST and your operation type to mutation
and krakend will merge the vars defined at the config with the elements contained at the request body. From the documentation:
method=post + type=mutation: Generates a body including any variables in the REST body plus the ones in the configuration
This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.