Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Add API Versioning configuration #22

Merged
merged 2 commits into from
Aug 19, 2021

Conversation

anduong
Copy link
Contributor

@anduong anduong commented Aug 14, 2021

Description

Add API version configuration to ShopifyAPI

Context

We have all setup for API key, Password, Shop domain, etc. However, Shopify API still requires us to specify the API version to make request using the correct API version. I think we should make this as a configuration to make it more convenient.

This will also help to fix this issue #7

Proposed Solution

The configuration for API version will either

What changes in this PR

  • Add prompt to ask for API version
  • Implement a mechanism to automatically figure out the latest API version using the current date & time
  • Add test to make sure the latest API version mechanism working correctly with every month in a year
  • Update Shopify API, GraphQL and GraphQL client gems to the latest
  • Update README to let people know how to configure the API version
  • Add webmock to test the HTTP Request as fakeweb is no longer maintained

@anduong
Copy link
Contributor Author

anduong commented Aug 16, 2021

Hi @chrisbutcher and @pfeffer, could you please help to review this PR?


def shopify_api_latest_version
quarter = 3
latest_released_month = SHOPIFY_API_RELEASE_MONTHS[(Time.now.month - 1)/ quarter]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a neat trick!

But that said, while stable API versions typically do get released on the first of the month/quarter, sometimes (as with version 2020-07) the version was released a day later).

Perhaps a safer alternative to computing the version handle in this library would be:

Since you have the shop domain + API credentials from above, perhaps you should call the GraphQL Admin API to obtain the latest API version from https://shopify.dev/api/admin/graphql/reference/common-objects/queryroot#publicapiversions-2021-07.

The last supported: true version would be the one to pick here.

image

Copy link
Contributor Author

@anduong anduong Aug 16, 2021

Choose a reason for hiding this comment

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

Hi @chrisbutcher,

Thanks for reviewing the changes. It is good to know that we can query the supported API version. Your suggestion is better than the time-induction approach. It helps to avoid timing sensitivity (especially in different timezones).

I will implement the GraphQL query and update this PR soon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chrisbutcher I have updated the implementation to get the Public API versions from Shopify. Can you please review the change? Thanks

One small note is that I am using webmock instead of fakeweb to test the functionality as the gem fakeweb is no longer maintained. See chrisk/fakeweb#62 and chrisk/fakeweb#57

@chrisbutcher chrisbutcher merged commit 97126fe into Shopify:master Aug 19, 2021
@chrisbutcher
Copy link
Contributor

Thanks @anduong !

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.

2 participants