-
Notifications
You must be signed in to change notification settings - Fork 110
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
Automatic GraphQL code generation #4048
Conversation
Loads from partners and business platform destination APIs
Examples are provided for: - a partners query and mutation - a BP query
We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset. |
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success1695 tests passing in 793 suites. Report generated by 🧪jest coverage report action from 7c627c2 |
export default { | ||
projects: { | ||
partners: projectFactory('partners', 'cli_schema.graphql'), | ||
businessPlatform: projectFactory('business-platform', 'destinations_schema.graphql'), |
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.
Do you need to include also the new app-management API? that's different than business-platform right?
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.
Tested by migrating a query myself, it works perfectly, process is easy 👌
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/api/business-platform.d.ts@@ -1,4 +1,6 @@
import { GraphQLVariables } from './graphql.js';
+import { TypedDocumentNode } from '@graphql-typed-document-node/core';
+import { Variables } from 'graphql-request';
/**
* Executes a GraphQL query against the Business Platform Destinations API.
*
@@ -7,4 +9,13 @@ import { GraphQLVariables } from './graphql.js';
* @param variables - GraphQL variables to pass to the query.
* @returns The response of the query of generic type <T>.
*/
-export declare function businessPlatformRequest<T>(query: string, token: string, variables?: GraphQLVariables): Promise<T>;
\ No newline at end of file
+export declare function businessPlatformRequest<T>(query: string, token: string, variables?: GraphQLVariables): 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.
+ * @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>;
\ No newline at end of file
packages/cli-kit/dist/public/node/api/graphql.d.ts@@ -1,19 +1,26 @@
import { rawRequest, RequestDocument, Variables } from 'graphql-request';
+import { TypedDocumentNode } from '@graphql-typed-document-node/core';
export interface GraphQLVariables {
[key: string]: any;
}
export type GraphQLResponse<T> = Awaited<ReturnType<typeof rawRequest<T>>>;
-export interface GraphQLRequestOptions<T> {
- query: RequestDocument;
+interface GraphQLRequestBaseOptions<TResult> {
api: string;
url: string;
token?: string;
addedHeaders?: {
[header: string]: string;
};
- variables?: Variables;
- responseOptions?: GraphQLResponseOptions<T>;
+ responseOptions?: GraphQLResponseOptions<TResult>;
}
+export type GraphQLRequestOptions<T> = GraphQLRequestBaseOptions<T> & {
+ query: RequestDocument;
+ variables?: Variables;
+};
+export type GraphQLRequestDocOptions<TResult, TVariables> = GraphQLRequestBaseOptions<TResult> & {
+ query: TypedDocumentNode<TResult, TVariables>;
+ variables?: TVariables;
+};
export interface GraphQLResponseOptions<T> {
handleErrors?: boolean;
onResponse?: (response: GraphQLResponse<T>) => void;
@@ -24,4 +31,12 @@ export interface GraphQLResponseOptions<T> {
* @param options - GraphQL request options.
* @returns The response of the query of generic type <T>.
*/
-export declare function graphqlRequest<T>(options: GraphQLRequestOptions<T>): Promise<T>;
\ No newline at end of file
+export declare function graphqlRequest<T>(options: GraphQLRequestOptions<T>): Promise<T>;
+/**
+ * Executes a GraphQL query to an endpoint. Uses typed documents.
+ *
+ * @param options - GraphQL request options.
+ * @returns The response of the query of generic type <TResult>.
+ */
+export declare function graphqlRequestDoc<TResult, TVariables extends Variables>(options: GraphQLRequestDocOptions<TResult, TVariables>): Promise<TResult>;
+export {};
\ No newline at end of file
packages/cli-kit/dist/public/node/api/partners.d.ts@@ -1,4 +1,6 @@
import { GraphQLVariables, GraphQLResponse } from './graphql.js';
+import { TypedDocumentNode } from '@graphql-typed-document-node/core';
+import { Variables } from 'graphql-request';
/**
* Executes a GraphQL query against the Partners API.
*
@@ -8,6 +10,15 @@ import { GraphQLVariables, GraphQLResponse } from './graphql.js';
* @returns The response of the query of generic type <T>.
*/
export declare function partnersRequest<T>(query: string, token: string, variables?: GraphQLVariables): Promise<T>;
+/**
+ * Executes a GraphQL query against the Partners API. Uses typed documents.
+ *
+ * @param query - GraphQL query to execute.
+ * @param token - Partners token.
+ * @param variables - GraphQL variables to pass to the query.
+ * @returns The response of the query of generic type <TResult>.
+ */
+export declare function partnersRequestDoc<TResult, TVariables extends Variables>(query: TypedDocumentNode<TResult, TVariables>, token: string, variables?: TVariables): Promise<TResult>;
export interface FunctionUploadUrlGenerateResponse {
functionUploadUrlGenerate: {
generatedUrlDetails: {
|
WHY are these changes introduced?
Fixes a long-standing issue: the types for GraphQL results and variables, as well as the content of the queries/mutations themselves, were manually specified and not automatically tested.
WHAT is this pull request doing?
🆕 The main addition here is
p graphql-codegen
. This takes.graphql
documents (containing a query/mutation that we use) and:✨ It also provides auto-complete and in-editor validation & documentation when writing queries in VS Code.
🚨 generated types are accurate vs. the schema, which means they can and will find snags the hand-crafted types didn't. improved quality is a good thing! but as more queries switch to this method, more fixes will be needed.
💁♂️ Some implementation notes:
dev up
internallygraphql-codegen
has been run prior to commits that do change queries.❓ I've converted a few queries in the scope of this PR. Should the rest be converted now? Or can we do that in a follow up?
How to test your changes?
CI does most of the testing here. Perhaps the thing to try is to migrate a query/mutation to this format: see how easy/ergonomic it is, what errors it finds, etc.
Measuring impact
How do we know this change was effective? Please choose one:
Checklist
dev
ordeploy
have been reflected in the internal flowchart.