-
Notifications
You must be signed in to change notification settings - Fork 147
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
Add generic cache for graphQL querys (as opt-in per query) #5343
Draft
isaacroldan
wants to merge
1
commit into
main
Choose a base branch
from
graphql-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+159
−15
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isaacroldan
changed the title
Add generic cache support for any graphQL query
Add generic cache for any graphQL query (as opt-in per query)
Feb 3, 2025
isaacroldan
changed the title
Add generic cache for any graphQL query (as opt-in per query)
Add generic cache for graphQL querys (as opt-in per query)
Feb 3, 2025
Coverage report
Show files with reduced coverage 🔻
Test suite run success2035 tests passing in 909 suites. Report generated by 🧪jest coverage report action from 5f488a1 |
isaacroldan
force-pushed
the
graphql-cache
branch
from
February 3, 2025 14:42
b24ac3d
to
5f488a1
Compare
isaacroldan
force-pushed
the
graphql-cache
branch
from
February 3, 2025 15:48
5f488a1
to
162fead
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/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@@ -9,6 +9,11 @@ export interface GraphQLVariables {
[key: string]: any;
}
export type GraphQLResponse<T> = Awaited<ReturnType<typeof rawRequest<T>>>;
+export interface CacheOptions {
+ cacheTTL?: CacheTTL;
+ cacheExtraKey?: string;
+}
+export type CacheTTL = '1h' | '6h' | '12h' | '1d' | '3d' | '7d' | '14d' | '30d';
interface GraphQLRequestBaseOptions<TResult> {
api: string;
url: string;
@@ -17,6 +22,8 @@ interface GraphQLRequestBaseOptions<TResult> {
[header: string]: string;
};
responseOptions?: GraphQLResponseOptions<TResult>;
+ cacheTTL?: CacheTTL;
+ cacheExtraKey?: string;
}
export type GraphQLRequestOptions<T> = GraphQLRequestBaseOptions<T> & {
query: RequestDocument;
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WHY are these changes introduced?
Improve performance by adding caching capabilities to GraphQL requests in the CLI.
WHAT is this pull request doing?
Adds caching support for GraphQL requests with configurable TTL options ranging from 1 hour to 30 days. The cache implementation:
cacheTTL
andcacheExtraKey
parameters to GraphQL request functionsHow to test your changes?
NOTE: The cache is not enabled right now for any existing query, that will happen in the following PR
Measuring impact
Checklist