-
Notifications
You must be signed in to change notification settings - Fork 38
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
Support fetching resources by id #125
Conversation
This looks great! @Dhaulagiri @srvance do you have any thoughts on this approach? I want to make sure there aren't any real-world use-cases we're overlooking where this is problematic. |
I know @joshwlewis is making these changes for real use cases in our app so I defer to his judgement as he has a lot more experience with github's api than I do. @joshwlewis would you mind updating the readme with examples of these calls as well? |
@Dhaulagiri the readme has been updated. @elwayman02 the only caveat I can think of I already listed on the PR description. However, I feel pretty strongly that preferring fetching by id is correct. In my experience, it's fairly common for repository names and user logins to change, but GitHub doesn't give notification when this happens. As a result, fetching resources by a name is considerably less stable than fetching by id. |
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 only have one question, otherwise this looks good. What happens if the ID passed is a string type? Will your code still read it as an ID instead of a name? I can see situations where some apps may be passing around strings because of how their backend stores the data, for example. It would be nice to have additional tests that verify the expected behavior, in particular so we don't accidentally break it in the future if someone decides to refactor your regexes for some reason.
const repo = 34598603; | ||
assert.equal(adapter.buildURL('github-repository', repo, null, 'findRecord'), `${host}/repositories/${repo}`); | ||
assert.equal(adapter.buildURL('github-repository', parseInt(id), null, 'findRecord'), `${host}/repositories/${id}`); | ||
assert.equal(adapter.buildURL('github-repository', id.toString(), null, 'findRecord'), `${host}/repositories/${id}`); |
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.
nice!
If it's a string of digits, this code will treat it as an id. =) Tests added. |
@Dhaulagiri do you mind handling this release to meet your app's timelines? Looks good to me once CI passes. |
Published in 0.5.0. Thanks @joshwlewis! |
@elwayman02 Sorry for the slow response. This sounds like a good approach. My only suggestion on the implementation would be to encapsulate the integer check and use |
Currently, this addon doesn't accommodate fetching
github-user
orgithub-repository
by it's id. That's because GitHub has an unusual API that requires using a different URL depending on whether you are fetching by name or id.For example, this fails:
But this works:
This PR adds support for fetching by id, by detecting if the provided id is an integer.
It is possible to name both resources with digits on GitHub, so this means there is a potential conflict if you want to find the user with the login
"1234"
, but instead get the user with id1234
. This PR means we would prefer the id version, and I believe that's consistent with the way EmberData is designed (heavily based on remote ids).