-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Collection variable not interpolated in GraphQL vars #2960
Comments
Not sure if this is something the Bruno team will be looking to add in the future, but in the meantime @rbideau, we've been using this in pre-request scripts: resolveTemplateVariables: function (string) {
const VARIABLE_NAME_REGEX = /{{([A-Za-z]\w+)}}/g
return string.replace(
VARIABLE_NAME_REGEX,
(_, key) => bru.getVar(key) || bru.getEnvVar(key)
)
} |
Ah, never mind, I see this is a net-new/separate issue. I think we needed to manually interpolate the string in the query, but never in the input variables |
I also have this issue. No matter what I try, I cannot use Bruno environment variables, or any other variables within the graphql variables. They just are not replaced before bruno sends the request. As a workaround, I'm able to use bru variables within the graphql variables by using a standard HTTP request, JSON body, with something like:
In the above example, the {{source}} and {{dataID}} variables are set by Bruno within a pre-request script
|
Still on v1.28.0 Also it was working before since we have many request that uses it. Happy to help debugging or giving some tests example if necessary. |
This is a regression and worked fine in 1.24 I had to go back to earlier build |
I was able to get it working by using the script of @mkurapov in a collection pre-script a bit changed: function resolveTemplateVariables(string) {
const VARIABLE_NAME_REGEX = /{{([A-Za-z_]\w+)}}/g;
return string.replace(
VARIABLE_NAME_REGEX,
(_, key) => bru.getVar(key) || bru.getEnvVar(key)
);
}
let body = req.getBody();
if (!body.variables) {
return;
}
let resolvedVariables = resolveTemplateVariables(body.variables);
body.variables = resolvedVariables;
//console.log(body); Works well with my Magento 2 project. |
I did something similar but kept copying it in every request, thank you @cmuench for making me realize that indeed the collections scripts exists! Although your script is fairly complete, there's two things I changed in my version : // Bruno apparently does not support variables substitution in GQL queries yet :)
// Doing this temporarily until this is fixed.
// https://github.com/usebruno/bruno/issues/2960
let body = req.getBody();
if (!body?.variables) {
return;
}
function resolveTemplateVariables(string) {
const VARIABLE_NAME_REGEX = /{{(\w+)}}/g;
return string.replace(
VARIABLE_NAME_REGEX,
(_, key) => bru.getVar(key) || bru.getEnvVar(key)
);
}
const resolvedVariables = resolveTemplateVariables(body.variables);
body.variables = resolvedVariables;
Hopefully this can get fixed so we don't need this workaround (especially since it seems like it was a regression, having hover info of the variable value in the GQL variables view would be super helpful!). |
The interpolation is only broken in the UI -- it works on the command line. However, the pre-request script breaks the CLI usage, because on the CLI, Revised pre-request script checks for this: // Bruno UI has a regression w.r.t. environment variables in GraphQL variables.
// Doing a manual replacement until the issue is fixed.
// https://github.com/usebruno/bruno/issues/2960
let body = req.getBody();
// skip if the variables are not defined or if the CLI runner is used (-> typeof variables is "object" there)
if (!body?.variables || (typeof body.variables === 'object')) {
return;
}
function resolveTemplateVariables(string) {
const VARIABLE_NAME_REGEX = /{{(\w+)}}/g;
return string.replace(
VARIABLE_NAME_REGEX,
(_, key) => bru.getVar(key) || bru.getEnvVar(key)
);
}
const resolvedVariables = resolveTemplateVariables(body.variables);
body.variables = resolvedVariables; |
Hopefully they fix this issue in new version |
Confirm this is the same bug as #352 This could fix the issue, merged on September 23: #3142, so should be good on 1.30.2 / 1.31.0 Reverting to 1.26.2 until fixed EDIT: Tried to build current version and still doesn't work |
I have checked the following:
Describe the bug
On version 1.27.0, collection variable are not interpolated in GraphQL Vars when executing the request via the app.
Might be related to
.bru file to reproduce the bug
Screenshots/Live demo link
Screencast.from.29-08-2024.08.35.56.webm
The text was updated successfully, but these errors were encountered: