Skip to content

[4.x]: Querying entries with GraphQL in a multi-site setup returns incorrect results with translated category fields from other sites. #12740

@samput

Description

@samput

What happened?

Description

When using GraphQL and a multi-site setup, querying entries for a specific site and category returns incorrect results. The returned entries have translated category field associations that belong to other sites.

Steps to reproduce

1. Muti-site setup

I have a multi-site setup, one for each 'market' US, and UK structured like below.

[
  {
    name: 'Site 1',
    handle: 'us',
    language: 'en-GB',
    group: 'Group 1'
  },
  {
    name: 'Site 2',
    handle: 'uk',
    language: 'en-GB',
    group: 'Group 1'
  }
]

2. Create platform categories

[
  {
      "id": 1,
      "title": "Platform 1",
      "slug": "platform1"
    },
  {
      "id": 2,
      "title": "Platform 2",
      "slug": "platform2"
    },
]

3. Create a new section named content.

4. Create one entry and 'translate' the platform category for each market.

US associate Platform 1 category

{
  "id": 3,
  "title": "Entry 1",
  "slug": "entry1",
  "platform": [
    {
      "id": 1,
      "title": "Platform 1",
      "slug": "platform1"
    },
  ]
}

UK associate Platform 2 category

{
  "id": 3,
  "title": "Entry 1",
  "slug": "entry1",
  "platform": [
    {
      "id": 2,
      "title": "Platform 2",
      "slug": "platform2"
    },
  ]
}

5. Query entires that belong to site 'us' and Platform 2

query ListEntries {
  entries(
    site: "us",
    section: "content",
    platform: "2",
  ) {
    siteHandle
    id
    title
    slug
    ...on content_default_Entry {
      platform {
        id
        title
        slug
      }
    }
  }
}

Expected behavior

The expected behaviour is that when querying entries that belong to site 'us' and Platform 2 the result should be empty as there are no entries that meets that criteria.

{
  "data": {
    "entries": []
  }
}

Actual behavior

The actual behaviour is that even though the query is for a specific category that does not exist for a particular entry and site, the returned entries contain incorrect 'platform' categories that are associated with other sites / translation.

Returns result with incorrect 'Platform 1', even though query was for 'Platform 2'.

Seems to be querying all categories for all sites, even if that category is not associated with that entry for that particular site.

{
  "data": {
    "entries": [
      {
        "siteHandle": "us",
        "id": 3,
        "title": "Entry 1",
        "slug": "entry1",
        "platform": [
          {
            "id": 1,
            "title": "Platform 1",
            "slug": "platform1"
          }
        ]
      }
    ]
  }
}

Craft CMS version

Craft Pro 4.3.10

PHP version

8.1.11

Operating system and version

macOS Montery 12.6.3

Database type and version

MySQL 5.7.38

Image driver and version

Imagick 3.6.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

Amazon S3 | 2.0.1
Feed Me | 5.0.5
KeyChain | 4.0.0
Notifications | 4.1.2
Redactor | 3.0.3
SAML Service Provider 4.0.5

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions