Prisma 1 Forum

Filte returns wrong result in nested object

Hi!

I don’t know if I am doing something wrong or if it’s a bug. Hope someone can point me in the right direction.

schema.js:

type Query {
   tags(
     filter: TagFilterInput
   ): QueryTags
}

  type QueryTags {
    count: Int
    payload: [Tag!]!
  }

  type Tag {
    id: ID!
    title: String
    hotels: [Hotel!]
  }

  input TagFilterInput {
    title: String
    hotel_name: String
  }

  type Hotel {
    id: ID!
    name: String
  }

Query.js

  tags: async (
    parent,
    {  filter },
    { prisma },
    info
  ) => {
    const TAG_FILTER = {
      where: filter
        ? {
            title_contains: filter.title,
            hotels_some: {
              name_contains: filter.hotel_name
            }
          }
        : {}
    }

    const payload = await prisma.tags(TAG_FILTER)

    return {
      payload
    }
  }

If I now run the query in the prisma Playground I expect the result in payload to be only one record because I filter with title “Flipboard” and look for the one hotel with name “Hilton”
Instead it lists every hotel which is connected to this tag.

Playground:

query Tags {
  tags(
    filter: { title: "Flipboard", hotel_name: "Hilton" }
  ) {
    payload {
      id
      title
      countHotels
      hotels {
        id
        name
      }
    }
  }
}

Result:

{
  "data": {
    "tags": {
      "payload": [
        {
          "id": "ck0ghupwh00a5083781usr6p0",
          "title": "Flipboard",
          "countHotels": 2,
          "hotels": [
            {
              "id": "ck0ghyxao00ar0837kxyprrlj",
              "name": "Marriott"
            },
            {
              "id": "ck0ginqgg00c70837gcxqfl5s",
              "name": "Hilton"
            }
          ]
        }
      ]
    }
  }
}

I think there is something wrong or missing in my Query.js. I also played around with “hotel_every” and “name_contains” but nothing worked.

Why is prisma returning the “Marriott” object as well?

Thanks for your help guys!

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.