Skip to content

Commit ff0afa2

Browse files
buildClientSchema: include standard type only if it is used (#1809)
Details: 183ff32#r32971387
1 parent 4bff6d8 commit ff0afa2

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/utilities/__tests__/buildClientSchema-test.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ function cycleIntrospection(sdlString) {
4040
const clientSchema = buildClientSchema(initialIntrospection);
4141
const secondIntrospection = introspectionFromSchema(clientSchema);
4242

43-
hackToRemoveStandardTypes(secondIntrospection);
44-
hackToRemoveStandardTypes(initialIntrospection);
45-
4643
/**
4744
* If the client then runs the introspection query against the client-side
4845
* schema, it should get a result identical to what was returned by the server
@@ -51,14 +48,6 @@ function cycleIntrospection(sdlString) {
5148
return printSchema(clientSchema);
5249
}
5350

54-
// Temporary hack to remove always presented standard types should be removed in 15.0
55-
function hackToRemoveStandardTypes(introspection) {
56-
(introspection.__schema: any).types = introspection.__schema.types.filter(
57-
({ name }) =>
58-
['ID', 'Float', 'Int', 'Boolean', 'String'].indexOf(name) === -1,
59-
);
60-
}
61-
6251
describe('Type System: build schema from introspection', () => {
6352
it('builds a simple schema', () => {
6453
const sdl = dedent`
@@ -138,6 +127,20 @@ describe('Type System: build schema from introspection', () => {
138127
expect(clientSchema.getType('CustomScalar')).not.to.equal(customScalar);
139128
});
140129

130+
it('include standard type only if it is used', () => {
131+
const schema = buildSchema(`
132+
type Query {
133+
foo: String
134+
}
135+
`);
136+
const introspection = introspectionFromSchema(schema);
137+
const clientSchema = buildClientSchema(introspection);
138+
139+
expect(clientSchema.getType('Int')).to.equal(undefined);
140+
expect(clientSchema.getType('Float')).to.equal(undefined);
141+
expect(clientSchema.getType('ID')).to.equal(undefined);
142+
});
143+
141144
it('builds a schema with a recursive type reference', () => {
142145
const sdl = dedent`
143146
schema {
@@ -329,10 +332,8 @@ describe('Type System: build schema from introspection', () => {
329332

330333
const introspection = introspectionFromSchema(schema);
331334
const clientSchema = buildClientSchema(introspection);
332-
const secondIntrospection = introspectionFromSchema(clientSchema);
333335

334-
hackToRemoveStandardTypes(secondIntrospection);
335-
hackToRemoveStandardTypes(introspection);
336+
const secondIntrospection = introspectionFromSchema(clientSchema);
336337
expect(secondIntrospection).to.deep.equal(introspection);
337338

338339
const clientFoodEnum = clientSchema.getType('Food');

src/utilities/buildClientSchema.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ export function buildClientSchema(
9090
);
9191

9292
for (const stdType of [...specifiedScalarTypes, ...introspectionTypes]) {
93-
typeMap[stdType.name] = stdType;
93+
if (typeMap[stdType.name]) {
94+
typeMap[stdType.name] = stdType;
95+
}
9496
}
9597

9698
// Get the root Query, Mutation, and Subscription types.

0 commit comments

Comments
 (0)