americanexpress/nodes

Variables not taken into account - Need help (or bug)

Closed this issue · 1 comments

Hi,
My variables don't seem to be taken into account when executing the query

List<Variable> myVars = new ArrayList<Variable>();
myVars.add(new Variable<String>("name", "text"));
myVars.add(new Variable<String>("language", "en"));

GraphQLRequestEntity requestEntity = GraphQLRequestEntity.Builder()
			.url(TestGlobalConfiguration.getGraphQlUrl())
			.variables(myVars).request(Jcr.class)
			.build();

GraphQLTemplate graphQLTemplate = new GraphQLTemplate();
GraphQLResponseEntity<Jcr> responseEntity = graphQLTemplate.query(requestEntity, Jcr.class);

In the Model I have defined, one of the property has the variables definition:

@GraphQLVariables({@GraphQLVariable(name = "name", scalar = "String"),
@GraphQLVariable(name = "language", scalar = "String")})
private Property property;

However when executing the request I can see the query is:

query ($name:String,$language:String){ jcr { nodeByPath { marketingFactory { optimizationTestVariant { path name property (name:$name,language:$language) { value } uuid } personalizedVariant { path name property (name:$name,language:$language) { value } uuid } } name uuid } } }

Which obviously returns:
Validation error of type VariableTypeMismatch: Variable type doesn't match since $name is not the expected "text"

I used to use GraphQLArguments, which worked fine but when you have the same arguments at two different places it is recommended to use Variables.
What am I doing wrong?

Apparently I needed to write scalar = "String!" to require the parsing of my variable.
Not sure why you would not want to parse the variable then....