From 3c79bed721b6e038d8d2bf68aeaef8005bb7f348 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 31 Mar 2019 15:03:09 +0300 Subject: [PATCH] buildClientSchema: Revert breaking change introduced in #1677 (#1808) More details here: https://github.com/graphql/graphql-js/commit/183ff32bee4bc23eb23657f79f414c2400ecb06a#r32971387 --- .../__tests__/buildClientSchema-test.js | 17 +++++++++++++++-- src/utilities/buildClientSchema.js | 4 +--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/utilities/__tests__/buildClientSchema-test.js b/src/utilities/__tests__/buildClientSchema-test.js index f4a17fb357..b0a70c89da 100644 --- a/src/utilities/__tests__/buildClientSchema-test.js +++ b/src/utilities/__tests__/buildClientSchema-test.js @@ -38,17 +38,27 @@ function cycleIntrospection(sdlString) { const serverSchema = buildSchema(sdlString); const initialIntrospection = introspectionFromSchema(serverSchema); const clientSchema = buildClientSchema(initialIntrospection); + const secondIntrospection = introspectionFromSchema(clientSchema); + + hackToRemoveStandardTypes(secondIntrospection); + hackToRemoveStandardTypes(initialIntrospection); /** * If the client then runs the introspection query against the client-side * schema, it should get a result identical to what was returned by the server */ - const secondIntrospection = introspectionFromSchema(clientSchema); expect(secondIntrospection).to.deep.equal(initialIntrospection); - return printSchema(clientSchema); } +// Temporary hack to remove always presented standard types should be removed in 15.0 +function hackToRemoveStandardTypes(introspection) { + (introspection.__schema: any).types = introspection.__schema.types.filter( + ({ name }) => + ['ID', 'Float', 'Int', 'Boolean', 'String'].indexOf(name) === -1, + ); +} + describe('Type System: build schema from introspection', () => { it('builds a simple schema', () => { const sdl = dedent` @@ -320,6 +330,9 @@ describe('Type System: build schema from introspection', () => { const introspection = introspectionFromSchema(schema); const clientSchema = buildClientSchema(introspection); const secondIntrospection = introspectionFromSchema(clientSchema); + + hackToRemoveStandardTypes(secondIntrospection); + hackToRemoveStandardTypes(introspection); expect(secondIntrospection).to.deep.equal(introspection); const clientFoodEnum = clientSchema.getType('Food'); diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index f8643ed972..69e4966d91 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -92,9 +92,7 @@ export function buildClientSchema( ); for (const stdType of [...specifiedScalarTypes, ...introspectionTypes]) { - if (typeMap[stdType.name]) { - typeMap[stdType.name] = stdType; - } + typeMap[stdType.name] = stdType; } // Get the root Query, Mutation, and Subscription types.