Skip to content

How to construct a complex Object from Record? #217

@Benjmhart

Description

@Benjmhart

I can't seem to construct a multi-field argument without several errors: Here's what I have so far:

type QuoteGQL = GQLAPI.Object "QuoteGQL" '[]
  '[ GQLAPI.Argument "symbol" Text :> GQLAPI.Field "globalQuote" QuoteR ]

type QuoteR =  GQLAPI.Object "QuoteR" '[] 
  '[ GQLAPI.Field  "symbol"           Text
   , GQLAPI.Field  "open"             Text
   , GQLAPI.Field  "high"             Text
   , GQLAPI.Field  "low"              Text
   , GQLAPI.Field  "price"            Text
   , GQLAPI.Field  "volume"           Text
   , GQLAPI.Field  "latestTradingDay" Text
   , GQLAPI.Field  "previousClose"    Text
   , GQLAPI.Field  "change"           Text
   , GQLAPI.Field  "changePercent"    Text
  ]

data QuoteRecord = QuoteRecord  { symbol              :: Text
                                , open                :: Text
                                , high                :: Text
                                , low                 :: Text
                                , price               :: Text
                                , volume              :: Text
                                , latestTradingDay    :: Text
                                , previousClose       :: Text
                                , change              :: Text
                                , changePercent       :: Text
                                } deriving (Eq, Show, Generic)

makeQuoteR :: QuoteRecord -> Maybe QuoteR
makeQuoteR qr = GQLV.objectFromList 
  [ ( "symbol",           TV.toValue $ symbol qr)
  , ( "open",             TV.toValue $ open qr) 
  , ( "high",             TV.toValue $ high qr) 
  , ( "low",              TV.toValue $ low qr) 
  , ( "price",            TV.toValue $ price qr) 
  , ( "volume",           TV.toValue $ volume qr) 
  , ( "latestTradingDay", TV.toValue $ latestTradingDay qr) 
  , ( "previousClose",    TV.toValue $ previousClose qr) 
  , ( "change",           TV.toValue $ change qr) 
  , ( "changePercent",    TV.toValue $ changePercent qr) 
  ]

makeQuoteGQL is failing to typeCheck with
Expected type: Maybe QuoteR
Actual type: Maybe (GQLV.Object' GQLV.ConstScalar)

How on Earth can I construct a QuoteR - I need to use the record type as an intermediary because GQLAPI.Object does not implement FromJSON

what am I missing for these more complex types?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions