-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Cache some queries for 6 hours #5345
base: graphql-cache
Are you sure you want to change the base?
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
We detected some changes at packages/*/src and there are no updates in the .changeset. |
Coverage report
Test suite run success2040 tests passing in 911 suites. Report generated by 🧪jest coverage report action from de4ea1c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lack of tests for this class I think is getting to be untenable, I think its gone beyond connecting straight to the APIs. Maybe its time to improve this.
/snapit |
🫰✨ Thanks @shauns! Your snapshot has been published to npm. Test the snapshot by intalling your package globally: pnpm i -g @shopify/cli@0.0.0-snapshot-20250203173903
|
c7d964b
to
b435b3d
Compare
eeb8b2a
to
de4ea1c
Compare
@@ -174,7 +174,10 @@ export class AppManagementClient implements DeveloperPlatformClient { | |||
const tokenResult = await ensureAuthenticatedAppManagementAndBusinessPlatform() | |||
const {appManagementToken, businessPlatformToken, userId} = tokenResult | |||
|
|||
const userInfoResult = await businessPlatformRequestDoc(UserInfo, businessPlatformToken) | |||
const userInfoResult = await businessPlatformRequestDoc(UserInfo, businessPlatformToken, undefined, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example of my comment from the other PR in the stack. Is every caller of session
OK with a 6hr TTL? How can we know this without having more context of the caller and how they use the values on the session? Will every future caller of session be ok with a 6hr TTL?
(should the TTL be passed into this method too?)
b435b3d
to
2da6001
Compare
de4ea1c
to
0070e0d
Compare
2da6001
to
dabf62d
Compare
0070e0d
to
d0a4778
Compare
dabf62d
to
902d552
Compare
d0a4778
to
47bc8ab
Compare
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/cli.d.ts@@ -31,6 +31,7 @@ export declare function runCreateCLI(options: RunCLIOptions, launchCLI?: (option
export declare const globalFlags: {
'no-color': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
verbose: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
+ 'no-cache': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
};
export declare const jsonFlag: {
json: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
packages/cli-kit/dist/private/node/conf-store.d.ts@@ -7,15 +7,17 @@ export type IntrospectionUrlKey = ;
export type PackageVersionKey = ;
export type NotificationsKey = ;
export type NotificationKey = ;
+export type GraphQLRequestKey = ;
type MostRecentOccurrenceKey = ;
type RateLimitKey = ;
-type ExportedKey = IntrospectionUrlKey | PackageVersionKey | NotificationsKey | NotificationKey;
+type ExportedKey = IntrospectionUrlKey | PackageVersionKey | NotificationsKey | NotificationKey | GraphQLRequestKey;
interface Cache {
[introspectionUrlKey: IntrospectionUrlKey]: CacheValue<string>;
[packageVersionKey: PackageVersionKey]: CacheValue<string>;
[notifications: NotificationsKey]: CacheValue<string>;
[notification: NotificationKey]: CacheValue<string>;
- [MostRecentOccurrenceKey: MostRecentOccurrenceKey]: CacheValue<boolean>;
+ [graphQLRequestKey: GraphQLRequestKey]: CacheValue<string>;
+ [mostRecentOccurrenceKey: MostRecentOccurrenceKey]: CacheValue<boolean>;
[rateLimitKey: RateLimitKey]: CacheValue<number[]>;
}
export interface ConfSchema {
packages/cli-kit/dist/public/node/api/app-management.d.ts@@ -1,4 +1,4 @@
-import { GraphQLResponse } from './graphql.js';
+import { CacheOptions, GraphQLResponse } from './graphql.js';
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
import { Variables } from 'graphql-request';
/**
@@ -8,9 +8,10 @@ import { Variables } from 'graphql-request';
* @param query - GraphQL query to execute.
* @param token - Partners token.
* @param variables - GraphQL variables to pass to the query.
+ * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.
* @returns The response of the query of generic type <T>.
*/
-export declare function appManagementRequestDoc<TResult, TVariables extends Variables>(orgId: string, query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables): Promise<TResult>;
+export declare function appManagementRequestDoc<TResult, TVariables extends Variables>(orgId: string, query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, cacheOptions?: CacheOptions): Promise<TResult>;
/**
* Sets the next deprecation date from [GraphQL response extensions](https://www.apollographql.com/docs/resources/graphql-glossary/#extensions)
* if objects contain a (ISO 8601-formatted string).
packages/cli-kit/dist/public/node/api/business-platform.d.ts@@ -1,4 +1,4 @@
-import { Exact, GraphQLVariables } from './graphql.js';
+import { CacheOptions, Exact, GraphQLVariables } from './graphql.js';
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
import { Variables } from 'graphql-request';
/**
@@ -7,18 +7,20 @@ import { Variables } from 'graphql-request';
* @param query - GraphQL query to execute.
* @param token - Business Platform token.
* @param variables - GraphQL variables to pass to the query.
+ * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.
* @returns The response of the query of generic type <T>.
*/
-export declare function businessPlatformRequest<T>(query: string, token: string, variables?: GraphQLVariables): Promise<T>;
+export declare function businessPlatformRequest<T>(query: string, token: string, variables?: GraphQLVariables, cacheOptions?: CacheOptions): Promise<T>;
/**
* Executes a GraphQL query against the Business Platform Destinations API. Uses typed documents.
*
* @param query - GraphQL query to execute.
* @param token - Business Platform token.
* @param variables - GraphQL variables to pass to the query.
+ * @param cacheOptions - Cache options for the request. If not present, the request will not be cached.
* @returns The response of the query of generic type <TResult>.
*/
-export declare function businessPlatformRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables): Promise<TResult>;
+export declare function businessPlatformRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables, cacheOptions?: CacheOptions): Promise<TResult>;
/**
* Executes a GraphQL query against the Business Platform Organizations API.
*
packages/cli-kit/dist/public/node/api/graphql.d.ts@@ -1,3 +1,5 @@
+import { ConfSchema } from '../../../private/node/conf-store.js';
+import { LocalStorage } from '../local-storage.js';
import { rawRequest, RequestDocument, Variables } from 'graphql-request';
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
export type Exact<T extends {
@@ -9,6 +11,12 @@ export interface GraphQLVariables {
[key: string]: any;
}
export type GraphQLResponse<T> = Awaited<ReturnType<typeof rawRequest<T>>>;
+export interface CacheOptions {
+ cacheTTL: CacheTTL;
+ cacheExtraKey?: string;
+ cacheStore?: LocalStorage<ConfSchema>;
+}
+export type CacheTTL = number;
interface GraphQLRequestBaseOptions<TResult> {
api: string;
url: string;
@@ -17,6 +25,7 @@ interface GraphQLRequestBaseOptions<TResult> {
[header: string]: string;
};
responseOptions?: GraphQLResponseOptions<TResult>;
+ cacheOptions?: CacheOptions;
}
export type GraphQLRequestOptions<T> = GraphQLRequestBaseOptions<T> & {
query: RequestDocument;
|
WHY are these changes introduced?
Start using the new cache system for some queries that are run frequently and where the output doesn't change that often.
WHAT is this pull request doing?
Adds caching with a 6-hour TTL to several GraphQL queries:
How to test your changes?
/Users/<YOUR_USER>/Library/Preferences/shopify-cli-kit-nodejs/config.json
and modify the timestamp to force expiration)Measuring impact
How do we know this change was effective? Please choose one:
Checklist