Adding a new query operation - "Missing graphql file for SilverStripeSiteTree" Error

Hello everyone, I am having some trouble… in CMS5, I am trying to create a custom query operation… and the moment I add the operation to the schema modelConfig: DataObject without adding it to any model, I start to get a “Missing graphql file for SilverStripeSiteTree error.”

ReadByURLQuery.php:

<?php

namespace LMC\GraphQL;

use Exception;
use SilverStripe\ORM\DataObject;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use SilverStripe\GraphQL\Schema\Interfaces\OperationCreator;
use SilverStripe\GraphQL\Schema\Field\ModelQuery;
use SilverStripe\GraphQL\Schema\Interfaces\ModelOperation;
use SilverStripe\GraphQL\Schema\Interfaces\SchemaModelInterface;
use SilverStripe\CMS\Model\SiteTree;


/**
 * Scaffolds a readByURL Operation
 */
class ReadByURLQuery implements OperationCreator
{

    public function createOperation(
        SchemaModelInterface $model,
        string $typeName,
        array $config = []
    ): ?ModelOperation
    {
        $mutationName = 'read' . ucfirst($typeName) . 'ByURL';

        return ModelQuery::create($model, $mutationName)
            ->setType($typeName)
            ->addArg('url', 'String!')
            ->setResolver([self::class, 'resolve'])
            ->setResolverContext([
                'dataClass' => $model->getSourceClass(),
            ]);
    }

    public static function resolve(array $resolverContext = []): \Closure
    {
        $dataClass = $resolverContext['dataClass'] ?? null;
        return function ($obj, array $args) use ($dataClass) {
            
            if (!$dataClass) {
                return null;
            }
            
            $page = DataObject::get($dataClass)
                ->filter('FullPath', $args['url'])->first();
            
            if(!$page) {
                throw new \Exception(sprintf(
                    'Page not found %s',
                    $this->dataObjectClass
                ));
            }

            if(!$page->canView()) {
                throw new \Exception(sprintf(
                    'Cannot view %s',
                    $this->dataObjectClass
                ));
            }
            
            return $page;
        };
    }

}

I don’t understand where this is coming from, I’ve rebuilt the graphql schema of course just prior to that…

Here’s the trace from graphql ide:

errors": [
    {
      "message": "Missing graphql file for SilverStripeSiteTree",
      "code": 0,
      "file": "/app/vendor/silverstripe/graphql/src/Schema/Storage/AbstractTypeRegistry.php",
      "line": 125,
      "trace": [
        {
          "file": "/app/vendor/silverstripe/graphql/src/Schema/Storage/AbstractTypeRegistry.php",
          "line": 68,
          "function": "fromCache",
          "class": "SilverStripe\\GraphQL\\Schema\\Storage\\AbstractTypeRegistry",
          "type": "::",
          "args": [
            "SilverStripeSiteTree"
          ]
        },
        {
          "file": "/app/vendor/webonyx/graphql-php/src/Type/Schema.php",
          "line": 328,
          "function": "get",
          "class": "SilverStripe\\GraphQL\\Schema\\Storage\\AbstractTypeRegistry",
          "type": "::",
          "args": [
            "SilverStripeSiteTree"
          ]
        },
        {
          "file": "/app/vendor/webonyx/graphql-php/src/Type/Schema.php",
          "line": 303,
          "function": "loadType",
          "class": "GraphQL\\Type\\Schema",
          "type": "->",
          "args": [
            "SilverStripeSiteTree"
          ]
        },
        {
          "file": "/app/vendor/webonyx/graphql-php/src/Utils/AST.php",
          "line": 565,
          "function": "getType",
          "class": "GraphQL\\Type\\Schema",
          "type": "->",
          "args": [
            "SilverStripeSiteTree"
          ]
        },...

Note that I am doing a bit of guesswork how to create a ModelQuery, as the only example in the v5 docs is a MutationQuery… and maybe the code above is way off :slightly_smiling_face:

What does your schema yaml look like? What models have you set up a schema definition for? What does your query look like in the IDE?