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

buildSchema/extendSchema: test standard scalars #1810

Merged
merged 1 commit into from Mar 31, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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