-
Notifications
You must be signed in to change notification settings - Fork 580
Description
Describe the bug
Inconsistent interpolation behavior in various parts of the configuration. In current state, when endpoint has one or more parameters, the parameters can be used in url_pattern freely. When using endpoint parameters in backend/graphql variables, it is not possible to have a string containing multiple parameters as in url_pattern.
I believe the bug is in
lura/transport/http/client/graphql/graphql.go
Lines 97 to 105 in faec9df
| for k, v := range opt.Variables { | |
| val, ok := v.(string) | |
| if !ok { | |
| continue | |
| } | |
| if val[0] == '{' && val[len(val)-1] == '}' { | |
| replacements = append(replacements, [2]string{k, title.String(val[1:2]) + val[2:len(val)-1]}) | |
| } | |
| } |
With url_pattern the logic is reversed and all parameters are replaced in one go by transforming {paramater} to a Go template variable {{ .parameter }}.
Line 579 in faec9df
| backend.URLPattern = strings.ReplaceAll(backend.URLPattern, "{"+output+"}", "{{."+key+"}}") |
To Reproduce
Steps to reproduce the behavior:
- Configuration used:
endpoint configuration
{
"endpoint": "/v1/{owner}/{repo}/announcements",
"method": "GET",
"output_encoding": "json",
"backend": [
{
"url_pattern": "/api/graphql",
"encoding": "json",
"target": "data.search",
"sd": "static",
"method": "POST",
"extra_config": {
"backend/graphql": {
"type": "query",
"query_path": "./graphql/github.announcements.graphql",
"variables": {
"query": "repo:{owner}/{repo} category:Announcements label:component:rollout"
}
},
"modifier/martian": {
"header.Modifier": {
"scope": ["request"],
"name": "Authorization",
"value": "Bearer {{ env "GITHUB_TOKEN" }}"
}
}
},
"host": [
"https://github.com"
],
"disable_host_sanitize": false
}
]
}- Configuration is used with krakend.
Expected behavior
Endpoint parameter interpolation will work consistently in all elements of configuration where parameters are allowed to be used. In above example, is this part:
"query": "repo:{owner}/{repo} category:Announcements label:component:rollout"
Logs
No logs, as there are no errors in this use case. Just a bad query is passed to graphql request, but returning empty result.
Additional context
GraphQL doesn't have string interpolation and this functionality will help preparing variables before being passed to the GraphQL request.