-
-
Notifications
You must be signed in to change notification settings - Fork 121
[Feature Request] Ignore null arguments #178
Comments
Hi. Could you add a little bit reasoning behind this feature? |
There are two reasons:
|
Thanks. |
@thanhbinh84 @vasilich6107 targets:
$default:
builders:
# Some of our queries fail when we send null keys
# (foo)
json_serializable:
options:
include_if_null: false Maybe this solves for you? The downside is that it applies to your whole project, so if your backend relies on specifically receiving |
Hello there, how are you doing? |
Thanks for your info. @Grohden's solution works, we don't need to update our lib then. Cheers. |
@comigor @thanhbinh84 I don't think that solves the issue completely. input User {
id: String!
firstName: String
lastName: String
companyID: String
} Now I want to update the firstName and remove them from a company, I would send a mutation like: mutation updateUser {
id: "myUserID"
firstName: "Alice"
# lastName is not included because I don't want to update it
companyID: null
} How can I do that? |
@GP4cK I haven't tried but passing empty string "" might help, as json serializable will bypass null but keep empty string. |
Ok so then it will be the responsibility of the server to convert the empty string to null if it's a foreign key. That's a workaround. |
@GP4cK Just an idea: you could create a scalar (something like Also, there's... a trick you could use input User {
id: String!
firstName: String
lastName: String
companyID: [String]
} A list ( Of course, this is a hack (which I may remember from list and maybe being monads (?)🤔) and probably will end up introducing more problems.. Anyway, I think that the only way to actually solve this is to have artemis processing a gql directive (maybe configurable on build.yaml) and then generating the json_serializable class with the include_if_null flag based on that directive |
I understand your use cases and, although not spec-compliant, it seems better to have some configuration than sourcing to these kind of "hacks". I'll think about something. |
Maybe we could use something like the Extract from their doc:
The source code is here |
@comigor do you have any update on this? I'd be happy to help develop this if you tell him how you want it to be implemented. |
@GP4cK I didn't have time to look at this yet. I understand your use case, but as it's not spec-compliant, it makes things harder. It seems that to solve your problem, we'd have to remove all nulls but a few selected fields when converting to json, right? In this case, we'd have to mark all fields with includeIfNull: false, and allow to configure which fields to mark as true. Still a hacky solution, but without need to change the backend would be to create a new option on artemis, named something like targets:
"$default":
builders:
artemis:
options:
allow_null_on_fields:
- User:
- companyID When this configuration is not null, like I said, all fields would be marked with |
Maybe I'm misunderstanding, but it seems to be saying that it's totally valid for the server to interpret these two differently and cites the exact use case discussed in this thread (emphasis mine):
Is it really out of spec for the server to treat omitted arguments and null arguments differently? |
How about wrapping nullable field types with a simple class? Take apollo-android for an example: If a field is nullable, it's generated type will would be |
@cody1024d i tried to implement this feature - see the #339 |
@vasilich6107 I'm not sure ignoring all nulls would be the best policy. I think something like the suggestion by @Luke265 would be best. Somehow generating a small wrapper class around the optional values in the schema, which then play a part in the serialization. Going to ask the rest of my team, but I may spend some time working on this proposed solution as it's going to be a blocker for us either way |
@cody1024d if you check the PR there is an optional value so it will remove only non setted values |
Some news about the explicit null? final notDonationsQuery = ProductForCatalogQuery(
variables: ProductForCatalogArguments(
where: ProductWhereInput(
price: FloatNullableFilter(not: *******ExplicityNull()*******),
),
take: 15,
orderBy: [ProductOrderByWithRelationInput(id: SortOrder.asc)]),
); Another question, do you know if "ferry" package for flutter has this problem too? Very thanks. |
I solved a similar issue - filtering nullable fields from some specific entities - by extending the RequestSerializer. I use as backend HotChocolate v12, and it wants no null fields in FilterInput & SortInput entities |
I think this should be changed from "enhancement" to "bug" |
any update? |
Steps to reproduce:
Expected
Generate graphql without birthday:
Actual
Generate graphql with null birthday:
Specs
Artemis version: ^6.0.4-beta.1
build.yaml:
Artemis output:
GraphQL schema:
GraphQL query:
The text was updated successfully, but these errors were encountered: