BinarCode / laravel-restify

The fastest way to make a powerful JSON:API compatible Rest API with Laravel.
https://restify.binarcode.com
MIT License
604 stars 54 forks source link

API quietly fails if policy does not exist #561

Closed HakuG closed 1 year ago

HakuG commented 1 year ago

API is quiet if the policy does not exist while capturing on a related element.

public static function related(): array
    {
        return [
            'conversation' => BelongsTo::make('conversation', ConversationRepository::class),
            'attachments' => HasMany::make('attachments', AttachmentRepository::class)
        ];
    }

AttachmentRepository didn't have an associated AttachmentPolicy, so it wasn't fetching attachments. It wasn't until I added a policy that the route started working.

Would prefer that it fails with some error to notify the user of the necessary additional configuration.

binaryk commented 1 year ago

I would debate this. Since Attachments is a hasMany relationship, you might have some attachments you don't have access to, so you want to leverage to the policy to filter them out instead of failing the main repository request.

HakuG commented 1 year ago

Agreed, but if there isn't a policy to leverage, it should error out, right? In this case, the policy file didn't exist, so it quietly fails.