haskell-graphql / graphql-api

Write type-safe GraphQL services in Haskell
BSD 3-Clause "New" or "Revised" License
406 stars 35 forks source link

How to parse JSON Response back to Haskell Type ? #190

Open revskill10 opened 6 years ago

revskill10 commented 6 years ago

Currently, Object doesn't have instance of fromJSON, so how can we convert back Response to Haskell Type from JSON Response ?

jml commented 6 years ago

You would have to write your own parser or submit one as a PR here.

revskill10 commented 6 years ago

@jml Any hint to do that ? Because the resulting response type seems arbitrary as a HashMap. My use case is to use with GHCJS.

jml commented 6 years ago

No, sorry. On Mon, 9 Jul 2018 at 06:46, Truong Hoang Dung notifications@github.com wrote:

@jml https://github.com/jml Any hint to do that ? Because the resulting response type seems arbitrary as a HashMap.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/haskell-graphql/graphql-api/issues/190#issuecomment-403366298, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHq6qvMQWX9RV9nL5lZVlaOi9CbwHnFks5uEu4YgaJpZM4VGjvd .

theobat commented 6 years ago

@checkraiser I'm currently writing a converter of a JSON object into a GraphQL haskell type given an existing schema. While my use case is for variables provided as a JSON map, and thus I'm only writing it for InputType, perhaps you'll be able to extend it to fit your use case.

revskill10 commented 6 years ago

@theobat Actually i think in this case, the nature of response result type consumed by client is too generic. To actually build up state on client side, we have to use something like aeson-lens to parse. I don't think if there's a better way that we could take advantage of Schema Type here (even in case you can convert into GrpahQL haskell type), you must do another conversion to base data types after all to use it to build client-side state.