statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.08k stars 533 forks source link

GraphQL schema for multiple collections with Bard+Sets is invalid #5211

Open dmgawel opened 2 years ago

dmgawel commented 2 years ago

Bug description

When there is more than one collection that has a Bard field with Sets, the generated GraphQL schema is invalid. List of possible Sets from one of the Bard fields is used for all other collections.

How to reproduce

  1. Create two collections, "aaa" and "bbb".
  2. Add a Bard field named content to both of them.
  3. Add different sets to the content field for both collections and add sample fields (can be text type) inside sets
  4. Visit GraphiQL Explorer and try to fetch entries including content field on both Entry_Aaa_Aaa and Entry_Bbb_Bbb. You'll see that sets for Entry_Bbb_Bbb are used for Entry_Aaa_Aaa as well (could be the other way, I'm not sure what the rule is here, but looks like it's alphabetical).

Logs

No response

Versions

Statamic 3.2.32 Pro Laravel 8.82.0 PHP 8.0.15 No addons installed

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

jasonvarga commented 2 years ago

The types get created as Set_BardFieldHandle_SetFieldHandle.

Looks to me like you get only the sets for the first field Bard that Statamic encounters, if they're named the same.

A workaround for now is to name your fields differently across collections.

dmgawel commented 2 years ago

Thanks @jasonvarga 🙇‍♂️ I've renamed a Bard field in a second collection to content2 and schema generation works again. That will do as a workaround, I'll leave the issue open for a more generic solution (that will allow us to give a content name to all Bard fields across collections).

panr commented 2 years ago

Hey, any chance to fix it anytime soon? We are using the workaround from @jasonvarga comment, but sometimes it's easy to forget about it ;-)

lotarbo commented 1 year ago

still same problem, we use block content system for all collections, so its very strange to have different field name for this

ps this issue not only for bard, we use replicator field

buffalom commented 1 year ago

I would like to have a go at fixing this, but I need your help on how to approach it.

Presumably just adding the blueprint's handle to the type is not the way to go as this would not solve the issue for nested bards/replicators and it would be a breaking change.

Do you have any idea how you would like this to be solved?

jasonvarga commented 1 year ago

An idea for a potential solution. Maybe we can have a config setting on the field that lets you give a custom GraphQL handle to the field to make it more unique across collections.