-
Notifications
You must be signed in to change notification settings - Fork 22
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
query keys in query string #19
Comments
@Dhaulagiri Yes, this is an issue. Unfortunately, ember-data appends the query string after the url is built with buildURL. I kind of think this is a bug in ember-data but would like to check with the core team and find out if this is intentional. There is a workaround. The idea is to make sure the query object ends up being empty. You can do this by deleting // adapter
export default ApplicationAdapter.extend(UrlTemplates, {
queryUrlTemplate: '{+host}/apps/{appName}/app'
urlSegments: {
appName(type, id, snapshot, query) {
var appName = query.appName;
delete query.appName;
return appName;
},
},
}); |
@igorT do you have any thoughts on if it makes sense that the default adapter is appending the query string to the result from |
I agree Ember.Data lets you construct the URL but not the query params which seems really strange. I ended up using RESTAdapter.sortQueryParams to achieve this. |
@cfator oh, would you be willing to share your solution? |
I think this will work: export default ApplicationAdapter.extend(UrlTemplates, {
queryUrlTemplate: '{+host}/apps/{appName}/app',
urlSegments: {
appName(type, id, snapshot, query) {
return query.appName;
}
},
sortQueryParams: function(params) {
return {};
}
}); Keep in mind that you might be doing other developers a disservice when they try to add a query param to this code and are left pondering why it doesn't work... heh |
@kehphin Nice! I wonder if it would be worth including Theoretically, it shouldn't be a problem. If one wants to include query params with url templates, they should define them as part of the template with However, I agree that this could be confusing and some people might even be depending on the existing functionality. My other concern here is that might only be compatible with a few versions of ember-data. I'd love some input here. |
@amiel : Did you find out if this was an intended behavior on the Ember Data teams' part? I was able to construct the correct endpoint by following the workarounds in this thread, but they seem very hacky. |
@OandrewO I have not heard from the Ember Data team on this, and I agree, the workarounds are hacky. I'll try pinging them again on slack. |
@OandrewO / others: It looks like emberjs/data#3099 will provide the hook we need to customize the query params ( Once that gets un-feature flagged and I personally have an app that is caught up to that version, I will be happy to work on having ember-data-url-templates use that hook to prevent this issue. If anyone else has an app up to canary and wants to work on it, please do :) For now, looking through the source, using |
Ok, I just released 0.2.0 with this hack. With this change, you should be able to remove either hack ( Note that if you were using |
awesome! thanks!! |
This way, we have a test that verifies that #19 continues to be resolved even after future changes.
This way, we have a test that verifies that #19 continues to be resolved even after future changes.
Add a test to verify the query params hack for #19
The docs for query show how to include just certain keys in a request, but in my use I am still seeing the query keys being included in the query string. For example:
Yields this url:
https://foo.com/apps/foo/app?appName=foo
When I really want just this:
https://foo.com/apps/foo/app
Are the docs incorrect or is there something I'm doing incorrectly here?
The text was updated successfully, but these errors were encountered: