From d2aa1d7a7610a53eb28afb47a141b6efd8ccc883 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 10 Jan 2024 21:53:52 +0000 Subject: [PATCH] Ditch duplicate fragment checks --- src/api.ts | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/api.ts b/src/api.ts index cfca536a..70cf9fe6 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,4 +1,4 @@ -import type { DocumentNode, DefinitionNode } from '@0no-co/graphql.web'; +import type { DocumentNode } from '@0no-co/graphql.web'; import { Kind, parse as _parse } from '@0no-co/graphql.web'; import type { @@ -61,30 +61,12 @@ function graphql< input: In, fragments?: Fragments ): getDocumentNode> { - const definitions = _parse(input).definitions as DefinitionNode[]; - const fragmentNames = new Map(); + const definitions = new Set(_parse(input).definitions); for (const document of fragments || []) { - for (const definition of document.definitions) { - if (definition.kind !== Kind.FRAGMENT_DEFINITION) { - /*noop*/ - } else if (!fragmentNames.has(definition.name.value)) { - fragmentNames.set(definition.name.value, definition); - definitions.push(definition); - } else if ( - process.env.NODE_ENV !== 'production' && - fragmentNames.get(definition.name.value) !== definition - ) { - // Fragments with the same names is expected to have the same contents - console.warn( - '[WARNING: Duplicate Fragment] A fragment with name `' + - definition.name.value + - '` already exists in this document.\n' + - 'While fragment names may not be unique across your source, each name must be unique per document.' - ); - } - } + for (const definition of document.definitions) + if (definition.kind === Kind.FRAGMENT_DEFINITION) definitions.add(definition); } - return { kind: Kind.DOCUMENT, definitions } as any; + return { kind: Kind.DOCUMENT, definitions: [...definitions] } as any; } /** A GraphQL `DocumentNode` with attached generics for its result data and variables.