Skip to content

Commit

Permalink
Fix: Operation row and imports (#6)
Browse files Browse the repository at this point in the history
* Fix file imports

* Fix reading operationName in OperationDefinition

If you use query.refetch() then the order in the definitions array changes
  • Loading branch information
egorlem authored Nov 14, 2024
1 parent 208b06d commit 6f2533b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
Empty file added CHANGELOG.md
Empty file.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { PrinterLink } from './printerLink';
export { PrinterLink } from './printerLink.js';
4 changes: 2 additions & 2 deletions src/printerLink.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
5 changes: 3 additions & 2 deletions src/rows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down

0 comments on commit 6f2533b

Please sign in to comment.