Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Relationship field crashes when referencing trashed posts as anonymous #167

@esamattis

Description

@esamattis

To reproduce

  • Create relationship field to a custom post type (might occur with buildin types too)
  • Create a page with some referenced posts
  • Move one of the referenced post to trash
  • Make an anonymous graphql query listing those posts
{
  page(idType: URI, id: "/test-page") {
    myFieldGroup {
      contacts {
        ... on Contact {
          title
          uri
        }
      }
    }
  }
}

Here's the myFieldGroup is an ACF field group and contacts is the custom post type.

When running this from the graphiql in wp-admin it works but when sending it as an anonymous query it errors with with:

Abstract type Page_MyFieldGroup_Contacts must resolve to an Object type at runtime for field Page_MyFieldGroup.contacts with value \"instance of WPGraphQL\\Model\\Post\", received \"null\". Either the Page_MyFieldGroup_Contacts type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.

My initial investigation leads here:

$relationship[] = $post_model;

The issue goes away if I add $post_object->post_status === 'publish' check for anonymous users before appending to the $relationship array but I'm not sure this is the right place to do it.

Thoughts?

I can also provide better reproduce steps with code if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions