Skip to content

Commit 8d7a5fd

Browse files
Merge schema validation tests with other schema tests (#1663)
1 parent 6741ac2 commit 8d7a5fd

File tree

2 files changed

+48
-87
lines changed

2 files changed

+48
-87
lines changed

src/type/__tests__/definition-test.js

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,90 +1198,3 @@ describe('Type System: NonNull must only accept non-nullable types', () => {
11981198
});
11991199
}
12001200
});
1201-
1202-
describe('Type System: A Schema must contain uniquely named types', () => {
1203-
it('rejects a Schema which redefines a built-in type', () => {
1204-
expect(() => {
1205-
const FakeString = new GraphQLScalarType({
1206-
name: 'String',
1207-
serialize: () => null,
1208-
});
1209-
1210-
const QueryType = new GraphQLObjectType({
1211-
name: 'Query',
1212-
fields: {
1213-
normal: { type: GraphQLString },
1214-
fake: { type: FakeString },
1215-
},
1216-
});
1217-
1218-
return new GraphQLSchema({ query: QueryType });
1219-
}).to.throw(
1220-
'Schema must contain unique named types but contains multiple types ' +
1221-
'named "String".',
1222-
);
1223-
});
1224-
1225-
it('rejects a Schema which defines an object type twice', () => {
1226-
expect(() => {
1227-
const A = new GraphQLObjectType({
1228-
name: 'SameName',
1229-
fields: { f: { type: GraphQLString } },
1230-
});
1231-
1232-
const B = new GraphQLObjectType({
1233-
name: 'SameName',
1234-
fields: { f: { type: GraphQLString } },
1235-
});
1236-
1237-
const QueryType = new GraphQLObjectType({
1238-
name: 'Query',
1239-
fields: {
1240-
a: { type: A },
1241-
b: { type: B },
1242-
},
1243-
});
1244-
1245-
return new GraphQLSchema({ query: QueryType });
1246-
}).to.throw(
1247-
'Schema must contain unique named types but contains multiple types ' +
1248-
'named "SameName".',
1249-
);
1250-
});
1251-
1252-
it('rejects a Schema which have same named objects implementing an interface', () => {
1253-
expect(() => {
1254-
const AnotherInterface = new GraphQLInterfaceType({
1255-
name: 'AnotherInterface',
1256-
fields: { f: { type: GraphQLString } },
1257-
});
1258-
1259-
const FirstBadObject = new GraphQLObjectType({
1260-
name: 'BadObject',
1261-
interfaces: [AnotherInterface],
1262-
fields: { f: { type: GraphQLString } },
1263-
});
1264-
1265-
const SecondBadObject = new GraphQLObjectType({
1266-
name: 'BadObject',
1267-
interfaces: [AnotherInterface],
1268-
fields: { f: { type: GraphQLString } },
1269-
});
1270-
1271-
const QueryType = new GraphQLObjectType({
1272-
name: 'Query',
1273-
fields: {
1274-
iface: { type: AnotherInterface },
1275-
},
1276-
});
1277-
1278-
return new GraphQLSchema({
1279-
query: QueryType,
1280-
types: [FirstBadObject, SecondBadObject],
1281-
});
1282-
}).to.throw(
1283-
'Schema must contain unique named types but contains multiple types ' +
1284-
'named "BadObject".',
1285-
);
1286-
});
1287-
});

src/type/__tests__/schema-test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import {
1111
GraphQLSchema,
12+
GraphQLScalarType,
1213
GraphQLInterfaceType,
1314
GraphQLObjectType,
1415
GraphQLString,
@@ -109,6 +110,53 @@ describe('Type System: Schema', () => {
109110
});
110111
});
111112

113+
describe('A Schema must contain uniquely named types', () => {
114+
it('rejects a Schema which redefines a built-in type', () => {
115+
const FakeString = new GraphQLScalarType({
116+
name: 'String',
117+
serialize: () => null,
118+
});
119+
120+
const QueryType = new GraphQLObjectType({
121+
name: 'Query',
122+
fields: {
123+
normal: { type: GraphQLString },
124+
fake: { type: FakeString },
125+
},
126+
});
127+
128+
expect(() => new GraphQLSchema({ query: QueryType })).to.throw(
129+
'Schema must contain unique named types but contains multiple types named "String".',
130+
);
131+
});
132+
133+
it('rejects a Schema which defines an object type twice', () => {
134+
const types = [
135+
new GraphQLObjectType({ name: 'SameName', fields: {} }),
136+
new GraphQLObjectType({ name: 'SameName', fields: {} }),
137+
];
138+
139+
expect(() => new GraphQLSchema({ types })).to.throw(
140+
'Schema must contain unique named types but contains multiple types named "SameName".',
141+
);
142+
});
143+
144+
it('rejects a Schema which defines fields with conflicting types', () => {
145+
const fields = {};
146+
const QueryType = new GraphQLObjectType({
147+
name: 'Query',
148+
fields: {
149+
a: { type: new GraphQLObjectType({ name: 'SameName', fields }) },
150+
b: { type: new GraphQLObjectType({ name: 'SameName', fields }) },
151+
},
152+
});
153+
154+
expect(() => new GraphQLSchema({ query: QueryType })).to.throw(
155+
'Schema must contain unique named types but contains multiple types named "SameName".',
156+
);
157+
});
158+
});
159+
112160
describe('when assumed valid', () => {
113161
it('configures the schema to have no errors', () => {
114162
expect(

0 commit comments

Comments
 (0)