I am trying to define a config, where a GraphQL Backend is called using a boolean variable, which comes from the query variables. See the following:
{{ define "graphql-backend" }}
"backend/graphql": {
"type": "query",
"query_path": "./output.graphql",
"variables": {
"locale": "{locale}",
"preview": "{preview}"
{{- with .variables -}},
{{- $vars := . -}}
{{- $length := len $vars -}}
{{- range $i, $key := keys $vars }}
"{{ $key }}": "{{ index $vars $key }}"{{ if lt $i (sub $length 1) }},{{ end }}
{{- end }}
{{- end }}
},
"operationName": "{{ .operation }}"
}
{{- end }}
The problematic line is "preview": "{preview}" as the substitution will always be a string. {preview} is a query param, i.e. what comes behind the ? in the URL, e.g. ?locale=en-US&preview=false. Thus it is supposed to be recognized at runtime. Is there a way to fix this? I could also adjust the GraphQL if needed, but I don't think there is a solution there.
The only (kinda ugly) solution i am seeing is creating two separate endpoints. Though if more such variables are added, the complexity will explode.
Also, is there a way to set a default value for locale and variables?