Mirror: The spec-compliant minimum of client-side GraphQL.

Export missing exports for apollo-client (#39)

Changed files
+58
.changeset
src
+5
.changeset/yellow-meals-fix.md
···
+
---
+
'@0no-co/graphql.web': patch
+
---
+
+
Add missing exports to make apollo-client functional with this library
+38
src/__tests__/helpers.test.ts
···
+
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
src/helpers.ts
···
+
import type { 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) {
+
return {
+
body,
+
name,
+
locationOffset: locationOffset || { line: 1, column: 1 },
+
};
+
}
+1
src/index.ts
···
export * from './visitor';
export * from './printer';
export * from './values';
+
export * from './helpers';