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

[bugfix] Ensure consistent behaviour when using access token from session in GQL and REST clients #1772

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

sle-c
Copy link
Contributor

@sle-c sle-c commented Nov 18, 2024

WHY are these changes introduced?

Fixes #1756

Passing real session to REST and GQL clients result in inconsistent behaviour. This is due to a custom if condition in the REST client that the GQL client doesn't have.

This only happens when using the testConfig test helper. While the consistent behaviour between the two is highly encouraged. It's not recommended to use a real session when using a testConfig. It's supposed to be a quick helper for unit tests, so all requests should be mocked.

For e2e tests, use a real config that points to a test Shopify store.

WHAT is this pull request doing?

This pull request includes changes to make the GraphQL (GQL) client behavior on custom app configurations consistent with the REST client. The most important changes include adding tests to ensure the correct behavior and updating the client classes to handle custom store app access tokens appropriately.

Consistent Behavior for Custom App Configurations:

Test Enhancements:

Client Class Updates:

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have used pnpm changeset to create a draft changelog entry (do NOT update the CHANGELOG.md files manually)
  • I have added/updated tests for this change
  • I have documented new APIs/updated the documentation for modified APIs (for public APIs)

@sle-c sle-c marked this pull request as ready for review November 19, 2024 16:18
@sle-c sle-c requested a review from a team as a code owner November 19, 2024 16:18
@sle-c sle-c changed the title Sle c/consisten api clients [bugfix] Ensure consistent behaviour when using access token from session in GQL and REST clients Nov 19, 2024
@@ -0,0 +1,5 @@
---
'@shopify/shopify-api': minor
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be a patch

@@ -53,10 +53,16 @@ export class GraphqlClient {
logger(config).debug(message);
}

const customStoreAppAccessToken =
Copy link
Contributor

Choose a reason for hiding this comment

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

I was a little confused on why this logic existed.

config.apiSecretKey = The apps private key
config.adminApiAccessToken = The apps access token for requests.

If we create a graphql client with the app private key, we would expect requests to fail.

Seems like in the past we had told folks when setting up a merchant custom app to put the access token = config.apiSecretKey. And then later added the config.adminApiAccessToken. And this logic is to handle folks that never migrated.

We could deprecate this logic, and require merchant custom apps to set both values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, indeed this has been deprecated

ed71298#diff-3bfd67f947f1e7d5cca6fba729bd99512b17d76b16303b6d00b235e1fb6a9237R91-R96

I think we should take this opportunity to deprecate it for good

@sle-c sle-c requested a review from lizkenyon November 21, 2024 23:35
@sle-c
Copy link
Contributor Author

sle-c commented Dec 2, 2024

holding off on merging because it's technically a breaking change for a number of apps

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

Successfully merging this pull request may close these issues.

Bug/question: E2E testing with GraphQL gives a 401 error
2 participants