-
Hello, me again :) TL;DR:Is there a way to not send the nulled fields at all? So instead of sending Long version:I'm receiving error: errors = [
GraphQlError {
message: "argument of type 'NoneType' is not iterable",
locations: Some(
[
GraphQlErrorLocation {
line: 2,
column: 3,
},
],
),
path: Some(
[
Field(
"categoryCreate",
),
],
),
extensions: Some(
IgnoredAny,
),
},
] schema: saleor.txt mutation createCategory($input: CategoryInput!, $parent_id: ID) {
categoryCreate(parent: $parent_id, input: $input) {
errors {
code
}
category {
id
}
}
} dbg!() of query: mutation CreateCategory($input: CategoryInput!, $parentId: ID) {\n categoryCreate(input: $input, parent: $parentId) {\n errors {\n code\n }\n category {\n id\n }\n }\n}\n\n dbg!() of variables (And yes JSON string parses with JSON.parse() ): CreateCategoryVariables {
input: CategoryInput {
description: Some(
Jsonstring(
"{\"blocks\":[{\"type\":\"paragraph\", \"data\":\"\"}]}",
),
),
name: Some(
"Root",
),
slug: Some(
"root",
),
seo: None,
background_image: None,
background_image_alt: Some(
"Root",
),
metadata: None,
private_metadata: None,
},
parent_id: None,
} Generated Structs: #[derive(cynic::QueryVariables, Debug)]
pub struct CreateCategoryVariables<'a> {
pub input: CategoryInput<'a>,
pub parent_id: Option<&'a cynic::Id>,
}
#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Mutation", variables = "CreateCategoryVariables")]
pub struct CreateCategory {
#[arguments(input: $input, parent: $parent_id)]
pub category_create: Option<CategoryCreate>,
}
#[derive(cynic::QueryFragment, Debug)]
pub struct CategoryCreate {
pub errors: Vec<ProductError>,
pub category: Option<Category>,
}
#[derive(cynic::QueryFragment, Debug)]
pub struct ProductError {
pub code: ProductErrorCode,
}
#[derive(cynic::QueryFragment, Debug)]
pub struct Category {
pub id: cynic::Id,
}
#[derive(cynic::Enum, Clone, Copy, Debug)]
pub enum ProductErrorCode {
AlreadyExists,
AttributeAlreadyAssigned,
AttributeCannotBeAssigned,
AttributeVariantsDisabled,
MediaAlreadyAssigned,
DuplicatedInputItem,
GraphqlError,
Invalid,
InvalidPrice,
ProductWithoutCategory,
NotProductsImage,
NotProductsVariant,
NotFound,
Required,
Unique,
VariantNoDigitalContent,
CannotManageProductWithoutVariant,
ProductNotAssignedToChannel,
UnsupportedMediaProvider,
PreorderVariantCannotBeDeactivated,
}
#[derive(cynic::InputObject, Debug)]
pub struct CategoryInput<'a> {
pub description: Option<Jsonstring>,
pub name: Option<&'a str>,
pub slug: Option<&'a str>,
pub seo: Option<SeoInput<'a>>,
pub background_image: Option<Upload>,
pub background_image_alt: Option<&'a str>,
pub metadata: Option<Vec<MetadataInput<'a>>>,
pub private_metadata: Option<Vec<MetadataInput<'a>>>,
}
#[derive(cynic::InputObject, Debug)]
pub struct MetadataInput<'a> {
pub key: &'a str,
pub value: &'a str,
}
#[derive(cynic::InputObject, Debug)]
pub struct SeoInput<'a> {
pub title: Option<&'a str>,
pub description: Option<&'a str>,
}
#[derive(cynic::Scalar, Debug, Clone)]
#[cynic(graphql_type = "JSONString")]
pub struct Jsonstring(pub String);
#[derive(cynic::Scalar, Debug, Clone)]
pub struct Upload(pub String); I wanted to thoroughly look into the issue this time, so I tapped into the communication with wireshark and observed the querries passing around. This is the request that was sent with the app: {
"operationName": "CreateCategory",
"query": "mutation CreateCategory($input: CategoryInput!, $parentId: ID) {\n categoryCreate(input: $input, parent: $parentId) {\n errors {\n code\n }\n category {\n id\n }\n }\n}\n\n",
"variables": {
"input": {
"backgroundImage": null,
"backgroundImageAlt": "Root",
"description": "{\"blocks\":[{\"type\":\"paragraph\", \"data\":\"\"}]}",
"metadata": null,
"name": "Root",
"privateMetadata": null,
"seo": null,
"slug": "root"
},
"parentId": null
}
} And I also took at how the request looks like when it's successful, so I used graphql playground, and it's successful request was: {
"query": "mutation createCategory($input: CategoryInput!, $parent_id: ID) {\n categoryCreate(parent: $parent_id, input: $input) {\n errors {\n code\n }\n category {\n id\n }\n }\n}\n",
"variables": {
"input": {
"description": "{\"blocks\":[{\"type\":\"paragraph\", \"data\":\"\"}]}",
"name": "test1"
}
},
"operationName": "createCategory"
} The only difference between a successful and unsuccessful query were the fields that are equal to null. So I did another test and put all the variables that got passed with the unsuccessful one into the playground and tried. It failed, so doing "field":null seems to break queries. Is there a way around this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The #[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<&'a str>,
#[cynic(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Vec<MetadataInput<'a>>>,
#[cynic(skip_serializing_if = "Option::is_none")]
pub private_metadata: Option<Vec<MetadataInput<'a>>>,
} Can you see if that helps? It's possible that it's the |
Beta Was this translation helpful? Give feedback.
-
Works with skip_serializing_if, |
Beta Was this translation helpful? Give feedback.
The
InputObject
derive provides askip_serailizing_if
attribute that can help with this: