graphql-client
graphql-client copied to clipboard
Problem with nonnull fields and @include directives
I have following request:
query ListRuns($detailed: Boolean!) {
submissions {
id,
problem @include(if: $detailed),
score @include(if: $detailed),
status @include(if: $detailed) {
kind,
code
},
toolchainName @include(if: $detailed)
}
}
When I execute this request with $detailed: true, my program receives required data successfully.
But when $detailed: false, instead of success I get error:
Error(Json(Error("missing field `problem`", line: 1, column: 32)))
Some my thoughts on why is it happening
related fragments from schema:
type Query {
submissions(...): [Run!]!
}
type Run {
id: Int!
problem: String!
score: Int
status: InvokeStatusOut!
toolchainName: String!
}
So, graphql-client sees, that almost all fields on Run are non-nullable, and emits following definiion (taken from cargo-expand output):
// (inside mod list_runs)
pub struct ListRunsSubmissions {
pub id: Int,
pub problem: String,
pub score: Option<Int>,
pub status: ListRunsSubmissionsStatus,
#[serde(rename = "toolchainName")]
pub toolchain_name: String,
}
To my mind, fields problem, status and toolchain_name should be marked as optional, because they are included in query conditionally.
However, I see that they are still non-nullable, and when they are missing in server reply because of detailed=false, deserialization fails.
Thanks for the detailed issue - I think this is indeed a bug.
I will try to find time to fix it asap, and if someone else has time that's even better, I can provide directions :)
At minimum it should be easy to test for, I'll try to open a PR for that first.
Has any progress been made here? I am also having this issue.
No, I don't have time to work on this library at the moment. I'm happy to review and merge PRs though.