Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Allow api version overrides #660

Merged
merged 4 commits into from
Jan 5, 2023
Merged

Allow api version overrides #660

merged 4 commits into from
Jan 5, 2023

Conversation

paulomarg
Copy link
Contributor

@paulomarg paulomarg commented Jan 4, 2023

WHY are these changes introduced?

Currently, we receive an apiVersion setting when calling shopifyApi(), and that version is used for any clients throughout the app lifecycle. However, using different versions of the API in different places is a valid use case, for example when trying out a developer preview without migrating everything else.

With the way things work now, the clients are unnecessarily rigid and make it harder to interact with multiple versions of the API.

WHAT is this pull request doing?

Adding an apiVersion override to all of the clients' constructors, that will be used instead of the global value when present.

With this, we can also update the REST resources to internally use their own API version, thus removing the requirement for the app to load the "right" REST resources - with this change, apps can load whatever resources they want to use. We still log a warning if the version mismatches to help remind folks that they might want to update their resources when they change the main version.

Bonus: it seems we'd accidentally removed the REST resource base tests, I'm adding those back. You can ignore those, and the actual changes are here: https://github.com/Shopify/shopify-api-js/pull/660/files/2965e1a9f07ef99e50fd0647f28b17c213dc0476..ea292fbb1fdb4a20213ff9ac54a7144562f71a62

Type of change

  • Minor: New feature (non-breaking change which adds functionality)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above
  • I have added/updated tests for this change
  • I have documented new APIs/updated the documentation for modified APIs (for public APIs)

@paulomarg paulomarg requested a review from a team as a code owner January 4, 2023 20:41
lib/clients/graphql/graphql_client.ts Outdated Show resolved Hide resolved
lib/clients/graphql/graphql_client.ts Show resolved Hide resolved
@@ -30,7 +31,15 @@ export class GraphqlClient {
);
}

if (params.apiVersion) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we do any validation that this is a valid apiVersion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't usually validate this kind of param - we're trusting TS to shout if anything is wrong, but this can be a version string ("2023-04") in pure JS and it will work normally.

lib/clients/graphql/graphql_client.ts Outdated Show resolved Hide resolved
@cquemin
Copy link
Contributor

cquemin commented Jan 4, 2023

@paulomarg since you change the argument type, I am wondering if these aren't breaking changes? It looks like it mostly on internal object but I am not 100% sure

@paulomarg
Copy link
Contributor Author

@paulomarg since you change the argument type, I am wondering if these aren't breaking changes? It looks like it mostly on internal object but I am not 100% sure

We're mostly just adding an optional apiVersion to the client constructors, so that won't break (most of the tests still use them the "old" way). The loadRestResources function is not exported so it shouldn't be a problem either.

What just occurred to me is that the CONFIG static in the clients is technically public. Even though it's extremely unlikely apps will access those, should we consider this a breaking change?

@cquemin
Copy link
Contributor

cquemin commented Jan 4, 2023

@paulomarg since you change the argument type, I am wondering if these aren't breaking changes? It looks like it mostly on internal object but I am not 100% sure

We're mostly just adding an optional apiVersion to the client constructors, so that won't break (most of the tests still use them the "old" way). The loadRestResources function is not exported so it shouldn't be a problem either.

What just occurred to me is that the CONFIG static in the clients is technically public. Even though it's extremely unlikely apps will access those, should we consider this a breaking change?

I guess potentially ? I am not sure if we want to go down this route for the few that will be impacted or not. If we apply the rules strictly then yes maybe it should be, but it means waiting for the next major release...

@paulomarg
Copy link
Contributor Author

I agree, IMO we shouldn't hold this change back because of that.

Copy link
Contributor

@cquemin cquemin left a comment

Choose a reason for hiding this comment

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

Following our conversation: you're good to go then

@paulomarg paulomarg merged commit ece979b into main Jan 5, 2023
@paulomarg paulomarg deleted the allow_api_version_overrides branch January 5, 2023 14:56
@shopify-shipit shopify-shipit bot temporarily deployed to production January 5, 2023 18:47 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants