silverstripe/silverstripe-graphql

[v4] Using the bulk loader breaks page polymorphism

bummzack opened this issue · 3 comments

Let's say that I have a Page and a CustomPage class:

Page:
  fields:
    id: true
    title: true

My\Project\CustomPage:
  fields:
    customField: true

When I query

query {
  readPages {
    nodes {
      title
      __typename
    }
  }
}

I get the following result:

{
  "data": {
    "readPages": {
      "nodes": [
        {
          "title": "Regular page",
          "__typename": "Page"
        },
        {
          "title": "Special Page",
          "__typename": "CustomPage"
        },
        …
      ]
    }
  }
}

The returned __typename is correct, and I can also query fields of CustomPage by using the ... on CustomPage syntax.

As soon as I use the bulk-load feature (eg. by creating a _graphql/bulkLoad.yml config for some extensions), I lose polymorphism and all pages get "Page" as their __typename. Queries with fragments also fail, with an error like:

"Fragment cannot be spread here as objects of type "Page" can never be of type "CustomPage"."

I've created a vanilla install to test/reproduce this behavior and was unable to reproduce. Will close until I find the real issue.

Update: Can reproduce, will post example repo soon

Code to reproduce can be found here: https://github.com/bummzack/graphql-issue-468

I have found that the issue also manifests, depending on the order in which models are declared.
One example where I observed this behaviour:

# _models.yml

My\Project\CustomElementalElement:
  fields:
    relatedPages: true # This returns a DataList of related Pages (CustomPage type)
    
Page:
  fields:
    title: true

My\Project\CustomPage:
  fields:
    customField: true

Declaring the My\Project\CustomElementalElement after the My\Project\CustomPage resolves the issue and I can query CustomPage again.