mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUGFIX: Restore, refactor getByLink plugin
This commit is contained in:
parent
7b960c1537
commit
e415d41856
@ -15,3 +15,7 @@ SilverStripe\GraphQL\Schema\Schema:
|
||||
admin:
|
||||
src:
|
||||
- 'silverstripe/cms: _graphql'
|
||||
SilverStripe\Core\Injector\Injector:
|
||||
SilverStripe\GraphQL\Schema\Registry\PluginRegistry:
|
||||
constructor:
|
||||
getByLink: '%$SilverStripe\CMS\GraphQL\LinkablePlugin'
|
||||
|
@ -53,45 +53,15 @@ class LinkablePlugin implements ModelQueryPlugin
|
||||
return;
|
||||
}
|
||||
Schema::invariant(
|
||||
$query->isList(),
|
||||
'Plugin %s only applies to queries that return lists. Query "%s" does not',
|
||||
!$query->isList(),
|
||||
'Plugin %s cannot be applied to queries that return lists. Query "%s" is a list',
|
||||
static::getIdentifier(),
|
||||
$query->getName()
|
||||
);
|
||||
|
||||
$filterPluginID = QueryFilter::singleton()->getIdentifier();
|
||||
$fieldName = $this->config()->get('field_name');
|
||||
|
||||
if ($query->hasPlugin($filterPluginID)) {
|
||||
$args = $query->getArgs();
|
||||
$filterArg = null;
|
||||
foreach ($args as $arg) {
|
||||
if ($arg->getName() === QueryFilter::config()->get('field_name')) {
|
||||
$filterArg = $arg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Schema::invariant(
|
||||
$filterArg,
|
||||
'Plugin "%s" was applied but the "%s" plugin has not run yet. Make sure it is set to after: %s',
|
||||
$this->getIdentifier(),
|
||||
$filterPluginID,
|
||||
$filterPluginID
|
||||
);
|
||||
$inputTypeName = $filterArg->getType();
|
||||
$inputType = $schema->getType($inputTypeName);
|
||||
Schema::invariant(
|
||||
$inputType,
|
||||
'Input type "%s" is not in the schema but the %s plugin is applied',
|
||||
$inputTypeName,
|
||||
$filterPluginID
|
||||
);
|
||||
$inputType->addField($fieldName, 'String');
|
||||
$query->addResolverAfterware([static::class, 'applyLinkFilter']);
|
||||
} else {
|
||||
$query->addArg($fieldName, 'String');
|
||||
$query->addResolverAfterware([static::class, 'applyLinkFilter']);
|
||||
}
|
||||
$query->addArg($fieldName, 'String');
|
||||
$query->addResolverAfterware([static::class, 'applyLinkFilter']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user