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

[WIP][Admin API Client] Add Admin API client package #1022

Merged
merged 18 commits into from
Nov 10, 2023
Merged

Conversation

scottdixon
Copy link
Contributor

@scottdixon scottdixon commented Oct 27, 2023

WHY are these changes introduced?

Add a new admin-api-client package. Used @melissaluu's Storefront client work as the starting point.

WHAT is this pull request doing?

Add a new admin-api-client package to the repo.

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 yarn changeset to create a draft changelog entry (do NOT update the CHANGELOG.md file manually)
  • I have added/updated tests for this change
  • I have documented new APIs/updated the documentation for modified APIs (for public APIs)

@scottdixon scottdixon force-pushed the sd-admin-client branch 4 times, most recently from 4537ee8 to fa9acee Compare October 27, 2023 02:40
packages/admin-api-client/README.md Outdated Show resolved Hide resolved
packages/admin-api-client/README.md Show resolved Hide resolved
packages/admin-api-client/README.md Outdated Show resolved Hide resolved
packages/admin-api-client/package.json Show resolved Hide resolved
packages/admin-api-client/package.json Outdated Show resolved Hide resolved
packages/admin-api-client/src/utilities/api-versions.ts Outdated Show resolved Hide resolved
packages/admin-api-client/src/utilities/api-versions.ts Outdated Show resolved Hide resolved
packages/admin-api-client/src/admin-api-client.ts Outdated Show resolved Hide resolved
packages/admin-api-client/src/constants.ts Outdated Show resolved Hide resolved
Comment on lines +81 to +74
"User-Agent": `${
userAgentPrefix ? `${userAgentPrefix} | ` : ""
}${CLIENT} v${DEFAULT_CLIENT_VERSION}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a mouthful 😅 is there a cleaner approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't think of anything other than pulling the prefix part into its own variable, but that doesn't really change anything. Fine as is IMO.

"Content-Type": "application/json",
Accept: "application/json",
"X-Shopify-Access-Token": "access-token",
"User-Agent": "Admin API Client vROLLUP_REPLACE_CLIENT_VERSION",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there some way to test it's actually replacing ROLLUP_REPLACE_CLIENT_VERSION?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe importing the built file? Seems like overkill to me though, I think we can trust rollup to do its thing if we manually check it.

Comment on lines +81 to +74
"User-Agent": `${
userAgentPrefix ? `${userAgentPrefix} | ` : ""
}${CLIENT} v${DEFAULT_CLIENT_VERSION}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't think of anything other than pulling the prefix part into its own variable, but that doesn't really change anything. Fine as is IMO.

"Content-Type": "application/json",
Accept: "application/json",
"X-Shopify-Access-Token": "access-token",
"User-Agent": "Admin API Client vROLLUP_REPLACE_CLIENT_VERSION",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe importing the built file? Seems like overkill to me though, I think we can trust rollup to do its thing if we manually check it.

});

it("throws an error when run in a browser environment (window is defined)", () => {
global.window = {} as any;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This might not be necessary since these tests should only run on a server environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't this still be handy to catch someone removing the browser/window check?

Copy link
Contributor

Choose a reason for hiding this comment

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

The test itself is fine - it's the global.window code I think we can remove.

Since these tests run only in a server environment, global.window should already be undefined.


### `createAdminApiClient()` parameters

| Property | Type | Description |
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the README still needs to be updated regarding the new retries and logger features.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the names of the functions and types needs to be updated as well.

Copy link
Contributor

@paulomarg paulomarg left a comment

Choose a reason for hiding this comment

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

I think we're pretty close to done here!

| -------------- | ------------------------ | ---------------------------------------------------- |
| variables? | `Record<string, any>` | Variable values needed in the graphQL operation |
| apiVersion? | `string` | The Admin API version to use in the API request |
| customHeaders? | `{[key: string]: string}` | Customized headers to be included in the API request |
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering about this name - should it be just headers? At this point these are the only headers the app is deliberately sending, not sure if we need to say they're custom here.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could definitely change this - it's actually defined in a common ApiClient level type so I can change it there and have all the API clients use the same interface.

Copy link
Contributor

@melissaluu melissaluu Nov 9, 2023

Choose a reason for hiding this comment

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

@scottdixon - this should be updated on main now so when you rebase and run turbo build and turbo test, you should be able to get the latest graphql-client library types.

packages/admin-api-client/package.json Outdated Show resolved Hide resolved
".": {
"module": {
"types": "./dist/ts/index.d.ts",
"default": "./dist/index.mjs"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to have require entries for the CJS build? I think that would be the right setup here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's happening a few lines down - let me know if I'm missing something!

yarn.lock Outdated Show resolved Hide resolved
Copy link
Contributor

@melissaluu melissaluu left a comment

Choose a reason for hiding this comment

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

I have a few comments but none of them are critical and can be addressed in either this PR or follow up PRs.

Generally looking good! 👍

@paulomarg
Copy link
Contributor

I think other than the package.json stuff (that can be a follow up as long as it gets done), I'm ok with this going in too!

@scottdixon scottdixon marked this pull request as ready for review November 10, 2023 00:48
@scottdixon scottdixon requested a review from a team as a code owner November 10, 2023 00:48
@scottdixon scottdixon merged commit 9caf5f5 into main Nov 10, 2023
@scottdixon scottdixon deleted the sd-admin-client branch November 10, 2023 01:00
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.

3 participants