Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeInfo-test: remove dependency on harness schema for validation tests #3175

Merged
merged 1 commit into from
Jun 14, 2021
Merged
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
48 changes: 43 additions & 5 deletions src/utilities/__tests__/TypeInfo-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,57 @@ import { parse, parseValue } from '../../language/parser';
import { print } from '../../language/printer';
import { visit } from '../../language/visitor';

import { GraphQLSchema } from '../../type/schema';
import { getNamedType, isCompositeType } from '../../type/definition';

import { buildSchema } from '../buildASTSchema';
import { TypeInfo, visitWithTypeInfo } from '../TypeInfo';

import { testSchema } from '../../validation/__tests__/harness';
const testSchema = buildSchema(`
interface Pet {
name: String
}

type Dog implements Pet {
name: String
}

type Cat implements Pet {
name: String
}

type Human {
name: String
pets: [Pet]
}

type Alien {
name(surname: Boolean): String
}

type QueryRoot {
human(id: ID): Human
alien: Alien
}

schema {
query: QueryRoot
}
`);

describe('TypeInfo', () => {
const schema = new GraphQLSchema({});

it('can be Object.toStringified', () => {
const typeInfo = new TypeInfo(testSchema);
const typeInfo = new TypeInfo(schema);

expect(Object.prototype.toString.call(typeInfo)).to.equal(
'[object TypeInfo]',
);
});

it('allow all methods to be called before entering any node', () => {
const typeInfo = new TypeInfo(testSchema);
const typeInfo = new TypeInfo(schema);

expect(typeInfo.getType()).to.equal(undefined);
expect(typeInfo.getParentType()).to.equal(undefined);
Expand Down Expand Up @@ -316,11 +349,16 @@ describe('visitWithTypeInfo', () => {
});

it('supports traversals of input values', () => {
const schema = buildSchema(`
input ComplexInput {
stringListField: [String]
}
`);
const ast = parseValue('{ stringListField: ["foo"] }');
const complexInputType = testSchema.getType('ComplexInput');
const complexInputType = schema.getType('ComplexInput');
invariant(complexInputType != null);

const typeInfo = new TypeInfo(testSchema, complexInputType);
const typeInfo = new TypeInfo(schema, complexInputType);

const visited: Array<any> = [];
visit(
Expand Down