Skip to content
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

Merged
merged 7 commits into from
Sep 8, 2022
Merged

Conversation

Selyatin
Copy link
Contributor

Closes #411 and #262 :)

Copy link
Member

@tomhoule tomhoule left a 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.

@Selyatin
Copy link
Contributor Author

@tomhoule requested changes were made, let me know if the test looks good.

README.md Outdated Show resolved Hide resolved
@tomhoule tomhoule merged commit 0776197 into graphql-rust:main Sep 8, 2022
@Nohac
Copy link

Nohac commented Oct 20, 2022

Sorry for bumping this closed PR, but I'm really struggling to get this to work.
I've added skip_serializing_none to the struct as stated in the README, but doing so still leaves me with null values after serialization.

My first guess was that this hasn't been released yet, so I switch over to the main branch in Cargo.toml, but that changed nothing. Here's the code I'm using:

#[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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Skipping Serialization of None fields.
4 participants