graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Add skip_serializing_none feature

Open Selyatin opened this issue 2 years ago • 1 comments

Closes #411 and #262 :)

Selyatin avatar Aug 17 '22 12:08 Selyatin

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

Selyatin avatar Aug 19 '22 15:08 Selyatin

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?

Nohac avatar Oct 20 '22 12:10 Nohac