diff --git a/src/GraphQL/Plugins/VersionedDataObject.php b/src/GraphQL/Plugins/VersionedDataObject.php index a113b540..0f6f27e8 100644 --- a/src/GraphQL/Plugins/VersionedDataObject.php +++ b/src/GraphQL/Plugins/VersionedDataObject.php @@ -21,6 +21,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) @@ -110,7 +111,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, [