refactor(api): Api clean up#361
refactor(api): Api clean up#361housseindjirdeh merged 12 commits intogitpoint:masterfrom machour:api-banana-split
Conversation
|
@machour this is an amazing job! Could you please add method for executing a GraphQL query from PR #347? And do you think we can use the plural for METHOD and ACCEPT constants? |
|
@lex111 GraphQL should be in a For the plurals, are you talking about changing |
|
Yes, you are right, GraphQL is already v4.
Correct, do you think? |
|
@lex111 it seems more natural to me to use the singular form. The idea is that you are selecting one method of the possible choices in the enum. I always see that in java projects for example. |
housseindjirdeh
left a comment
There was a problem hiding this comment.
Wow this is so great, thank you so much @machour. This is going to smoothen things out so nicely once we start updating and using the v4 namespace for GraphQL.
Ran some regressions and it all looks smooth as silk - next up like you mentioned would be including each
of the fetch methods within the appropriate directories and ideally, we should be able to swap out
v3 to v4 thanks to this wrapper 🙌
While looking at redux, I came accros a few facts with api/index.js :
fetch()is being called in a lot of functions, inside and outsideapi/index.js. Some actions files also borrowed the accessTokenParameters* helpers.fetchUrlfor GET returning json, andfetchNormalfor GET returning aResponsefetchUrlCommentsHTMLwas in fact performing the exact same thing asfetchUrlThis PR cleans up all this, and makes the API crystal clear, by introducing the
v3namespace:v3 is a simple object representing our GitHub Rest API v3 client :
v3.call()is the only function that calls GitHub. It receives theurlandparametersarguments for thefetch()call and returns a Responsev3.rootis the root endpointv3.parameters()is the sole responsible for preparing thefetch()call parameters. It takes the accessToken (mandatory), the HTTP method (optional), the Accept header (optional) and a body for the request (optional), does its magic, and returns the correct object.httpVerb AcceptedResult ()
For example:
v3.get()performs aGETquery and returns theResponsev3.getJson()performs aGETquery and returns the .json() responsev3.head()performs aHEADquery and returns theResponsev3.postRaw()performs aPOSTrequest with the given object and returns the .text() responseI implemented all the needed helpers, and if a new combination arises (
postHtml()for example), it should be added in v3 following this nomenclature.I also adopted two enums,
METHODandACCEPTto attempt to standardize things a bit more.This clean up made obvious that
fetchStarCount()was missing the accessToken, and that some weird calls were made by the watch/unwatch actions. I fixed the calls.I did my best to test all the apps, but I might have missed a few spots, please let me know if it's the case!
Next step (once this is merged), is to re-dispatch all remaining functions (aside v3 of course) from
api/index.jsto the actions files where they belong.