Comments (2)
Hi @gscalzo - I understand your request and I get that this behaviour is making the transition to Apollo iOS more difficult than it needs to be. As stated in the other issue, the fact remains that Apollo iOS is a spec-compliant GraphQL client.
They highlighted that Apollo Kotlin has functioned without this need for years
There will always be nuanced differences between clients and simply because they are from the same organization does not mean every facet of behaviour is the same. Formal specifications exist to minimize this.
@martinbonnin, @BoD - do you have a definitive answer on why the difference in behaviour is allowed?
and pointed out that the referenced specification is still in draft, making adherence somewhat ambiguous.
I linked to the draft spec because it is the most recent and up-to-date version of the specification. Yes it contains new behaviour that is not yet part of an official dated release but null response field values is not one of those. The very first released specification back in July 2015 stated "If result is null or a value similar to null such as undefined or NaN, return null."; this has been defined field response behaviour for 8 years now.
However, I noted in @AnthonyMDev's PR (#2897) the introduction of
HandleMissingValues
, particularly theallowForOptionalFields
option, which would resolve our issue. The challenge is thatGraphQLSelectionSetMapper
is instantiated with.disallow
as the default, and there's no current method to alter this from the client code.Could this policy be accessible to the caller's code, possibly as a parameter in the
ApolloStore
class? This approach would maintain the existing and default behaviour while allowing users who need to handle omitted null values the flexibility to set this policy. What do you think about this?
Not allowing missing fields is a piece of the overall design that extends further than just GraphQLSelectionSetMapper
. If you were to allow missing fields in the response you're then out of sync with the behaviour of the cache which is also does not expect missing fields; there are other parts of Apollo iOS built on this premise too. A change like this is more complicated to keep everything working together than simply exposing the ability to control HandleMissingValues
.
This isn't behaviour that we'll change in Apollo iOS but you are always able to fork the repo, adapt it to your specific needs and maintain it yourself. I also do not believe this is a change we would accept back into the main repo either.
from apollo-ios.
@martinbonnin, @BoD - do you have a definitive answer on why the difference in behaviour is allowed?
AFAIK, this is out of practical reasons mainly. The JSON parsers use the following pseudo code:
var field: Int? = null
while (jsonReader.hasNext()) {
when (jsonReader.nextName()) {
"field" -> field = jsonReader.nextInt()
}
}
return Data(field)
So it saves a bunch of generated code and hasn't been an issue so far but it's definitely not allowed by the spec.
Actually now that I think about it, it breaks a small optimization we have because the order of fields in the JSON is deterministic, nextName()
skips a few strcmp
because it knows in advance what to expect. If a field is missing, we have to fallback to scanning all possible names.
So not great and should probably fixed on the server indeed. I'm actually surprised DGS allows this. It's probably worth filing a bug there.
from apollo-ios.
Related Issues (20)
- Uploading files with apollo HOT 4
- Crash Thread 1: Fatal error: No data found for task 1, cannot append received data HOT 6
- Use ApolloClient with swift-corelibs-foundation 5.10.1 HOT 5
- RFC: 2.0 API Changes - Swift Concurrency HOT 19
- Add support for local cache mutations HOT 2
- Pagination: Errors on initial page not reported HOT 5
- CacheKeyInfo with a numeric jsonValue of `1` returns nil HOT 4
- Type 'Operation' has no member 'deferredSelectionSetType' in IncrementalGraphQLResponse HOT 2
- Feature Request: Async RequestBodyCreator for Async Auth Payload Retrieval HOT 3
- 1.14.0 using introspection creates duplicate defer directive HOT 22
- Pagination: support cache policy for initial fetch HOT 1
- codegen: Add an option to capitalize acronyms when the first character is capitalized HOT 4
- Error handling for CacheWriteInterceptor added in 1.14.0 causing issues HOT 2
- Swift Package Manager Apollo Web Socket Not Working HOT 2
- Cache migrations HOT 2
- Generated code cannot compile when using include directive on field that is selected on interface and implementation HOT 3
- apollo-ios-xcframework doesn't add bundle identifier to the Info.plist for the created xcframework HOT 2
- Codegen: Merging entity into same type with inclusion condition does not build
- make build-apollo-xc-framework fail with Error 70 HOT 9
- Setter for local cache mutation is unavailable, mutate properties of fragment HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-ios.