0

I have a this graphql query on hasura

query MyQuery {
  events(where: {event_id: {_eq: "6b1a8373"}}) {
    checkins {
      checkpoint {
        name
      }
      created_at
      user {
        email
        first_name
        last_name
      }
    }
  }
}

but it returns duplicate items for some entries. What could be causing the problem? How can I fix it?

This is what is being returned

{
  "data": {
    "events": [
      {
        "checkins": [
          {
            "checkpoint": {
              "name": "Vaccari Italian Restaurant"
            }
          },
          {
            "checkpoint": {
              "name": "Vaccari Italian Restaurant"
            }
          },
          {
            "checkpoint": {
              "name": "Silver Lake Pool & Inn"
            }
          },
          {
            "checkpoint": {
              "name": "Silver Lake Pool & Inn"
            }
          },
          {
            "checkpoint": {
              "name": "USC Hotel"
            }
          },
          {
            "checkpoint": {
              "name": "Vaccari Italian Restaurant"
            }
          },
          {
            "checkpoint": {
              "name": "Vaccari Italian Restaurant"
            }
          }
        ]
      }
    ]
  }
}

There should only be 2 "Vaccari Italian Restaurant" and 2 "Silver Lake Pool & Inn"

Natnael
  • 59
  • 12
  • Can you provide a sanitized example response? – Jared Beekman Jul 23 '21 at 15:32
  • Take a look at database level. What will return on `SELECT * from events E JOIN checkins C ON [what defined in array relationships]` ? – Alex Yu Jul 25 '21 at 08:21
  • At the database level, it returns the expected result. The Hasura graphql query is what' returning the duplicates. – Natnael Jul 28 '21 at 14:32
  • Can you post the generated SQL for the above query? – praveenweb Jul 29 '21 at 08:21
  • 1
    I think I found the problem, there was an array relationship, when it should have been an object relationship. I think that's what was causing the issue. Thanks for the help everyone. – Natnael Jul 30 '21 at 14:01
  • 1
    @phatnael - Can you add the solution and mark it as answered to make it easy for anyone in the future? – praveenweb Aug 12 '21 at 11:23

1 Answers1

0

The problem was when I was defining my relationships I created an array relationship where it should have been an object relationship. Once I changed it to object relationship, it is working properly as intended.

Natnael
  • 59
  • 12