wpengine / atlas-content-modeler

Content modeling plugin for WordPress
https://developers.wpengine.com/docs/atlas-content-modeler
GNU General Public License v2.0
165 stars 13 forks source link

Retrieving a content model by `idType: SLUG` returns `null` #310

Closed blakewilson closed 2 years ago

blakewilson commented 3 years ago

When querying a content model by id and idType as SLUG, the content model returns null.

To reproduce

  1. Create a content model
  2. Create a few posts in the CPT content model
  3. Query for a post by slug:
    query MyQuery {
      teamMember(id: "42", idType: SLUG) {
        id
        slug
      }
    }
  4. See a null response

Expected behavior

The response should include the post, as it would when using idType set to ID, DATABASE_ID, etc.

Screenshots

Screen Shot 2021-10-06 at 1 21 38 PM

Screen Shot 2021-10-06 at 1 21 45 PM

Version information

mindctrl commented 3 years ago

This appears to be caused by the fact that we don't register post types as public. Trying publicly_queryable set to true, while public still being false, does not fix it. Seems like we might be forced to register with public => true for this query type to work.

mindctrl commented 3 years ago

As a test, commenting out this line in WPGraphQL makes the query work:

https://github.com/wp-graphql/wp-graphql/blob/24d00d1c428b9ef933d167edab61652f6f4a48d6/src/Data/NodeResolver.php#L390

I wonder what the reasoning is for WPGraphQL to check for public + show_in_graphql. Is the latter not sufficient? If not, is there a chance of changing that to publicly_queryable instead? Just looking at all our options here. cc @jasonbahl

jasonbahl commented 3 years ago

Is the post type hierarchical?

If so, slug should not be an identifier for the type, because you can have multiple entries of the same post type with the same slug.

For example, you could have:

All with a slug of john but a uri of:


That said, I do think @mindctrl has pointed out a bug with WPGraphQL🤔

I believe I've not encountered the bug, because post types I've tested with have all been public!

I think we can get rid of the public => true arg here

nickcernis commented 3 years ago

This appears to be caused by the fact that we don't register post types as public.

Related: https://github.com/wpengine/atlas-content-modeler/issues/290.

ChrisWiegman commented 3 years ago

@jasonbahl , I've opened up https://github.com/wp-graphql/wp-graphql/pull/2132 per the feedback above to address.

mindctrl commented 2 years ago

This was fixed in https://github.com/wp-graphql/wp-graphql/pull/2132

image