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

Support Customer Account API in GraphiQL #1693

Merged
merged 12 commits into from
Jan 29, 2024
Merged

Support Customer Account API in GraphiQL #1693

merged 12 commits into from
Jan 29, 2024

Conversation

frandiox
Copy link
Contributor

Add support for multiple schemas in GraphiQL and a way to update schema automatically when changing tabs.
Open GraphiQL clicking on links from the Subrequest Profiler.

@frandiox frandiox requested a review from a team January 26, 2024 15:33

This comment has been minimized.

@@ -91,21 +91,42 @@ export function createCustomerAccountClient({
url.protocol === 'http:' ? url.origin.replace('http', 'https') : url.origin;
const redirectUri = authUrl.startsWith('/') ? origin + authUrl : authUrl;

const customerAccountApiUrl = `${customerAccountUrl}/account/customer/api/${customerApiVersion}/graphql`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I made a bunch of similar changes in #1684

Comment on lines +38 to +39
// CustomerAccount API does not support introspection to the same URL.
// Read it from a file using the asset server:
Copy link
Contributor

Choose a reason for hiding this comment

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

@s-lee-kwong Can we add introspection to the graphql end point?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is something we can look at but right now our only introspection point is something like

https://app.myshopify.com/services/graphql/introspection/customer?api_client_api_key=159a99b8a7289a72f68603f2f4de40ac&api_version=2024-01

but that api_key is from an app so I wouldn't use what I pasted exactly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GraphiQL can only work with 1 url for both introspection and queries. So if you want to add support for GraphiQL in CAAPI, the URL for queries should also provide introspection 🙏

Here we had to work around this issue by downloading the schema in a different way and providing it to GarphiQL in JSON format without doing introspection.

Copy link
Contributor

Choose a reason for hiding this comment

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

I will add this to the on going Friction Doc for the future.

Having the introspection and queries be at the same URL is a fairly standard way of implementation for GraphQL API. A lot of the tools work assuming this convention and it would be really good to have.

@@ -53,6 +53,8 @@ export type CustomerClient = {
handleAuthStatus: () => void | DataFunctionValue;
/** Returns CustomerAccessToken if the customer is logged in. It also run a expiry check and does a token refresh if needed. */
getAccessToken: () => Promise<string | undefined>;
/** Creates the fully-qualified URL to your store's GraphQL endpoint.*/
getApiUrl: () => string;
Copy link
Contributor

Choose a reason for hiding this comment

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

reminder to add this to the Doc type below as well

Copy link
Contributor

@michenly michenly left a comment

Choose a reason for hiding this comment

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

🎩 and it looks great! Just missing a type.

Screenshot 2024-01-26 at 1 01 56 PM

Slightly wonder if we should list out both Storefront API and Customer Account API in the UI with selected state or maybe a drop down? The interaction of tabbing on the text to switch API is not super clear to me.

Also future task! would love to bring in a documentation explore for the schema!

@frandiox
Copy link
Contributor Author

Slightly wonder if we should list out both Storefront API and Customer Account API in the UI with selected state or maybe a drop down? The interaction of tabbing on the text to switch API is not super clear to me.

Yeah absolutely. This was my original intention but adding the toggle next to the GraphiQL logo was much easier (we don't have JSX in this page 🙃 ).

Also future task! would love to bring in a documentation explore for the schema!

Do you mean this? We added it long ago! Or are you suggesting another plugin?

image

@frandiox
Copy link
Contributor Author

frandiox commented Jan 29, 2024

Slightly wonder if we should list out both Storefront API and Customer Account API in the UI with selected state or maybe a drop down? The interaction of tabbing on the text to switch API is not super clear to me.

Yeah absolutely. This was my original intention but adding the toggle next to the GraphiQL logo was much easier (we don't have JSX in this page 🙃 ).

Changed it to a toolbar button! I thought we had to add the whole existing toolbar manually but luckily it supports a additionalComponent prop:

image image

Also, it now stores the tab<>schema information in localStorage instead of using an in-query comment 🎉

@frandiox frandiox merged commit 0279878 into main Jan 29, 2024
10 checks passed
@frandiox frandiox deleted the fd-graphiql-caapi branch January 29, 2024 09:14
@michenly
Copy link
Contributor

Do you mean this? We added it long ago! Or are you suggesting another plugin?
Silly me! I just didnt find it!

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.

3 participants