graphql-dotnet / graphql-dotnet/graphql-client

Variable parsing different between C# "GraphQLRequest" and json/webui

Open
#648 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
648
Forks
136
PR merge metrics
No merged PRs in 30d

Description

## Description

C# requires an exact match in variable names, despite this not being a requirement on the backend (or for e.g. requests made with POSTMAN)

### Steps to reproduce

I don't have a publicly available endpoint for you to test this against, but the short version:

I get the expected result when I `POST` this:

```json
{
"query" :
"query CustomsFields($AWB: String!) { shipments( filter: { shipment_awb: $AWB } ) {
shipment {
documents {
document_code
document_url
}
}
}
}",
"variables" : {
"AWB":"this string is secret"
}
}
```

I get an error response when I `SendQueryAsync<>` this:

```csharp
const string queryText =
"""
query CustomsFields($AWB: String!) {
shipments(filter: { shipment_awb: $AWB }) {
shipment {
documents {
document_code
document_url
}
}
}
}
""";

var client = new GraphQLHttpClient(new TestSettings().Endpoint, new SystemTextJsonSerializer());
var o = await client
.SendQueryAsync(
new GraphQLHttpRequest(
query: query,
variables:new{AWB="this string is secret"} // NOTICE: Variable name is "AWB"
)
);

```

The specific error response is:

```
"Errors":[{"Locations":[{"Column":21,"Line":1}],"Message":"Variable '$AWB' is invalid. No value provided for a non-null variable.",
```

If I change the variable name from `$AWB` to `$shipment_awb`, the request succeeds with the same response as the raw post call.

## EXPECTED

Variable semantics are identical for calls made with REST and calls made with `SendQueryAsync`

## Actual

Variable semantics are not identical for etc./

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.