Skip to content

Commit

Permalink
starWarsIntrospection-test: cleanup + add explanation comment (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Aug 13, 2019
1 parent cd9fc8e commit d9f959e
Showing 1 changed file with 84 additions and 134 deletions.
218 changes: 84 additions & 134 deletions src/__tests__/starWarsIntrospection-test.js
Expand Up @@ -7,152 +7,126 @@ import { graphqlSync } from '../graphql';

import { StarWarsSchema } from './starWarsSchema';

function queryStarWars(source) {
const result = graphqlSync({ schema: StarWarsSchema, source });
expect(Object.keys(result)).to.deep.equal(['data']);
return result.data;
}

describe('Star Wars Introspection Tests', () => {
describe('Basic Introspection', () => {
it('Allows querying the schema for types', () => {
const query = `
query IntrospectionTypeQuery {
const data = queryStarWars(`
{
__schema {
types {
name
}
}
}
`;
const expected = {
`);

// Include all types used by StarWars schema, introspection types and
// standard directives. For example, `Boolean` is used in `@skip`,
// `@include` and also inside introspection types.
expect(data).to.deep.equal({
__schema: {
types: [
{
name: 'Query',
},
{
name: 'Episode',
},
{
name: 'Character',
},
{
name: 'String',
},
{
name: 'Human',
},
{
name: 'Droid',
},
{
name: '__Schema',
},
{
name: '__Type',
},
{
name: '__TypeKind',
},
{
name: 'Boolean',
},
{
name: '__Field',
},
{
name: '__InputValue',
},
{
name: '__EnumValue',
},
{
name: '__Directive',
},
{
name: '__DirectiveLocation',
},
{ name: 'Query' },
{ name: 'Episode' },
{ name: 'Character' },
{ name: 'String' },
{ name: 'Human' },
{ name: 'Droid' },
{ name: '__Schema' },
{ name: '__Type' },
{ name: '__TypeKind' },
{ name: 'Boolean' },
{ name: '__Field' },
{ name: '__InputValue' },
{ name: '__EnumValue' },
{ name: '__Directive' },
{ name: '__DirectiveLocation' },
],
},
};
const result = graphqlSync(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('Allows querying the schema for query type', () => {
const query = `
query IntrospectionQueryTypeQuery {
const data = queryStarWars(`
{
__schema {
queryType {
name
}
}
}
`;
const expected = {
`);

expect(data).to.deep.equal({
__schema: {
queryType: {
name: 'Query',
},
},
};
const result = graphqlSync(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('Allows querying the schema for a specific type', () => {
const query = `
query IntrospectionDroidTypeQuery {
const data = queryStarWars(`
{
__type(name: "Droid") {
name
}
}
`;
const expected = {
`);

expect(data).to.deep.equal({
__type: {
name: 'Droid',
},
};
const result = graphqlSync(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('Allows querying the schema for an object kind', () => {
const query = `
query IntrospectionDroidKindQuery {
const data = queryStarWars(`
{
__type(name: "Droid") {
name
kind
}
}
`;
const expected = {
`);

expect(data).to.deep.equal({
__type: {
name: 'Droid',
kind: 'OBJECT',
},
};
const result = graphqlSync(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('Allows querying the schema for an interface kind', () => {
const query = `
query IntrospectionCharacterKindQuery {
const data = queryStarWars(`
{
__type(name: "Character") {
name
kind
}
}
`;
const expected = {
`);

expect(data).to.deep.equal({
__type: {
name: 'Character',
kind: 'INTERFACE',
},
};
const result = graphqlSync(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('Allows querying the schema for object fields', () => {
const query = `
query IntrospectionDroidFieldsQuery {
const data = queryStarWars(`
{
__type(name: "Droid") {
name
fields {
Expand All @@ -164,64 +138,44 @@ describe('Star Wars Introspection Tests', () => {
}
}
}
`;
const expected = {
`);

expect(data).to.deep.equal({
__type: {
name: 'Droid',
fields: [
{
name: 'id',
type: {
name: null,
kind: 'NON_NULL',
},
type: { name: null, kind: 'NON_NULL' },
},
{
name: 'name',
type: {
name: 'String',
kind: 'SCALAR',
},
type: { name: 'String', kind: 'SCALAR' },
},
{
name: 'friends',
type: {
name: null,
kind: 'LIST',
},
type: { name: null, kind: 'LIST' },
},
{
name: 'appearsIn',
type: {
name: null,
kind: 'LIST',
},
type: { name: null, kind: 'LIST' },
},
{
name: 'secretBackstory',
type: {
name: 'String',
kind: 'SCALAR',
},
type: { name: 'String', kind: 'SCALAR' },
},
{
name: 'primaryFunction',
type: {
name: 'String',
kind: 'SCALAR',
},
type: { name: 'String', kind: 'SCALAR' },
},
],
},
};

const result = graphqlSync(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('Allows querying the schema for nested object fields', () => {
const query = `
query IntrospectionDroidNestedFieldsQuery {
const data = queryStarWars(`
{
__type(name: "Droid") {
name
fields {
Expand All @@ -237,8 +191,9 @@ describe('Star Wars Introspection Tests', () => {
}
}
}
`;
const expected = {
`);

expect(data).to.deep.equal({
__type: {
name: 'Droid',
fields: [
Expand Down Expand Up @@ -301,14 +256,12 @@ describe('Star Wars Introspection Tests', () => {
},
],
},
};
const result = graphqlSync(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('Allows querying the schema for field args', () => {
const query = `
query IntrospectionQueryTypeQuery {
const data = queryStarWars(`
{
__schema {
queryType {
fields {
Expand All @@ -330,8 +283,9 @@ describe('Star Wars Introspection Tests', () => {
}
}
}
`;
const expected = {
`);

expect(data).to.deep.equal({
__schema: {
queryType: {
fields: [
Expand Down Expand Up @@ -390,29 +344,25 @@ describe('Star Wars Introspection Tests', () => {
],
},
},
};

const result = graphqlSync(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});

it('Allows querying the schema for documentation', () => {
const query = `
query IntrospectionDroidDescriptionQuery {
const data = queryStarWars(`
{
__type(name: "Droid") {
name
description
}
}
`;
const expected = {
`);

expect(data).to.deep.equal({
__type: {
name: 'Droid',
description: 'A mechanical creature in the Star Wars universe.',
},
};
const result = graphqlSync(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});
});
});

0 comments on commit d9f959e

Please sign in to comment.