Skip to content

Commit

Permalink
Temporary workaround with withDescendants
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Feb 8, 2019
1 parent 05564ba commit 6dcc005
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
32 changes: 31 additions & 1 deletion src/Scaffolding/Scaffolders/DataObjectScaffolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ class DataObjectScaffolder implements ManagerMutatorInterface, ScaffolderInterfa
*/
protected $nestedQueries = [];

/**
* @var bool Include ancestors and descendants in the types.
* Works around a regression which existing CMS GraphQL queries rely on.
* See https://github.com/silverstripe/silverstripe-versioned-admin/issues/98
* The proper default should be withDescendants=true.
* There's also a proposal for restructuring that whole thing:
* https://github.com/silverstripe/silverstripe-graphql/issues/209
*/
protected $withDescendants = false;

/**
* DataObjectScaffold constructor.
*
Expand All @@ -75,10 +85,26 @@ public function __construct($dataObjectClass)
$this->setDataObjectClass($dataObjectClass);
}

/**
* @return bool
*/
public function getWithDescendants()
{
return $this->withDescendants;
}

/**
* @param bool $withDescendants
*/
public function setWithDescendants($withDescendants)
{
$this->withDescendants = $withDescendants;

This comment has been minimized.

Copy link
@unclecheese

unclecheese Feb 17, 2019

Fluent APIs, please

}

/**
* Name of graphql type
*
* @return string
* @return strinnestedQueryg

This comment has been minimized.

Copy link
@unclecheese

unclecheese Feb 17, 2019

spelling

*/
public function getTypeName()
{
Expand Down Expand Up @@ -538,6 +564,10 @@ public function applyConfig(array $config)
}
}

if (isset($config['withDescendants'])) {
$this->setWithDescendants((bool)$config['withDescendants']);

This comment has been minimized.

Copy link
@unclecheese

unclecheese Feb 17, 2019

I prefer the type casting to be in the setter. I think it's more consistent with how other applyConfigs do it, but I could be wrong.

}

return $this;
}

Expand Down
19 changes: 12 additions & 7 deletions src/Scaffolding/Scaffolders/SchemaScaffolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,18 @@ public function addToManager(Manager $manager)
// Add all DataObjects to the manager
foreach ($this->types as $scaffold) {
$scaffold->addToManager($manager);
$inheritanceScaffolder = new InheritanceScaffolder(
$scaffold->getDataObjectClass(),
StaticSchema::config()->get('inheritanceTypeSuffix')
);
// Due to shared ancestry, it's inevitable that the same union type will get added multiple times.
if (!$manager->hasType($inheritanceScaffolder->getName())) {
$inheritanceScaffolder->addToManager($manager);

// Optionally add descendant types. If this isn't set,
// fields on those descendant types can only be queried via type-specific operations.
if ($scaffold->getWithDescendants()) {
$inheritanceScaffolder = new InheritanceScaffolder(
$scaffold->getDataObjectClass(),
StaticSchema::config()->get('inheritanceTypeSuffix')
);
// Due to shared ancestry, it's inevitable that the same union type will get added multiple times.
if (!$manager->hasType($inheritanceScaffolder->getName())) {
$inheritanceScaffolder->addToManager($manager);
}
}
}

Expand Down

0 comments on commit 6dcc005

Please sign in to comment.