From 6f2533bcf54d1ee07f899dcc9a740bb7b3424f45 Mon Sep 17 00:00:00 2001 From: Egor Lem <63231806+egorlem@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:59:53 +0300 Subject: [PATCH] Fix: Operation row and imports (#6) * Fix file imports * Fix reading operationName in OperationDefinition If you use query.refetch() then the order in the definitions array changes --- CHANGELOG.md | 0 package.json | 2 +- src/index.ts | 2 +- src/printerLink.ts | 4 ++-- src/rows/index.ts | 5 +++-- 5 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index 9aa5008..919a1a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-link-printer", - "version": "1.0.1", + "version": "1.0.2", "description": "Pretty logger of Apollo GraphQL network operations packaged in a Apollo link", "type": "module", "scripts": { diff --git a/src/index.ts b/src/index.ts index 71e6632..c54f163 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export { PrinterLink } from './printerLink'; +export { PrinterLink } from './printerLink.js'; diff --git a/src/printerLink.ts b/src/printerLink.ts index e9a963a..5efc4fe 100644 --- a/src/printerLink.ts +++ b/src/printerLink.ts @@ -1,6 +1,6 @@ import { ApolloLink, NextLink, Operation } from '@apollo/client'; -import { fragmentRow, messageRow, operationRow, variablesRow } from './rows'; -import { TLinkOptions } from './printerLink.types'; +import { fragmentRow, messageRow, operationRow, variablesRow } from './rows/index.js'; +import { TLinkOptions } from './printerLink.types.js'; const prepareSubrows = (operation: Operation) => { const result = { diff --git a/src/rows/index.ts b/src/rows/index.ts index 33bc704..2186726 100644 --- a/src/rows/index.ts +++ b/src/rows/index.ts @@ -67,8 +67,9 @@ export const fragmentRow = ({ query: { definitions } }: Operation) => { * @param {Operation} operation */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -export const operationRow = ({ query: { definitions }, operationName }: Operation | any) => { - const [{ operation: operationType }] = definitions; +export const operationRow = ({ query: { definitions = [] }, operationName }: Operation | any) => { + const definition = definitions.find(({ kind }) => kind === 'OperationDefinition'); + const operationType = definition.operation || 'unknown' return [ `%c ${operationType.toUpperCase()} %c ${operationName}`,