Skip to content

Don't send variable as "field": null if variable is None #752

Closed Answered by obmarg
djkato asked this question in Q&A
Discussion options

You must be logged in to vote

The InputObject derive provides a skip_serailizing_if attribute that can help with this:

#[derive(cynic::InputObject, Debug)]
pub struct CategoryInput<'a> {
    #[cynic(skip_serializing_if = "Option::is_none")]
    pub description: Option<Jsonstring>,
    #[cynic(skip_serializing_if = "Option::is_none")]
    pub name: Option<&'a str>,
    #[cynic(skip_serializing_if = "Option::is_none")]
    pub slug: Option<&'a str>,
    #[cynic(skip_serializing_if = "Option::is_none")]
    pub seo: Option<SeoInput<'a>>,
    #[cynic(skip_serializing_if = "Option::is_none")]
    pub background_image: Option<Upload>,
    #[cynic(skip_serializing_if = "Option::is_none")]
    pub background_image_alt: Option<&'

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@djkato
Comment options

Answer selected by djkato
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants