Comments (6)
I think this would be a great addition.
Would validateResponseStructure
just return a bool
? Or would it give some hints as to where the mismatched data is?
If a bool
is sufficient, we could integrate validation into normalizeNode
and denormalizeNode
by default. Then we wouldn't need a separate validation method. We could just wrap writeQuery
and readQuery
in a try / catch and catch validation exceptions.
from ferry.
Just throwing an exception is sufficient for now – eventually surfacing mismatched paths could be a goal but we can add that to the exception details later as well
from ferry.
After thinking about this further, without having access to the schema, we'd really only be able to validate whether the data should be a Map (i.e. the node has a SelectionSet) or a scalar (i.e. the node doesn't have a SelectionSet), and I'm not sure how useful this would be.
So we could either:
- include the schema as an optional parameter to the normalize functions, and if one is provided, perform a more thorough validation
- implement validation as a separate function
How do you envision this being used? Would it be called directly by the user? Or are you incorporating validation into the graphql
client automatically?
from ferry.
@smkhalsa we can tell from the document
which fields the Map
should have right? Because denormalize has to select the fields. That's mainly what I'm after, is just to validate that the structure is valid given the operation document.
This came up because for whatever reason a user's result.data
was unexpectedly null
and they had no idea why. So like, if a server responds to { foo, bar }
with { foo: 1 }
, denormalizeOperation(document, data)
will return null
from ferry.
@micimize ah, ok.
The way that the denormalize functions work is that if a Map doesn't contain a key for a given FieldNode in the document (e.g. "bar" in your example above), the denormalizeNode
function throws a PartialDataException
. If returnPartialData
is set to true
, the exception is caught and ignored and the partial data is returned. If returnPartialData
is set to false
, the exception is caught and null
is returned for the entire operation.
By default returnPartialData
is set to false
since:
- non-nullable fields could potentially return null data
- we may want to fetch from the network if all the data is not available for the operation (e.g. FetchPolicy.CacheFirst)
It sounds like in the case you describe above, if they want to receive partial data, they should be able to just set returnPartialData
to true
.
from ferry.
closed by #104
from ferry.
Related Issues (20)
- Missing scalar JSON. Defaulting to String HOT 10
- Upgrade to gql 1.0 HOT 1
- Verbose, duplicated CHANGELOGS
- Cache not updated after adding paginated data through updateResult with ferry HOT 4
- Could `FieldPolicy` and `TypePolicy` have a const constructor? HOT 1
- Add a way to generate classes for some types in the schema HOT 6
- Feature Request: Ability to generate to non-`lib/` directory HOT 3
- [FerryGenerator]How to make it work within a monorepo? HOT 5
- Unable to use types directly with conditional fragment spreading HOT 2
- FIle Upload error HOT 2
- More detailed documentation. HOT 4
- [FerryGenerator] Query generator adds all types as document nodes HOT 2
- [FerryGenerator] Why isn't my basic schema working? HOT 2
- Only one document node is created for many queries and mutations HOT 1
- [normalize] Weird writeFragment behaviour when used with an interface fragment
- Set Ferry as a replacement for Artemis HOT 6
- [question] Is the header of a request cached? HOT 4
- Conditional fragment spreading in a fragment HOT 5
- readFragment returns null if it contains variable object
- operationRequest generated on initial request being included in response each time, when using IsolateClient
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 ferry.