Git Product home page Git Product logo

Comments (6)

smkhalsa avatar smkhalsa commented on May 17, 2024

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.

micimize avatar micimize commented on May 17, 2024

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.

smkhalsa avatar smkhalsa commented on May 17, 2024

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:

  1. include the schema as an optional parameter to the normalize functions, and if one is provided, perform a more thorough validation
  2. 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.

micimize avatar micimize commented on May 17, 2024

@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.

smkhalsa avatar smkhalsa commented on May 17, 2024

@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:

  1. non-nullable fields could potentially return null data
  2. 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.

smkhalsa avatar smkhalsa commented on May 17, 2024

closed by #104

from ferry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.