Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent interpolation behavior in various parts of the configuration #660

Open
egmar opened this issue May 12, 2023 · 1 comment
Open
Assignees
Labels
enhancement Enhancement request on an existing feature
Milestone

Comments

@egmar
Copy link

egmar commented May 12, 2023

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

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 }}.

backend.URLPattern = strings.ReplaceAll(backend.URLPattern, "{"+output+"}", "{{."+key+"}}")

To Reproduce
Steps to reproduce the behavior:

  1. 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
        }
      ]
    }
  1. 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.

@kpacha kpacha added this to the 3.0 milestone Sep 28, 2023
@kpacha kpacha added the enhancement Enhancement request on an existing feature label Sep 28, 2023
@kpacha
Copy link
Member

kpacha commented Sep 28, 2023

For historical reasons, params are capitalized during its extraction (at the beginning of this project, url patterns were treated as templates). Once the reason was removed, we couldn't change that behavior because there are several other components and extensions than relies on that convention.

We can keep this idea for the future 3.0 version, where we can break compatibility.

Thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement request on an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants