Skip to content

Commit

Permalink
Export missing exports for apollo-client
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 31, 2024
1 parent 0e92930 commit 4e03ea5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-meals-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphql.web': patch
---

Add missing exports to make apollo-client functional with this library
38 changes: 38 additions & 0 deletions src/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, it, expect } from 'vitest';

import { parse } from '../parser';
import { isSelectionNode, Source } from '../helpers';
import type { OperationDefinitionNode } from '../ast';

describe('helpers', () => {
it('Correctly indicates a selection-node', () => {
const parsed = parse(`
query {
field
... on Query { field }
...Frag
}
fragment Frag on Query { field }
`);

const operation = parsed.definitions[0] as OperationDefinitionNode;
expect(isSelectionNode(operation.selectionSet.selections[0])).toEqual(true);
expect(isSelectionNode(operation.selectionSet.selections[1])).toEqual(true);
expect(isSelectionNode(operation.selectionSet.selections[2])).toEqual(true);
});

it('Source is a function', () => {
expect(typeof Source).toEqual('function');
expect(Source('test')).toEqual({
body: 'test',
name: undefined,
locationOffset: { line: 1, column: 1 },
});
expect(Source('test', 'test', { line: 2, column: 1 })).toEqual({
body: 'test',
name: 'test',
locationOffset: { line: 2, column: 1 },
});
});
});
14 changes: 14 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Source, Location } from './types';
import type { ASTNode, SelectionNode } from './ast';

export function isSelectionNode(node: ASTNode): node is SelectionNode {
return node.kind === 'Field' || node.kind === 'FragmentSpread' || node.kind === 'InlineFragment';
}

export function Source(body: string, name?: string, locationOffset?: Location): Source {
return {
body,
name,
locationOffset: locationOffset || { line: 1, column: 1 },
};
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './parser';
export * from './visitor';
export * from './printer';
export * from './values';
export * from './helpers';

0 comments on commit 4e03ea5

Please sign in to comment.