Skip to content
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

[PART 2] Networking Refactor - Unify REST & GraphQL networking implementation #182

Merged
merged 33 commits into from
Aug 17, 2023

Conversation

scannillo
Copy link
Collaborator

Reason for changes

Follow up to #177.

This PR:

  • Standardizes the interface for making REST & GraphQL requests from the feature client's perspective
  • Unifies REST & GraphQL requests to use the same underlying HTTP, URLRequest, and URLSession implementations
  • Repurposes APIClient (which previously just passed requests along to HTTP) into a true NetworkingCoordinator that transforms REST & GraphQL --> HTTP.

Summary of changes

  • Add fetch(request: GraphQLRequest) method to APIClient
    • This class now has only 2 public functions, an equivalent for REST & GraphQL
  • Remove GraphQLClient and other no-longer-used GraphQL files
  • Rename GraphQLQueryResponse --> GraphQLHTTPResponse

Next

  • Rename APIClient to NetworkingClient
  • Unit Tests
  • Add VaultPaymentMethodTokensAPI class (waiting on Victoria's Vault without Purchase #172 PR to merge)
  • Update parsing layer for GraphQL (see TODOs)

Note

Tests are expected to fail.

Checklist

  • Added a changelog entry

Authors

@scannillo

scannillo and others added 25 commits August 8, 2023 22:29
A
dd docstrings with specifics on how to find each API in PPaaS
* Remove Eligibility feature

* remove two types for Eligibility feature
@scannillo scannillo requested a review from a team as a code owner August 11, 2023 17:26
@scannillo scannillo changed the title Unify REST & GraphQL networking implementation [PART 2] Networking Refactor - Unify REST & GraphQL networking implementation Aug 11, 2023
Base automatically changed from construct-url-request-in-http to networking-refactor August 16, 2023 14:36
Copy link
Collaborator

@sshropshire sshropshire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

/// :nodoc:
public func fetch(request: GraphQLRequest) async throws -> HTTPResponse {
let url = try constructGraphQLURL(queryName: request.queryNameForURL)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we need this extra space but up to you:

Suggested change

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it intentionally to group postBody and postData together, but down to remove this newline if it's harder to read

let postBody = GraphQLHTTPPostBody(query: request.query, variables: request.variables)
let postData = try JSONEncoder().encode(postBody)

let httpRequest = HTTPRequest(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we single line this is it above our linter line length? May be nice to just group all of the properties together but not sure if this is more readable this way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not violate our line length, but I thought it was a little cleaner. Happy to go either way though!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way is fine, was more just curious. If it makes more sense to have things grouped together a particular way that's fine too.

Copy link
Collaborator Author

@scannillo scannillo Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by "group all of these properties together"? You mean single line it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I single-lined both the HTTPRequest() definitions (see commit 7417e15)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by "group all of these properties together"? You mean single line it?

Ah, sorry was referencing this comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That link takes me back to:

If we single line this is it above our linter line length? May be nice to just group all of the properties together but not sure if this is more readable this way.

Do you mean to remove the newlines between these variables?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, idk why GH is linking to that. This comment above is the one I was trying to reference:

I did it intentionally to group postBody and postData together, but down to remove this newline if it's harder to read

Not a blocker though, whatever you feel is best

Sources/CorePayments/Networking/APIClient.swift Outdated Show resolved Hide resolved
Sources/CorePayments/Networking/APIClient.swift Outdated Show resolved Hide resolved
Copy link
Collaborator

@jaxdesmarais jaxdesmarais left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@scannillo scannillo merged commit 561b1d3 into networking-refactor Aug 17, 2023
@scannillo scannillo deleted the refactor-graphql branch August 17, 2023 19:07
url: url,
body: request.body
)
let httpRequest = HTTPRequest(headers: headers, method: request.method, url: url, body: request.body)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

public func fetch(request: GraphQLRequest) async throws -> HTTPResponse {
let url = try constructGraphQLURL(queryName: request.queryNameForURL)

let postBody = GraphQLHTTPPostBody(query: request.query, variables: request.variables)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants