Skip to content

Properly recurse into :*: #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2018
Merged

Conversation

dminuoso
Copy link

@dminuoso dminuoso commented Apr 6, 2018

The old FromValue code makes the assumption that product types are always of the shape (a :*: (b :*: c)).
However GHC balances product and sum types (https://hackage.haskell.org/package/base-4.11.0.0/docs/GHC-Generics.html#g:9)

Resolves #173

@Akii
Copy link

Akii commented Apr 6, 2018

Can confirm this solves the issue. Thanks for fixing it!

@teh teh self-requested a review April 7, 2018 15:33
Copy link
Collaborator

@teh teh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good thank you!

Copy link
Collaborator

@jml jml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test that takes advantage of the fix in this code?

@Akii
Copy link

Akii commented Apr 10, 2018

data Resource = Resource
    { roleId      :: Text
    , resAge      :: Int32
    , resGender   :: Text
    , resLang     :: Text
    } deriving (Generic, Show)

instance FromValue Resource

Will that do? If the test compiles it "should" work. Can I write the actual test somehow?

@jml
Copy link
Collaborator

jml commented Apr 17, 2018

Yes, please add a test. It should use a resource definition like the one you provided and it should call fromValue on a JSON object and confirm that it's what you expect.

@Shou
Copy link
Contributor

Shou commented Jul 15, 2018

What's the status on this?

@jml
Copy link
Collaborator

jml commented Jul 16, 2018

This needs some kind of executable test before it can be merged. I've asked @dminuoso to do that, but they are a volunteer, so it's up to them when they do it. If you would like to create a new PR that includes the work of this one and adds the necessary tests, that would be very much appreciated.

@dminuoso
Copy link
Author

dminuoso commented Jul 16, 2018 via email

@teh teh merged commit f7ed7bb into haskell-graphql:master Aug 13, 2018
@EdmundsEcho
Copy link

EdmundsEcho commented Aug 19, 2018

I have FromValue being derived like a charm... Thank you for that! Should I expect this fix to include the ability to derive HasAnnotatedInputType for a record with more than 3 fields? I'm still getting an error.

data MixInputType = MixInputType
  { keyType    :: Text
  , keyName    :: Text
  , textValues :: Maybe [Text]
  , intValues  :: Maybe [Int32]
  , spanValues :: Maybe [SpanInputType]
  } deriving (Show, Generic)

instance FromValue Mix              <<< works using the commit referenced in the previous post
instance HasAnnotatedInputType Mix  <<< generates an error

I can avoid the error if I limit the number of fields to three.

@Gabriella439
Copy link

@EdmundsEcho: It looks like HasAnnotatedInputType has the same issue. It needs to be fixed in the same way as in this pull request since it was also written with the assumption that :*: constructors would form a linked list instead of a balanced binary tree

@dminuoso
Copy link
Author

Sorry, work stuff kept me too occupied. The issue with writing tests here is that I'd have to write generics for the other direction from scratch.

@Gabriel439 Do you have a testcase that I can use to validate my fix?

@Gabriella439
Copy link

@dminuoso: The following example fails to derive the HasAnnotatedInputType because the data type has four fields:

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric  #-}

import GHC.Generics (Generic)
import GraphQL.API (HasAnnotatedInputType)

data Example = Example
    { field0 :: Bool
    , field1 :: Bool
    , field2 :: Bool
    , field3 :: Bool
    } deriving (Generic, HasAnnotatedInputType)

... but if you remove one of the fields then the example works:

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric  #-}

import GHC.Generics (Generic)
import GraphQL.API (HasAnnotatedInputType)

data Example = Example
    { field0 :: Bool
    , field1 :: Bool
    , field2 :: Bool
    } deriving (Generic, HasAnnotatedInputType)

I tested those two examples using graphql-api-0.3.0

@dminuoso
Copy link
Author

Yeah it's all addressed by 5747b88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants