I'm trying to send a GraphQL Request using This GraphQL Library.
When I attempt to send the GraphQLRequest with some variables attached I get the following error,Variable $max is used by but not declared.
GraphQLRequest graphqlRequest = new GraphQLRequest
{
Query = "query {boards(limit: $max) {items(limit: $max) {id}}}",
Variables = new
{
max = "1"
}
};
GraphQLResponse<string> graphQLResponse = await _graphqlClient.SendQueryAsync<string>(graphqlRequest);
Changing max from a string to an int had no change.
If I try and send the same request hardcoded without the Variables attached, the request is successful.
query {boards(limit: 1) {items(limit: 1) {id}}}
Update
I updated the query with the help of gunr2171's answer, however unfortunately the sdk is still throwing errors.
GraphQLRequest graphqlRequest = new GraphQLRequest
{
Query = "query($max: Int) {boards(limit: $max) {items(limit: $max) {id}}}",
Variables = new
{
max = 1
}
};
System.AggregateException: 'One or more errors occurred. (Unexpected character encountered while parsing value: {. Path 'data', line 1, position 9.)'
I tried changing $max: Int to $max: String as well as max = 1 to max = "1"
but the request isnt sucessful.
Variable max of type Int was provided invalid value or Type mismatch on variable $max and argument limit (String / Int) depending on the combination.
Update
Changing the response type from string to the proper object response has solved the problem. eg
GraphQLResponse<string> graphQLResponse = await _graphqlClient.SendQueryAsync<string>(graphqlRequest);
to
GraphQLResponse<AuthorizationResponse> graphQLResponse = await _graphqlClient.SendQueryAsync<AuthorizationResponse>(graphqlRequest);
For some one reason or another when using Variables it didnt like the string response type.
Thank you gunr2171 for their help, and pointing me in the right direction