-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[BUGFIX beta] Overhaul queryRecord #4300
Conversation
The request is made through the adapters' `queryRecord`: | ||
|
||
```javascript | ||
// app/adapters/application.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe pointing to app/adapters/user.js would be better here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 You're absolutely right!
Thanks for the feedback @sly7-7! |
I think this is a good answer to related issues, disambiguate, and making the things consistent, I'm all for it |
This has been discussed in the team meeting and overall the taken approach looks good. I will take a look at #4310 to see if it can be addressed with this PR as well. |
assert('Expected the primary data returned by the serializer for a `queryRecord` response to be a single object but instead it was an array.', false, { | ||
id: 'ds.serializer.json-api.queryRecord-array-response' | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on doing this in normalizeQueryRecordResponse
?
I've updated this PR to address the following issues:
|
Just to clarify the clarification, does this PR ensure that |
@taras yes, |
Cool, thank you :) |
if (Array.isArray(normalized.data)) { | ||
assert('Expected the primary data returned by the serializer for a `queryRecord` response to be a single object but instead it was an array.', false, { | ||
id: 'ds.serializer.json-api.queryRecord-array-response' | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of wrapping this in an if block should we replace false
with !Array.isArray(normalized.data)
so it gets stripped correctly is a prod build?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely! Don't know why I chose the if here 😕
Currently the use case for `store.queryRecord` is not communicated very well and there has been some confusion on what the expected server response should look like (array, or an object). There are several issues with the current code base: - in general, if the serializer returns an array for the primary data returned by `normalizeQueryRecordResponse`, then `store.queryRecord` resolves with an array - if rest serializer is used and an array is returned by the adapter, then the first entry of the array is used as primary data and `store.queryRecord` resolves with the first record - if json-api serializer is used and the primary data is an array, then `store.queryRecord` resolves with an array of the primary records - the API documentation for `queryRecord` is similar to `query` and doesn't indicate when this method should be used in contrast to `store.query` and getting the first record of the array - an assertion for the payload returned by the adapter for `queryRecord` not being an empty object has been added in 2.4, which is a regression to the behavior of 2.3 ----------------------------------------------------------------------- This commit addresses the above issues and makes the following changes: - add assertion that `store.queryRecord` never resolves with an array - add deprecation warning for the rest-serializers' `queryRecord`, if an array is returned instead of a single record - removes the assertion that the returned payload from the adapter for `queryRecord` is not an empty object - add assertion within json-api serializer that the primary data of the normalized response is not an array
Thanks @pangratz |
Currently the use case for
store.queryRecord
is not communicated verywell and there has been some confusion on what the expected server
response should look like (array, or an object).
There are several issues with the current code base:
returned by
normalizeQueryRecordResponse
, thenstore.queryRecord
resolves with an array
then the first entry of the array is used as primary data and
store.queryRecord
resolves with the first recordstore.queryRecord
resolves with an array of the primary recordsqueryRecord
is similar toquery
anddoesn't indicate when this method should be used in contrast to
store.query
and getting the first record of the arrayqueryRecord
not being an empty object has been added in 2.4, which is a regression
to the behavior of 2.3
This commit addresses the above issues and makes the following changes:
store.queryRecord
never resolves with an arrayqueryRecord
, if anarray is returned instead of a single record
queryRecord
is not an empty objectnormalized response is not an array
I am not so sure about the deprecation for the
rest-serializer
, since it looks like currently alsofindRecord
works when an array is returned (see this test). But sincejson-api-adapter
doesn't allowdata: [...]
responses forqueryRecord
, this seems like an inconsistency which is a little surprising IMHO¯\_(ツ)_/¯
.This addresses issues raised in #3977, #4227 and #4255.