tchak / orbit-server

A server interface for Orbit
8 stars 2 forks source link

Return 404 for non-existent resources #11

Closed dgeb closed 4 years ago

dgeb commented 4 years ago

Currently, PATCH and DELETE requests are treated as successful, even if a resource does not exist on the server. To be JSON:API compliant, these requests should respond with a 404.

tchak commented 4 years ago

@dgeb I just checked. It is an issue with orbit sources. But not only orbit-sql every source based on record-cache have the issue.

tchak commented 4 years ago

I am actually not sure. Do you expect a source.update(t => t.updateRecord({ id: 'not-a-valid-id', type: 'planet' })) to be a success?

dgeb commented 4 years ago

@tchak The default record-cache behavior is based upon the assumption that the caches contain a sparsely populated set of records that is non-authoritative. I think we can assume that orbit-sql is not sparse, but rather the authoritative source for records.

Do you expect a source.update(t => t.updateRecord({ id: 'not-a-valid-id', type: 'planet' })) to be a success?

For a sparse cache, not-a-valid-id is probably impossible to recognize as invalid, and won't be rejected until it's sent to an authoritative source. On the other hand, an authoritative source should reject what it knows to be invalid (and that rule is written into the JSON:API spec).

Maybe the concept of "authoritative" should be encoded into @orbit/record-cache, so that both scenarios could be handled?

dgeb commented 4 years ago

@tchak thanks for implementing this <3