Cms: GraphQl query entries from other site when "site" paramenter is defined

Created on 4 Aug 2020  Â·  3Comments  Â·  Source: craftcms/cms

Description

Whe referencing an Entry from a different site. GraphQl ist not able to resolve the entry when the site parameter is definend in the query. Sometimes we need to reference an entry that doesn't exist on the same site this is not possible at the moment.

Steps to reproduce

  1. Create a entry field with the option "Manage relations on a per-site basis"

Bildschirmfoto 2020-08-04 um 11 03 35

  1. Query it with the "site" parameter
{
 entry(site: 'en-US', id: 123) {
   myEntryField {
     id
   }
 }
}
  1. Recieve an empty array
bug

All 3 comments

GraphQL wraps around element queries and does not add any meaningful changes along the way, for what it's worth.

Can you reproduce the same problem with an element query in twig?

By default, relational fields will fetch elements in the same site as the source element, unless that “Relate entries from a specific site?” checkbox is ticked.

To get GraphQL (or an element query in Twig) to fetch the related entries in a different site, you need to pass a site param on the Entries field.

{
  entry(site: 'en-US', id: 123) {
    myEntryField(site:'other-site') {
      id
    }
  }
}

Or, if you don’t know which site the related entries will be defined in and just want them to be returned in _any_ site, set site to '*', and also set the unique param so you don’t get duplicate results.

{
  entry(site: 'en-US', id: 123) {
    myEntryField(site:'*', unique:true) {
      id
    }
  }
}

thx solved my issue

Was this page helpful?
0 / 5 - 0 ratings