Merge pull request #2620 from unclecheese/pulls/4/linkable-revisions

BUGFIX: Restore, refactor getByLink plugin
This commit is contained in:
Ingo Schommer 2020-12-08 13:53:39 +13:00 committed by GitHub
commit 7681b94f29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,46 +53,16 @@ class LinkablePlugin implements ModelQueryPlugin
return; return;
} }
Schema::invariant( Schema::invariant(
$query->isList(), !$query->isList(),
'Plugin %s only applies to queries that return lists. Query "%s" does not', 'Plugin %s cannot be applied to queries that return lists. Query "%s" is a list',
static::getIdentifier(), static::getIdentifier(),
$query->getName() $query->getName()
); );
$filterPluginID = QueryFilter::singleton()->getIdentifier();
$fieldName = $this->config()->get('field_name'); $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->addArg($fieldName, 'String');
$query->addResolverAfterware([static::class, 'applyLinkFilter']); $query->addResolverAfterware([static::class, 'applyLinkFilter']);
} }
}
/** /**
* @param $obj * @param $obj