Mirror: The spec-compliant minimum of client-side GraphQL.
1import { describe, it, expect } from 'vitest'; 2 3import { parse } from '../parser'; 4import { isSelectionNode, Source } from '../helpers'; 5import type { OperationDefinitionNode } from '../ast'; 6 7describe('helpers', () => { 8 it('Correctly indicates a selection-node', () => { 9 const parsed = parse(` 10 query { 11 field 12 ... on Query { field } 13 ...Frag 14 } 15 16 fragment Frag on Query { field } 17 `); 18 19 const operation = parsed.definitions[0] as OperationDefinitionNode; 20 expect(isSelectionNode(operation.selectionSet.selections[0])).toEqual(true); 21 expect(isSelectionNode(operation.selectionSet.selections[1])).toEqual(true); 22 expect(isSelectionNode(operation.selectionSet.selections[2])).toEqual(true); 23 }); 24 25 it('Source is a function', () => { 26 expect(typeof Source).toEqual('function'); 27 expect(Source('test')).toEqual({ 28 body: 'test', 29 name: undefined, 30 locationOffset: { line: 1, column: 1 }, 31 }); 32 expect(Source('test', 'test', { line: 2, column: 1 })).toEqual({ 33 body: 'test', 34 name: 'test', 35 locationOffset: { line: 2, column: 1 }, 36 }); 37 }); 38});