Eduard Boloș
02/26/2025, 3:08 PMBy default, the GraphQL spec treats nullable variables as optional, so it's valid to omit them at runtime. In practice, however, this is rarely used and makes the operation's declaration verbose.I am not sure that the "so it's valid to omit them at runtime" is actually true. Looking at the linked spec, if hasValue is is not true, and defaultValue doesn't exist, there's no value coercion happening. Which will lead to an error – that's exactly what we are experiencing with our Python server that uses Strawberry. Instead, what we are seeing is that we can omit the nullable variable only if there is a default value defined for it in the schema, which is not clear in Apollo's documentation. Am I making sense? 😄
mbonnin
02/26/2025, 3:58 PMmbonnin
02/26/2025, 3:59 PMmbonnin
02/26/2025, 3:59 PMmbonnin
02/26/2025, 4:02 PMtype Mutation {
// Modifies the user name and returns the new name
modifyUser(name: String): String
}
mbonnin
02/26/2025, 4:07 PMmutation ChangeUserName($name: String) {
modifyUser(name: $name)
}
mbonnin
02/26/2025, 4:08 PMname
in your variablesmbonnin
02/26/2025, 4:30 PMundefined
and can decide what to do. Most probably, it will just leave the user name unchangedEduard Boloș
02/26/2025, 5:27 PMTypeError: mutate_foo() missing 1 required positional argument: 'argName'We can easily avoid this on our part with a linter rule to require a default value on all nullable variables, but this was surprising and seems to be a mismatch somewhere between the expectation and reality 😄 So I thought of flagging it, as the docs seemed confusing. But it's also the page for migration to the old V3, so not sure if it's worth updating it now, although this was the only place in the documentation I could find anything being discussed on the topic.
mbonnin
02/26/2025, 6:03 PMundefined
mbonnin
02/26/2025, 6:03 PMStylianos Gakis
02/26/2025, 6:51 PMeditUser
and takes in a name
and lastName
as parameters.
Let's say name
is a nullable String
Omitting the value means don't change it at all
Sending null means make the name be null
Sending not null means set the name to the input
So if your server doesn't support this functionality, it feels like the server is the one at fault here, right?Eduard Boloș
02/27/2025, 10:00 AM