Skip to content

Commit

Permalink
buildSchema/extendSchema: test standard scalars (#1810)
Browse files Browse the repository at this point in the history
Background: 183ff32#r32971387
  • Loading branch information
IvanGoncharov committed Mar 31, 2019
1 parent d2ffd7c commit 0a98379
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/utilities/__tests__/buildASTSchema-test.js
Expand Up @@ -25,6 +25,11 @@ import {
assertScalarType,
graphqlSync,
validateSchema,
GraphQLID,
GraphQLInt,
GraphQLFloat,
GraphQLString,
GraphQLBoolean,
GraphQLSkipDirective,
GraphQLIncludeDirective,
GraphQLDeprecatedDirective,
Expand Down Expand Up @@ -94,6 +99,26 @@ describe('Schema Builder', () => {
}
`;
expect(cycleSDL(sdl)).to.equal(sdl);

const schema = buildSchema(sdl);
// Built-ins are used
expect(schema.getType('Int')).to.equal(GraphQLInt);
expect(schema.getType('Float')).to.equal(GraphQLFloat);
expect(schema.getType('String')).to.equal(GraphQLString);
expect(schema.getType('Boolean')).to.equal(GraphQLBoolean);
expect(schema.getType('ID')).to.equal(GraphQLID);
});

it('include standard type only if it is used', () => {
const schema = buildSchema(`
type Query {
str: String
}
`);

expect(schema.getType('Int')).to.equal(undefined);
expect(schema.getType('Float')).to.equal(undefined);
expect(schema.getType('ID')).to.equal(undefined);
});

it('With directives', () => {
Expand Down
46 changes: 46 additions & 0 deletions src/utilities/__tests__/extendSchema-test.js
Expand Up @@ -11,6 +11,7 @@ import { describe, it } from 'mocha';
import { expect } from 'chai';
import dedent from '../../jsutils/dedent';
import invariant from '../../jsutils/invariant';
import { buildSchema } from '../buildASTSchema';
import { extendSchema } from '../extendSchema';
import { parse, print, DirectiveLocation } from '../../language';
import { printSchema } from '../schemaPrinter';
Expand All @@ -30,7 +31,10 @@ import {
GraphQLInterfaceType,
GraphQLUnionType,
GraphQLID,
GraphQLInt,
GraphQLFloat,
GraphQLString,
GraphQLBoolean,
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLNonNull,
Expand Down Expand Up @@ -266,6 +270,48 @@ describe('extendSchema', () => {
expect(queryType.getFields().foo).to.include({ type: fooType });
});

it('extends objects with standard type fields', () => {
const schema = buildSchema(`
type Query {
str: String
}
`);

expect(schema.getType('Int')).to.equal(undefined);
expect(schema.getType('Float')).to.equal(undefined);
expect(schema.getType('String')).to.equal(GraphQLString);
expect(schema.getType('Boolean')).to.equal(GraphQLBoolean);
expect(schema.getType('ID')).to.equal(undefined);

const extendAST = parse(`
extend type Query {
bool: Boolean
}
`);
const extendedSchema = extendSchema(schema, extendAST);

expect(extendedSchema.getType('Int')).to.equal(undefined);
expect(extendedSchema.getType('Float')).to.equal(undefined);
expect(extendedSchema.getType('String')).to.equal(GraphQLString);
expect(extendedSchema.getType('Boolean')).to.equal(GraphQLBoolean);
expect(extendedSchema.getType('ID')).to.equal(undefined);

const extendTwiceAST = parse(`
extend type Query {
int: Int
float: Float
id: ID
}
`);
const extendedTwiceSchema = extendSchema(schema, extendTwiceAST);

expect(extendedTwiceSchema.getType('Int')).to.equal(GraphQLInt);
expect(extendedTwiceSchema.getType('Float')).to.equal(GraphQLFloat);
expect(extendedTwiceSchema.getType('String')).to.equal(GraphQLString);
expect(extendedTwiceSchema.getType('Boolean')).to.equal(GraphQLBoolean);
expect(extendedTwiceSchema.getType('ID')).to.equal(GraphQLID);
});

it('extends enums by adding new values', () => {
const extendedSchema = extendTestSchema(`
extend enum SomeEnum {
Expand Down

0 comments on commit 0a98379

Please sign in to comment.