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

Extends #603 to fix related errors #605

Merged
merged 5 commits into from
Mar 14, 2019
Merged

Extends #603 to fix related errors #605

merged 5 commits into from
Mar 14, 2019

Conversation

dgeb
Copy link
Member

@dgeb dgeb commented Mar 14, 2019

This PR is based on #603 and extends the fix for SyncRecordCache to apply to AsyncRecordCache as well.

Furthermore, a related set of bugs is resolved, in which findRelatedRecord and findRelatedRecords should throw a RecordNotFoundException when the primary record can not be found in a cache. This makes them consistent with findRecord.

Closes #603

Pieter-jan vandenbussche and others added 5 commits March 9, 2019 20:51
Whenever a primary record, or records related to a primary record, are requested and don’t exist `RecordNotFoundException` should be thrown.
`findRelatedRecord` and `findRelatedRecords` must throw `RecordNotFoundException` when a primary record doesn’t exist. Otherwise, `findRelatedRecords` should return `[]` in the undefined case.
@dgeb dgeb added the bug label Mar 14, 2019
@dgeb dgeb merged commit 3aa8ca5 into master Mar 14, 2019
@dgeb dgeb deleted the empty-related-records branch March 14, 2019 22:08
@henrixapp
Copy link
Contributor

Furthermore, a related set of bugs is resolved, in which findRelatedRecord and findRelatedRecords should throw a RecordNotFoundException when the primary record can not be found in a cache. This makes them consistent with findRecord.

Does that mean, that I have to be sure that the findRecord has succeeded? I'm currently using an optimistic pattern to query relationship...

@dgeb
Copy link
Member Author

dgeb commented Mar 15, 2019

@henrixapp This change allows you to distinguish between cases when a primary record is completely missing vs. when a relationship to that record is just empty.

If you issue a query such as store.query(q => q.findRelatedRecord({type: 'planet', id: 'jupiter'}, 'moon'), an error will be thrown if the planet jupiter does not exist in the store. This is consistent with issuing the same query against a JSONAPISource when the planet jupiter doesn't exist on the server (the 404 error will be thrown). It's also consistent with the behavior of findRecord for all sources.

If you want to adjust the contents of a cache prior to the query being processed, you could do so in a beforeQuery strategy.

Another approach entirely would be to inspect the contents of the cache via store.cache.getRelatedRecordSync() to see what's in memory. See these record accessor methods. This would be appropriate if you just want to just check what's in the store (and its cache) rather than issuing a query that can be coordinated with other sources.

If neither approach works for you, please expand upon your use case here or in gitter so I can better understand.

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

Successfully merging this pull request may close these issues.

2 participants