documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Component Relation Publication State needs to be set at each level

Open kasonde opened this issue 2 years ago • 6 comments

Bug report

Required System information

  • Node.js version: 14
  • NPM version: 6
  • Strapi version: 4.1.9
  • Database: SQLite
  • Operating system: MacOS Mojave

Describe the bug

Publication State isn't applied in component fields when making a graphql query.

Steps to reproduce the behavior

  1. Create Content Strucure as below: alloys
{
  "kind": "collectionType",
  "collectionName": "alloys",
  "info": {
    "singularName": "alloy",
    "pluralName": "alloys",
    "displayName": "alloy"
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "name": {
      "type": "string"
    },
    "tp_with_st": {
      "displayName": "tp_with_st",
      "type": "component",
      "repeatable": true,
      "component": "shared.tp-with-st"
    }
  }
}

st

{
  "kind": "collectionType",
  "collectionName": "sts",
  "info": {
    "singularName": "st",
    "pluralName": "sts",
    "displayName": "st"
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "name": {
      "type": "string"
    }
  }
}

tp

{
  "kind": "collectionType",
  "collectionName": "tps",
  "info": {
    "singularName": "tp",
    "pluralName": "tps",
    "displayName": "tp"
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "name": {
      "type": "string"
    }
  }
}

tp_with_st

{
  "collectionName": "components_shared_tp_with_sts",
  "info": {
    "displayName": "tp_with_st",
    "icon": "adjust",
    "description": ""
  },
  "options": {},
  "attributes": {
    "st": {
      "type": "relation",
      "relation": "oneToOne",
      "target": "api::st.st"
    },
    "tp": {
      "type": "relation",
      "relation": "oneToOne",
      "target": "api::tp.tp"
    }
  }
}

Make a GraphQL query, querying alloys and notice that the publication state of the one-to-one related elements on the component is not respected.

Expected behavior

For all element publication state to be respected.

Screenshots

image

kasonde avatar May 23 '22 14:05 kasonde

Hey, is the issue the fact that you've to add a publicationState: LIVE to the relation attributes too? If it's that, then it's the wanted behavior as we don't cascade this state to child resolvers.

Convly avatar May 30 '22 13:05 Convly

Hey, is the issue the fact that you've to add a publicationState: LIVE to the relation attributes too? If it's that, then it's the wanted behavior as we don't cascade this state to child resolvers.

Ah this is one of the undocumented changes from v3 where it ran globally.

derrickmehaffy avatar May 30 '22 14:05 derrickmehaffy

Indeed. In V3 we were sharing the state to child resolvers but it didn't really make sense in a GraphQL architecture where every resolver should be as isolated as possible. However, I do agree that from a product perspective it's a bit awkward to redefine this state for every relation, especially for content types where you have a lot of them. One solution could be to write a custom resolver :man_shrugging:

Sorry for the undocumented change, it must've been lost among all the other things :pray:

Convly avatar May 30 '22 14:05 Convly

No problem, I'll transfer this over to the documentation repo to have it added into the docs.

derrickmehaffy avatar May 31 '22 03:05 derrickmehaffy

  • The st and tp here are components
  • tp_with_st is another component
  • "alloys" is a collection with tp_with_st as a repeatable component
  • Even if publication state is passed as live, draft st and tp show up in the results for alloys

ghost avatar Jun 02 '22 09:06 ghost

It's been over a year and this issue is still a big problem and unsolved. Please fix it in future releases.

galago avatar Feb 02 '23 09:02 galago