Giter Site home page Giter Site logo

Comments (6)

mattfaluotico avatar mattfaluotico commented on July 3, 2024 1

Could the JSON deserialization be optional? It's safe to ship with, but it would be nice to have some sort of plug allowing someone to continue using their own deserialization method.

from apollo-ios.

martijnwalraven avatar martijnwalraven commented on July 3, 2024 1

The issue with this is that strictly taken the type system is defined by GraphQL, and JSON is just one serialization format. What that means in practice is that there are GraphQL-specific features that existing JSON mappers don't necessarily support well.

For instance, a GraphQL enum value would be serialized as a JSON string, but as a client you expect an actual enum of the right type to be returned. There are also issues around the handling of optional values. And things quickly get more complicated when you take more advanced GraphQL features into account, like polymorphic results, where a __typename field decides what the actual type returned is.

If you're interested, you'll find some more details of the proposed mappings in the design docs.

There are probably things that could be be improved about the current implementation of JSON parsing and the resulting mapping, but I feel having this be part of the project offers us more flexibility and is worth the overhead. If we find a good use case for pluggable serialization formats, we can take it from there.

from apollo-ios.

stubailo avatar stubailo commented on July 3, 2024

Would it make sense to remove JSON Parsing at all to concentrate on GraphQL.

Doesn't GraphQL return results in JSON? What would a GraphQL client without JSON parsing do?

from apollo-ios.

lightsprint09 avatar lightsprint09 commented on July 3, 2024

It does. But what if your implementation returns as Dictionary<String, Any> as result. The Consumer of the can then decide how to parse it. If I find time tomorrow I will add a little example here

from apollo-ios.

lightsprint09 avatar lightsprint09 commented on July 3, 2024

You only would definde some kind of JSON protocol and the consumer of your API has to implement it.

This library could concentate on a great GraphQL implementation and not try to solve JSONMapping

protocol JSONInitializable {
  init(map: Dictionary<String, Any>) throws
}
public protocol GraphQLQuery {
  var operationDefinition: String { get }
  var queryDocument: String { get }
  var variables: GraphQLMap? { get }

  associatedtype Data: JSONInitializable
}

from apollo-ios.

lightsprint09 avatar lightsprint09 commented on July 3, 2024

I like the idea from @Mattfxyz. But this would not remove the overhead of implementing a JSON mapper.

from apollo-ios.

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.