From e896a0fd70aa7cd36be128b4aeccde78ffd98d85 Mon Sep 17 00:00:00 2001 From: beerose Date: Wed, 8 Mar 2023 16:37:47 +0100 Subject: [PATCH 1/5] Add TypedDocumentString and DocumentTypeDecoration helper --- packages/core/src/index.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 7a0c1b5..203359a 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,17 +1,23 @@ import type { DocumentNode } from "graphql"; -export interface TypedDocumentNode< - Result = { [key: string]: any }, - Variables = { [key: string]: any } -> extends DocumentNode { +export interface DocumentTypeDecoration { /** * This type is used to ensure that the variables you pass in to the query are assignable to Variables * and that the Result is assignable to whatever you pass your result to. The method is never actually * implemented, but the type is valid because we list it as optional */ - __apiType?: (variables: Variables) => Result; + __apiType?: (variables: TVariables) => TResult; } +export interface TypedDocumentNode< + TResult = { [key: string]: any }, + TVariables = { [key: string]: any } +> extends DocumentNode, + DocumentTypeDecoration {} + +export type TypedDocumentString = string & + DocumentTypeDecoration; + /** * Helper for extracting a TypeScript type for operation result from a TypedDocumentNode. * @example From 975d9d280a711a66e50ba2c0b70c1278d076ce3f Mon Sep 17 00:00:00 2001 From: beerose Date: Wed, 8 Mar 2023 16:40:37 +0100 Subject: [PATCH 2/5] Changeset --- .changeset/lovely-ghosts-suffer.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lovely-ghosts-suffer.md diff --git a/.changeset/lovely-ghosts-suffer.md b/.changeset/lovely-ghosts-suffer.md new file mode 100644 index 0000000..3ff31a7 --- /dev/null +++ b/.changeset/lovely-ghosts-suffer.md @@ -0,0 +1,5 @@ +--- +"@graphql-typed-document-node/core": minor +--- + +Add TypedDocumentString type From bd39199bd20b87b0a8cabab47bbcd9c195af77c9 Mon Sep 17 00:00:00 2001 From: beerose Date: Fri, 10 Mar 2023 12:26:15 +0100 Subject: [PATCH 3/5] Fix ResultOf and VariablesOf definitions --- packages/core/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 203359a..7bf4373 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -19,12 +19,12 @@ export type TypedDocumentString = string & DocumentTypeDecoration; /** - * Helper for extracting a TypeScript type for operation result from a TypedDocumentNode. + * Helper for extracting a TypeScript type for operation result from a TypedDocumentNode and TypedDocumentString. * @example * const myQuery = { ... }; // TypedDocumentNode * type ResultType = ResultOf; // Now it's R */ -export type ResultOf = T extends TypedDocumentNode< +export type ResultOf = T extends DocumentTypeDecoration< infer ResultType, infer VariablesType > @@ -32,12 +32,12 @@ export type ResultOf = T extends TypedDocumentNode< : never; /** - * Helper for extracting a TypeScript type for operation variables from a TypedDocumentNode. + * Helper for extracting a TypeScript type for operation variables from a TypedDocumentNode and TypedDocumentString. * @example * const myQuery = { ... }; // TypedDocumentNode * type VariablesType = VariablesOf; // Now it's V */ -export type VariablesOf = T extends TypedDocumentNode< +export type VariablesOf = T extends DocumentTypeDecoration< infer ResultType, infer VariablesType > From 930ed97ca58fab1acb668c6b247d5508e0acc3f5 Mon Sep 17 00:00:00 2001 From: beerose Date: Tue, 14 Mar 2023 17:14:25 +0100 Subject: [PATCH 4/5] Remove TypedDocumentString --- packages/core/src/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 7bf4373..60e73a4 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -15,9 +15,6 @@ export interface TypedDocumentNode< > extends DocumentNode, DocumentTypeDecoration {} -export type TypedDocumentString = string & - DocumentTypeDecoration; - /** * Helper for extracting a TypeScript type for operation result from a TypedDocumentNode and TypedDocumentString. * @example From aafb8c1921fbc3eabfa9f5dfae2144b9d60848f2 Mon Sep 17 00:00:00 2001 From: beerose Date: Tue, 14 Mar 2023 17:15:42 +0100 Subject: [PATCH 5/5] Update changeset --- .changeset/lovely-ghosts-suffer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/lovely-ghosts-suffer.md b/.changeset/lovely-ghosts-suffer.md index 3ff31a7..2ed22d4 100644 --- a/.changeset/lovely-ghosts-suffer.md +++ b/.changeset/lovely-ghosts-suffer.md @@ -2,4 +2,4 @@ "@graphql-typed-document-node/core": minor --- -Add TypedDocumentString type +Export `DocumentTypeDecoration` interface with `__apiType` key so that it can be used to extend types other than `DocumentNode`