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

Unable to create request class of type [Query] for resource type ... #67

Closed
6 tasks done
tomsiwik opened this issue Apr 8, 2021 · 2 comments
Closed
6 tasks done

Comments

@tomsiwik
Copy link

tomsiwik commented Apr 8, 2021

I did everything the tutorial specifies but I still keep getting the same error whatever I try.

routes/api.php

use LaravelJsonApi\Laravel\Facades\JsonApiRoute;
use LaravelJsonApi\Laravel\Http\Controllers\JsonApiController;

JsonApiRoute::server('v1')
    ->prefix('v1')
    ->resources(function ($server) {
        $server->resource('clients', JsonApiController::class);
        $server->resource('users', JsonApiController::class);
        $server->resource('flags', JsonApiController::class);
    });

Handler.php

$this->renderable(
            \LaravelJsonApi\Exceptions\ExceptionParser::make()->renderable()
        );

Server.php

    public function serving(): void
    {
        // Do I need to register these?

        LaravelJsonApi::registerCollectionQuery(Users\UserCollectionQuery::class, 'users');
        LaravelJsonApi::registerCollectionQuery(Clients\ClientCollectionQuery::class, 'clients');
        LaravelJsonApi::registerCollectionQuery(Flags\FlagCollectionQuery::class, 'flags');
    }

    /**
     * Get the server's list of schemas.
     *
     * @return array
     */
    protected function allSchemas(): array
    {
        return [
            Users\UserSchema::class,
            Clients\ClientSchema::class,
            Flags\FlagSchema::class
        ];
    }

It looks almost identical like the dummy project in this repo.
I created everything from commandline only. The above code is the only thing I added + exception handler.

  • Getting started installation
  • Registered Schemas (Auto-discovery) -> doesn't seem to work?
  • Models via php artisan make:model Client -mfs
  • Everything in JsonApi/V1 added via php artisan jsonapi:requests Client
  • No controllers, no filter
  • Schemas + Server added with cli

Any suggestions what else I can try? Haven't found any clue in the documentation

@tomsiwik
Copy link
Author

tomsiwik commented Apr 8, 2021

Apparently. git reset --hard HEAD and doing everything from scratch solves the issue. I don't see any difference but seems to work now :( heisenbug

@tomsiwik tomsiwik closed this as completed Apr 8, 2021
@lindyhopchris
Copy link
Contributor

@tomsiwik yeah this was definitely something to do with your setup as far as I can tell. Unfortunately your issue doesn't give me the required information to debug - as a tip, it's best to include the stack trace for an error if you're reporting an issue that has an exception.

FYI you don't need to use LaravelJsonApi::registerCollectionQuery()

It's worth noting that the error title you've given to this issue states: Unable to create request class of type [Query]

From the information you've provided, it seems you have CollectionQuery classes, not Query classes.

If you have problems with classes not loading, another tip is to try:

composer dump-autoload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants