Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/__fixtures__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ export const bigSchemaSDL = readLocalFile('github-schema.graphql');
export const bigSchemaIntrospectionResult = JSON.parse(
readLocalFile('github-schema.json'),
);

export const kitchenSinkSDL = readLocalFile('schema-kitchen-sink.graphql');
export const kitchenSinkQuery = readLocalFile('kitchen-sink.graphql');
9 changes: 2 additions & 7 deletions src/language/__tests__/parser-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@
* @flow strict
*/

import { join } from 'path';
import { readFileSync } from 'fs';
import { kitchenSinkQuery } from '../../__fixtures__';
import { parse } from '../parser';

const kitchenSink = readFileSync(join(__dirname, '/kitchen-sink.graphql'), {
encoding: 'utf8',
});

export const name = 'Parse kitchen sink';
export function measure() {
parse(kitchenSink);
parse(kitchenSinkQuery);
}
11 changes: 3 additions & 8 deletions src/language/__tests__/parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
*/

import { inspect as nodeInspect } from 'util';
import { readFileSync } from 'fs';
import { join } from 'path';

import { Kind } from '../kinds';
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { Kind } from '../kinds';
import { TokenKind } from '../lexer';
import { parse, parseValue, parseType } from '../parser';
import { Source } from '../source';
import dedent from '../../jsutils/dedent';
import inspect from '../../jsutils/inspect';
import toJSONDeep from './toJSONDeep';
import { kitchenSinkQuery } from '../../__fixtures__';

function expectSyntaxError(text, message, location) {
expect(() => parse(text))
Expand Down Expand Up @@ -145,12 +144,8 @@ describe('Parser', () => {
);
});

const kitchenSink = readFileSync(join(__dirname, '/kitchen-sink.graphql'), {
encoding: 'utf8',
});

it('parses kitchen sink', () => {
expect(() => parse(kitchenSink)).to.not.throw();
expect(() => parse(kitchenSinkQuery)).to.not.throw();
});

it('allows non-keywords anywhere a Name is allowed', () => {
Expand Down
13 changes: 3 additions & 10 deletions src/language/__tests__/printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { parse } from '../parser';
import { readFileSync } from 'fs';
import { print } from '../printer';
import { join } from 'path';
import dedent from '../../jsutils/dedent';
import { kitchenSinkQuery } from '../../__fixtures__';

describe('Printer: Query document', () => {
const kitchenSink = readFileSync(join(__dirname, '/kitchen-sink.graphql'), {
encoding: 'utf8',
});

it('does not alter ast', () => {
const ast = parse(kitchenSink);
const ast = parse(kitchenSinkQuery);
const astBefore = JSON.stringify(ast);
print(ast);
expect(JSON.stringify(ast)).to.equal(astBefore);
Expand Down Expand Up @@ -168,9 +163,7 @@ describe('Printer: Query document', () => {
});

it('prints kitchen sink', () => {
const ast = parse(kitchenSink);

const printed = print(ast);
const printed = print(parse(kitchenSinkQuery));

expect(printed).to.equal(
dedent(String.raw`
Expand Down
5 changes: 5 additions & 0 deletions src/language/__tests__/schema-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { describe, it } from 'mocha';
import dedent from '../../jsutils/dedent';
import { parse } from '../parser';
import toJSONDeep from './toJSONDeep';
import { kitchenSinkSDL } from '../../__fixtures__';

function expectSyntaxError(text, message, location) {
expect(() => parse(text))
Expand Down Expand Up @@ -823,6 +824,10 @@ input Hello {
);
});

it('parses kitchen sink schema', () => {
expect(() => parse(kitchenSinkSDL)).to.not.throw();
});

it('Option: allowLegacySDLEmptyFields supports type with empty fields', () => {
const body = 'type Hello { }';
expect(() => parse(body)).to.throw('Syntax Error: Expected Name, found }');
Expand Down
14 changes: 3 additions & 11 deletions src/language/__tests__/schema-printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

import { expect } from 'chai';
import { describe, it } from 'mocha';
import { readFileSync } from 'fs';
import { join } from 'path';
import { parse } from '../parser';
import { print } from '../printer';
import dedent from '../../jsutils/dedent';
import { kitchenSinkSDL } from '../../__fixtures__';

describe('Printer: SDL document', () => {
it('prints minimal ast', () => {
Expand All @@ -31,22 +30,15 @@ describe('Printer: SDL document', () => {
);
});

const kitchenSink = readFileSync(
join(__dirname, '/schema-kitchen-sink.graphql'),
{ encoding: 'utf8' },
);

it('does not alter ast', () => {
const ast = parse(kitchenSink);
const ast = parse(kitchenSinkSDL);
const astBefore = JSON.stringify(ast);
print(ast);
expect(JSON.stringify(ast)).to.equal(astBefore);
});

it('prints kitchen sink', () => {
const ast = parse(kitchenSink);

const printed = print(ast);
const printed = print(parse(kitchenSinkSDL));

expect(printed).to.equal(dedent`
schema {
Expand Down
9 changes: 2 additions & 7 deletions src/language/__tests__/visitor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';
import { parse } from '../parser';
import { print } from '../printer';
import { readFileSync } from 'fs';
import { visit, visitInParallel, visitWithTypeInfo, BREAK } from '../visitor';
import { join } from 'path';
import { TypeInfo } from '../../utilities/TypeInfo';
import { testSchema } from '../../validation/__tests__/harness';
import { getNamedType, isCompositeType } from '../../type';
import { Kind } from '../kinds';
import { kitchenSinkQuery } from '../../__fixtures__';

function getNodeByPath(ast, path) {
let result = ast;
Expand Down Expand Up @@ -464,11 +463,7 @@ describe('Visitor', () => {
});

it('visits kitchen sink', () => {
const kitchenSink = readFileSync(join(__dirname, '/kitchen-sink.graphql'), {
encoding: 'utf8',
});
const ast = parse(kitchenSink);

const ast = parse(kitchenSinkQuery);
const visited = [];

visit(ast, {
Expand Down