0

Assume we're consuming an API that we don't control. That API returns an array of mapped currency / price pairs like this:

[{"GBP":1.092},{"USD":0.878977}]

How can this be modelled in a GraphQL schema?

Note: the format in which this data arrives on the client is not important. e.g. it could be something like:

[
  {
    "currency": "GBP",
    "value": 1.092
  },
  {
    "currency": "USD",
    "value": 0.878977
  }

]
Chris Sargent
  • 321
  • 2
  • 13
  • FYI, I have read this entire thread and not seen any clear answer: https://github.com/graphql/graphql-spec/issues/101 – Chris Sargent May 29 '20 at 10:02
  • flatten it to a single 'record' type `{ currencyOneName, currencyOneRatio, currencyTwoName, currencyTwoRatio }` ... or use **customJSON type** and use simplest object, currency as key: `{ "GBP":1.092, "USD":0.878977 }` ... add `id` (date/typestamp) (for cache) ... depends on further processing requirements – xadm May 29 '20 at 10:24
  • You mean like, `type Pairs {GBP: Float USD: Float}`? Yes, that would work in this case but unfortunately the currency pairs was just an example and in reality the currency name is actually a uuid (i.e. completely unknown ahead of time) – Chris Sargent May 29 '20 at 12:18
  • my samples was not hardcoded - both currencyOneName and keys in custom JSON can be anything/dynamic string – xadm May 29 '20 at 12:25
  • Okay, then I'm not sure I understand what you mean then, sorry. Can you expand at all please? – Chris Sargent May 29 '20 at 15:38
  • And yeah, question was closed as a dupe - which is fair. As far as I can tell you can just use the `JSON` type which works. Or, as in my case I'm using AWS Appsync, they have an `AWSJSON` type. – Chris Sargent May 29 '20 at 15:43

0 Answers0