-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
feat(modules-sdk): remote query retrieve #6849
Conversation
🦋 Changeset detectedLatest commit: d421a83 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Ignored Deployments
|
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.
I think this is fine, but I do have a question.
Why don't we add list
and retrieve
on remoteQuery
? For example you'd do remoteQuery.list
and remoteQuery.retrieve
, and like that you will either get an array or a single object. Also the arguments we pass can be slightly different, eg. for retrieve you will only be able to pass an ID for filtering.
Again, not something we need to do now, but I am curious why we haven't opted for that approach
The Remote Joiner is a generic data fetching system that resolves relations always in bulk.
We can implement that. but I believe this should also come when we somehow can type the expected result of the query. |
Just chatted with @carlos-r-l-rodrigues about an alternative approach that would solve two common scenarios:
We could introduce an option to For both 1. and 2., it would look like:
This would allow us to create generic steps for validating that resources exist instead of having steps for each domain like the following one: What do you guys think? @sradevski, @adrien2p |
I think the only caveat here is that we will need to apply that rule only if you are filtering by ID (or in fact, primary keys), otherwise it wouldn't make much sense to have such a setting. An alternative approach is to be explicit about what sort of data fetch you are trying to do - A |
I am not sure it is the remote query responsibility to do this, already, if we call the retrieve from the modules, it will throw if no results are found for the given primary key. Also, it would only work for primary keys, which in my opinion could lead to miss understanding, e.g filtering using any filters + true for the throw option but there is no way to validate that internally. Shouldn't this be something done outside of the remote query. Like we usually do, find -> check -> throw? Maybe we could have a validator predicate? e.g const result = await remoteQuery({
filters: {
code: 'test'
}
}, {
throwOnNotFound: 'code'
})
const result = await remoteQuery({
filters: {
id: ['test']
}
}, {
throwOnNotFound: 'id'
}) above, it is explicit the field you want to validate the data against and if there is multiple filters it is also explicit that you can't do it and you have to handle it manually 🤔 I am totally unsure about this approach, just throwing it out loud ahah |
The idea was based on the assumption that we always use |
I think it is fine to have this validation on the Remote Joiner. But the only validation it will be able to perform is if primary keys were returned, anything outside this scope is business logic and should be handled where it belongs. So, the remote joiner will have options to throw in case the key is not found. Under the hood, the remote query will always call the method |
Right now, I believe we are in fact not handling the case of a non-existing resource in any of our Here, we would either have to add:
or use the option proposed here. I am fine with either. |
changes
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.
Given that this doesn't really change the behavior or anything in remoteQuery
, I'd be down for merging this now. We can play around with it in API routes and then come to a decision whether or not to keep it at a later point?
Personally, I think this is a nice addition.
What:
Remote Joiner options to check if keys exist on entry points or relations