0

I have a query that looks like this:

    query ($email: String!) {
      users(where: {email: {_eq: $email}}, limit: 1) {
        id
        email
        name
        clients {
          id
        }
      }
    }

and when executed returns something like this:

{
  "data": {
    "users": [
      {
        "id": 2,
        "email": "abc@gmail.com",
        "name": "Billy",
        "clients": [
          {
            "id": 1
          },
          {
            "id": 2
          },
          {
            "id": 3
          }
        ]
      }
    ]
  }
}

Is there a way to modify the query and/or hasura so that the clients array is an array of numbers instead of an array of objects so it looks like this (clients is another table not a jsonb field)?

{
  "data": {
    "users": [
      {
        "id": 2,
        "email": "abc@gmail.com",
        "name": "Billy",
        "clients": [1, 2, 3]
      }
    ]
  }
}
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
  • if it is a part of object/type (and can contain other fields) then of course not ... as returning only array of numbers doesn't return declared type for this prop ... you can extract/modify it after receiving – xadm Dec 22 '20 at 17:54
  • I assumed I would have to modify it after receiving it. I wasn't sure if there was a way to map it on hasura or not... – Get Off My Lawn Dec 22 '20 at 17:59
  • for single prop you can have f.e. some 'format' param on string type field to receive plain text or rendered/html ... and in theory you can define type as an array of some union type elements (int or Client) it could be possible to return it both ways conditionally (with resolver support of course) – xadm Dec 22 '20 at 19:03
  • I would do that in postgresql with ARRAY_AGG/JSONB_AGG. I'm not aware of possibilities to do that on graphql level. – Alex Yu Dec 23 '20 at 22:54
  • 1
    Okay, Thanks everyone for the feedback. I will just create the array via javascript. – Get Off My Lawn Dec 26 '20 at 17:06

0 Answers0