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

FIX Avoid inferring model type #336

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/GraphQL/Plugins/VersionedDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use SilverStripe\Versioned\GraphQL\Resolvers\VersionedResolver;
use SilverStripe\Versioned\Versioned;
use Closure;
use SilverStripe\GraphQL\Schema\Field\ModelField;

// GraphQL dependency is optional in versioned,
// and the following implementation relies on existence of this class (in GraphQL v4)
Expand Down Expand Up @@ -114,7 +115,12 @@ public function apply(ModelType $type, Schema $schema, array $config = []): void
}

$schema->addType($versionType);
$type->addField('versions', '[' . $versionName . ']', function (Field $field) use ($type, $schema, $config) {
$versionsFieldConfig = new ModelField('versions', [
'type' => '[' . $versionName . ']',
// TODO This isn't the actual resolvedModelClass, it just avoids triggering database queries through inference
'resolvedModelClass' => $type->getModel()->getSourceClass()
], $type->getModel());
$type->addField('versions', $versionsFieldConfig, function (Field $field) use ($type, $schema, $config) {
$field->setResolver([VersionedResolver::class, 'resolveVersionList'])
->addResolverContext('sourceClass', $type->getModel()->getSourceClass());
SortPlugin::singleton()->apply($field, $schema, [
Expand Down