brandonchinn178 / aeson-schemas

Easily consume JSON data on-demand with type-safety
http://hackage.haskell.org/package/aeson-schemas
BSD 3-Clause "New" or "Revised" License
52 stars 1 forks source link

Make version of mkGetter with polymorphic input #80

Open brandon-leapyear opened 2 years ago

brandon-leapyear commented 2 years ago
mkGetter' "Node" "getNodes" ".nodes[]"

should work for any object with a nodes key.

Could be implemented with a helper that generates the type of the input of

[get| .foo[].bar |]

e.g.

getFoo :: [has| .foo[].bar |] ->

Specifically,

getFoo :: [has| .s |] -> [unwrap| MySchema.s |]
getFoo = [get| .s |]

should be valid for any schema MySchema and any query path s

Currently workaround-able with

getFoo ::
  ( s1 ~ LookupSchema "a" schema
  , Maybe (Object r1) ~ SchemaResult s1
  , s2 ~ LookupSchema "b" r1
  , [Object r2] ~ SchemaResult s2
  , s3 ~ LookupSchema "c" r2
  , Int ~ SchemaResult s3
  , Typeable s1
  , Typeable s2
  , Typeable s3
  , Typeable r1
  , Typeable r2
  ) =>
  Object schema ->
  [Int]
getFoo = [get| .a!.b[].c |]

Possibly related to #2