haskell-graphql / graphql-api

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

Simplify GenericInputObjectFieldDefinitions #195

Closed Shou closed 6 years ago

Shou commented 6 years ago

We simplify GenericInputObjectFieldDefinitions by using tree-recursion, resulting in better error messages. Example code to reproduce below, where the 'true' error is usage of lists.

data family Test :: Nat -> Type
data instance Test 1 = Test
  { testField1 :: Int32
  , testField2 :: Text
  , testField3 :: Text
  , testField4 :: [Int32]
  } deriving (Show, Generic)
instance HasAnnotatedInputType Test

Before

        • No instance for (GraphQL.Internal.API.GenericInputObjectFieldDefinitions
                             ((S1
                                 ('MetaSel
                                    ('Just "testField1")
                                    'NoSourceUnpackedness
                                    'NoSourceStrictness
                                    'DecidedLazy)
                                 (Rec0 Int32)
                               :*: S1
                                     ('MetaSel
                                        ('Just "testField2")
                                        'NoSourceUnpackedness
                                        'NoSourceStrictness
                                        'DecidedLazy)
                                     (Rec0 Text))
                              :*: (S1
                                     ('MetaSel
                                        ('Just "testField3")
                                        'NoSourceUnpackedness
                                        'NoSourceStrictness
                                        'DecidedLazy)
                                     (Rec0 Text)
                                   :*: S1
                                         ('MetaSel
                                            ('Just "testField4")
                                            'NoSourceUnpackedness
                                            'NoSourceStrictness
                                            'DecidedLazy)
                                         (Rec0 [Int32]))))
            arising from a use of ‘GraphQL.Internal.API.$dmgetAnnotatedInputType’
        • In the expression:
            GraphQL.Internal.API.$dmgetAnnotatedInputType @(Test 1)
          In an equation for ‘QL.getAnnotatedInputType’:
              QL.getAnnotatedInputType
                = GraphQL.Internal.API.$dmgetAnnotatedInputType @(Test 1)
          In the instance declaration for ‘QL.HasAnnotatedInputType (Test 1)’
       |
    72 | instance QL.HasAnnotatedInputType (Test 1)
       |

After

    • No instance for (QL.HasAnnotatedInputType [Int32])
      arising from a use of ‘GraphQL.Internal.API.$dmgetAnnotatedInputType’
    • In the expression:
        GraphQL.Internal.API.$dmgetAnnotatedInputType @(Test 1)
      In an equation for ‘QL.getAnnotatedInputType’:
          QL.getAnnotatedInputType
            = GraphQL.Internal.API.$dmgetAnnotatedInputType @(Test 1)
      In the instance declaration for ‘QL.HasAnnotatedInputType (Test 1)’
    |
72  | instance QL.HasAnnotatedInputType (Test 1)
    |
jml commented 6 years ago

Thanks for the PR. The test failure is due to our coverage ratchet. Because you improve the test coverage (yay!), you need to update the COVERAGE_TOLERANCE dict in scripts/hpc-ratchet to have the new values.

Shou commented 6 years ago

Done! Tests are looking good now.

Shou commented 6 years ago

@jml anything else I can do to get the PR merged?

jml commented 6 years ago

All good. Sorry for the delay.