Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeAncestry always returns an empty array #4

Open
TheBnl opened this issue Jan 7, 2023 · 0 comments
Open

TypeAncestry always returns an empty array #4

TheBnl opened this issue Jan 7, 2023 · 0 comments

Comments

@TheBnl
Copy link

TheBnl commented Jan 7, 2023

I noticed that TypeAncestry always returns an array with one null item in it:

"typeAncestry": [
  null
],

While the method (DataObjectHashExtension::getTypeAncestry()) that is producing the array is actually creating the following array:

Array
(
    [0] => Array
        (
            [0] => UserDefinedForm
            [1] => b438700702fb871b886359357e938a87
        )
    [1] => Array
        (
            [0] => Page
            [1] => c989cfe250b1fadad5b45da5116401e3
        )
    [2] => Array
        (
            [0] => SiteTree
            [1] => 7a018541792aafd19ecdae03b3ad5ff5
        )
)

When changing the type from [[String]] to String and change the method so it returns the type directly it does return the actual type:

modelConfig:
  DataObject:
    type_formatter: 'SilverStripe\Core\ClassInfo::shortName'
    base_fields:
      ID: ID!
      HashID: String!
      TypeAncestry: 'String'
      # TypeAncestry: '[[String]]'
      exists: Boolean!
public function getTypeAncestry()
{
  $config = SchemaBuilder::singleton()->getConfig($this->owner->config()->get('headless_schema'));
  if ($config) {
    return $config->getTypeNameForClass($this->owner->ClassName);
  }
  return null;
}

returns:

"typeAncestry": "UserDefinedForm",

Is something changed in the way array types ([[String]]) are handled?
I noticed that in the silverstripe/silverstripe-nextjs your using a different implementation to determine the ancestry in the (Resolver::resolveStaticBuild() method)[https://github.com/silverstripe/silverstripe-nextjs/blob/db7b253217c0981a2b70203f26e0a90529ebfa4c/src/GraphQL/Resolver.php#L30] that uses a custom type TypeAncestry. Is that something that should be implemented here as well?

For context, i'm working on an sveltekit implementation where i would like to resolve a Page or Elemental template based on the ancestry. Currently i'm just directly falling back to Page when a template isn't found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant