Skip to content

Commit

Permalink
Fix type dependence in formatDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Mar 24, 2023
1 parent af2ef5a commit c8d6e2b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/utils/typenames.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Kind, SelectionNode, DefinitionNode } from '@0no-co/graphql.web';
import type { DocumentNode } from './graphql';
import { KeyedDocumentNode, keyDocument } from './request';
import { TypedDocumentNode } from '../types';

interface EntityLike {
[key: string]: EntityLike | EntityLike[] | any;
Expand Down Expand Up @@ -33,7 +33,9 @@ export const collectTypesFromResponse = (response: object): string[] => [
...collectTypes(response as EntityLike, new Set()),
];

const formatNode = <T extends SelectionNode | DefinitionNode | DocumentNode>(
const formatNode = <
T extends SelectionNode | DefinitionNode | TypedDocumentNode<any, any>
>(
node: T
): T => {
let hasChanged = false;
Expand Down Expand Up @@ -98,7 +100,9 @@ const formattedDocs = new Map<number, KeyedDocumentNode>();
* @see {@link https://spec.graphql.org/October2021/#sec-Type-Name-Introspection} for more information
* on typename introspection via the `__typename` field.
*/
export const formatDocument = <T extends DocumentNode>(node: T): T => {
export const formatDocument = <T extends TypedDocumentNode<any, any>>(
node: T
): T => {
const query = keyDocument(node);

let result = formattedDocs.get(query.__key);
Expand Down

0 comments on commit c8d6e2b

Please sign in to comment.