-
Notifications
You must be signed in to change notification settings - Fork 159
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
Add skip_serializing_none feature #431
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks for the PR!
I think there are two points to address before we can merge this:
-
We should change the way the attribute value is specified, expecting
true
as a string is not a good API. Maybe something like#[graphql(schema_path = "...", query_path = "...", skip_serializing_none)]
or#[graphql(schema_path = "...", query_path = "...", skip_serializing_none = true)]
? (I prefer the first one, and it should be doable) -
We should have at least one end-to-end test that checks that the flag works by actually serializing an input (there are a bunch of examples in https://github.com/graphql-rust/graphql-client/tree/main/graphql_client/tests) — asserting that the generated code contains a specific substring sounds a bit brittle.
… end-to-end test for it.
@tomhoule requested changes were made, let me know if the test looks good. |
Sorry for bumping this closed PR, but I'm really struggling to get this to work. My first guess was that this hasn't been released yet, so I switch over to the #[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/insert_mutation.graphql",
response_derives = "Debug",
skip_serializing_none
)]
pub struct InsertMutation; let vars = Variables {
// .. omitted
user_id: None,
// .. omitted
};
let q = crate::graphql::InsertMutation::build_query(vars);
let skipped = serde_json::to_string_pretty(&q).unwrap();
println!("{skipped}"); Output: {
"variables": {
// .. omitted
"user_id": null,
// .. omitted
},
...
} Is there something obvious I'm missing here to make this work, or is this something that warrants it's own issue? |
Closes #411 and #262 :)