From f66f29a160cd37d90e8b84964e91fcf48104859a Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Thu, 19 Sep 2019 20:37:43 +0200 Subject: [PATCH 1/8] Consistent error messages in buildClientSchema Always: - put a space after : - terminate with a . --- src/utilities/buildClientSchema.js | 33 +++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index 0ccccbb59d..15702cca16 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -75,7 +75,8 @@ export function buildClientSchema( devAssert( isObjectLike(introspection) && isObjectLike(introspection.__schema), 'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: ' + - inspect(introspection), + inspect(introspection) + + '.', ); // Get the schema from the introspection result. @@ -142,7 +143,7 @@ export function buildClientSchema( return GraphQLNonNull(assertNullableType(nullableType)); } if (!typeRef.name) { - throw new Error('Unknown type reference: ' + inspect(typeRef)); + throw new Error('Unknown type reference: ' + inspect(typeRef) + '.'); } return getNamedType(typeRef.name); } @@ -218,8 +219,9 @@ export function buildClientSchema( } } throw new Error( - 'Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema:' + - inspect(type), + 'Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema: ' + + inspect(type) + + '.', ); } @@ -238,7 +240,8 @@ export function buildClientSchema( if (!objectIntrospection.interfaces) { throw new Error( 'Introspection result missing interfaces: ' + - inspect(objectIntrospection), + inspect(objectIntrospection) + + '.', ); } return new GraphQLObjectType({ @@ -265,7 +268,8 @@ export function buildClientSchema( if (!unionIntrospection.possibleTypes) { throw new Error( 'Introspection result missing possibleTypes: ' + - inspect(unionIntrospection), + inspect(unionIntrospection) + + '.', ); } return new GraphQLUnionType({ @@ -281,7 +285,8 @@ export function buildClientSchema( if (!enumIntrospection.enumValues) { throw new Error( 'Introspection result missing enumValues: ' + - inspect(enumIntrospection), + inspect(enumIntrospection) + + '.', ); } return new GraphQLEnumType({ @@ -304,7 +309,8 @@ export function buildClientSchema( if (!inputObjectIntrospection.inputFields) { throw new Error( 'Introspection result missing inputFields: ' + - inspect(inputObjectIntrospection), + inspect(inputObjectIntrospection) + + '.', ); } return new GraphQLInputObjectType({ @@ -317,7 +323,7 @@ export function buildClientSchema( function buildFieldDefMap(typeIntrospection) { if (!typeIntrospection.fields) { throw new Error( - 'Introspection result missing fields: ' + inspect(typeIntrospection), + 'Introspection result missing fields: ' + inspect(typeIntrospection) + '.', ); } return keyValMap( @@ -327,7 +333,8 @@ export function buildClientSchema( if (!fieldIntrospection.args) { throw new Error( 'Introspection result missing field args: ' + - inspect(fieldIntrospection), + inspect(fieldIntrospection) + + '.', ); } return { @@ -365,13 +372,15 @@ export function buildClientSchema( if (!directiveIntrospection.args) { throw new Error( 'Introspection result missing directive args: ' + - inspect(directiveIntrospection), + inspect(directiveIntrospection) + + '.', ); } if (!directiveIntrospection.locations) { throw new Error( 'Introspection result missing directive locations: ' + - inspect(directiveIntrospection), + inspect(directiveIntrospection) + + '.', ); } return new GraphQLDirective({ From c2e2b4b97d04ffd3f23f01b7dbef00135498782c Mon Sep 17 00:00:00 2001 From: spawnia Date: Sat, 21 Sep 2019 18:54:44 +0200 Subject: [PATCH 2/8] Reword and add some comments --- src/utilities/__tests__/buildClientSchema-test.js | 8 ++++---- src/utilities/buildClientSchema.js | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utilities/__tests__/buildClientSchema-test.js b/src/utilities/__tests__/buildClientSchema-test.js index b67feecb84..eb3098c94a 100644 --- a/src/utilities/__tests__/buildClientSchema-test.js +++ b/src/utilities/__tests__/buildClientSchema-test.js @@ -29,10 +29,10 @@ import { introspectionFromSchema } from '../introspectionFromSchema'; /** * This function does a full cycle of going from a string with the contents of * the SDL, build in-memory GraphQLSchema from it, produce a client-side - * representation of the schema by using "buildClientSchema"and then finally - * printing that that schema into the SDL + * representation of the schema by using "buildClientSchema" and then + * returns that schema printed as SDL. */ -function cycleIntrospection(sdlString) { +function cycleIntrospection(sdlString: string): string { const serverSchema = buildSchema(sdlString); const initialIntrospection = introspectionFromSchema(serverSchema); const clientSchema = buildClientSchema(initialIntrospection); @@ -141,7 +141,7 @@ describe('Type System: build schema from introspection', () => { expect(clientSchema.getType('CustomScalar')).not.to.equal(customScalar); }); - it('include standard type only if it is used', () => { + it('includes standard types only if they are used', () => { const schema = buildSchema(` type Query { foo: String diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index 15702cca16..9f351e34fe 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -89,6 +89,7 @@ export function buildClientSchema( typeIntrospection => buildType(typeIntrospection), ); + // Include standard types only if they are used. for (const stdType of [...specifiedScalarTypes, ...introspectionTypes]) { if (typeMap[stdType.name]) { typeMap[stdType.name] = stdType; From 67c4f4669dd437983a6b0ef46e8aa97c17e18254 Mon Sep 17 00:00:00 2001 From: spawnia Date: Sat, 21 Sep 2019 19:11:42 +0200 Subject: [PATCH 3/8] Make it prettier --- src/utilities/buildClientSchema.js | 60 +++++++++++++----------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index 9f351e34fe..14d893c715 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -72,11 +72,10 @@ export function buildClientSchema( introspection: IntrospectionQuery, options?: Options, ): GraphQLSchema { + const introspectionStr = inspect(introspection); devAssert( isObjectLike(introspection) && isObjectLike(introspection.__schema), - 'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: ' + - inspect(introspection) + - '.', + `Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: ${introspectionStr}.`, ); // Get the schema from the introspection result. @@ -144,7 +143,7 @@ export function buildClientSchema( return GraphQLNonNull(assertNullableType(nullableType)); } if (!typeRef.name) { - throw new Error('Unknown type reference: ' + inspect(typeRef) + '.'); + throw new Error(`Unknown type reference: ${inspect(typeRef)}.`); } return getNamedType(typeRef.name); } @@ -165,10 +164,9 @@ export function buildClientSchema( if (isInputType(type)) { return type; } + const typeStr = inspect(type); throw new Error( - 'Introspection must provide input type for arguments, but received: ' + - inspect(type) + - '.', + `Introspection must provide input type for arguments, but received: ${typeStr}.`, ); } @@ -179,10 +177,9 @@ export function buildClientSchema( if (isOutputType(type)) { return type; } + const typeStr = inspect(type); throw new Error( - 'Introspection must provide output type for fields, but received: ' + - inspect(type) + - '.', + `Introspection must provide output type for fields, but received: ${typeStr}.`, ); } @@ -219,10 +216,9 @@ export function buildClientSchema( return buildInputObjectDef(type); } } + const typeStr = inspect(type); throw new Error( - 'Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema: ' + - inspect(type) + - '.', + `Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema: ${typeStr}.`, ); } @@ -239,10 +235,9 @@ export function buildClientSchema( objectIntrospection: IntrospectionObjectType, ): GraphQLObjectType { if (!objectIntrospection.interfaces) { + const introspectionStr = inspect(objectIntrospection); throw new Error( - 'Introspection result missing interfaces: ' + - inspect(objectIntrospection) + - '.', + `Introspection result missing interfaces: ${introspectionStr}.`, ); } return new GraphQLObjectType({ @@ -267,10 +262,9 @@ export function buildClientSchema( unionIntrospection: IntrospectionUnionType, ): GraphQLUnionType { if (!unionIntrospection.possibleTypes) { + const introspectionStr = inspect(unionIntrospection); throw new Error( - 'Introspection result missing possibleTypes: ' + - inspect(unionIntrospection) + - '.', + `Introspection result missing possibleTypes: ${introspectionStr}.`, ); } return new GraphQLUnionType({ @@ -285,9 +279,9 @@ export function buildClientSchema( ): GraphQLEnumType { if (!enumIntrospection.enumValues) { throw new Error( - 'Introspection result missing enumValues: ' + - inspect(enumIntrospection) + - '.', + `Introspection result missing enumValues: ${inspect( + enumIntrospection, + )}.`, ); } return new GraphQLEnumType({ @@ -308,10 +302,9 @@ export function buildClientSchema( inputObjectIntrospection: IntrospectionInputObjectType, ): GraphQLInputObjectType { if (!inputObjectIntrospection.inputFields) { + const introspectionStr = inspect(inputObjectIntrospection); throw new Error( - 'Introspection result missing inputFields: ' + - inspect(inputObjectIntrospection) + - '.', + `Introspection result missing inputFields: ${introspectionStr}.`, ); } return new GraphQLInputObjectType({ @@ -324,7 +317,7 @@ export function buildClientSchema( function buildFieldDefMap(typeIntrospection) { if (!typeIntrospection.fields) { throw new Error( - 'Introspection result missing fields: ' + inspect(typeIntrospection) + '.', + `Introspection result missing fields: ${inspect(typeIntrospection)}.`, ); } return keyValMap( @@ -333,9 +326,9 @@ export function buildClientSchema( fieldIntrospection => { if (!fieldIntrospection.args) { throw new Error( - 'Introspection result missing field args: ' + - inspect(fieldIntrospection) + - '.', + `Introspection result missing field args: ${inspect( + fieldIntrospection, + )}.`, ); } return { @@ -370,18 +363,15 @@ export function buildClientSchema( } function buildDirective(directiveIntrospection) { + const introspectionStr = inspect(directiveIntrospection); if (!directiveIntrospection.args) { throw new Error( - 'Introspection result missing directive args: ' + - inspect(directiveIntrospection) + - '.', + `Introspection result missing directive args: ${introspectionStr}.`, ); } if (!directiveIntrospection.locations) { throw new Error( - 'Introspection result missing directive locations: ' + - inspect(directiveIntrospection) + - '.', + `Introspection result missing directive locations: ${introspectionStr}.`, ); } return new GraphQLDirective({ From bf930cd4cf21372d004aa5d091c3d4dbb84e7ef9 Mon Sep 17 00:00:00 2001 From: spawnia Date: Sat, 21 Sep 2019 19:14:29 +0200 Subject: [PATCH 4/8] Even prettier --- src/utilities/buildClientSchema.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index 14d893c715..ba28263b23 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -235,9 +235,9 @@ export function buildClientSchema( objectIntrospection: IntrospectionObjectType, ): GraphQLObjectType { if (!objectIntrospection.interfaces) { - const introspectionStr = inspect(objectIntrospection); + const objectIntrospectionStr = inspect(objectIntrospection); throw new Error( - `Introspection result missing interfaces: ${introspectionStr}.`, + `Introspection result missing interfaces: ${objectIntrospectionStr}.`, ); } return new GraphQLObjectType({ @@ -262,9 +262,9 @@ export function buildClientSchema( unionIntrospection: IntrospectionUnionType, ): GraphQLUnionType { if (!unionIntrospection.possibleTypes) { - const introspectionStr = inspect(unionIntrospection); + const unionIntrospectionStr = inspect(unionIntrospection); throw new Error( - `Introspection result missing possibleTypes: ${introspectionStr}.`, + `Introspection result missing possibleTypes: ${unionIntrospectionStr}.`, ); } return new GraphQLUnionType({ @@ -278,10 +278,9 @@ export function buildClientSchema( enumIntrospection: IntrospectionEnumType, ): GraphQLEnumType { if (!enumIntrospection.enumValues) { + const enumIntrospectionStr = inspect(enumIntrospection); throw new Error( - `Introspection result missing enumValues: ${inspect( - enumIntrospection, - )}.`, + `Introspection result missing enumValues: ${enumIntrospectionStr}.`, ); } return new GraphQLEnumType({ @@ -302,9 +301,9 @@ export function buildClientSchema( inputObjectIntrospection: IntrospectionInputObjectType, ): GraphQLInputObjectType { if (!inputObjectIntrospection.inputFields) { - const introspectionStr = inspect(inputObjectIntrospection); + const inputObjectIntrospectionStr = inspect(inputObjectIntrospection); throw new Error( - `Introspection result missing inputFields: ${introspectionStr}.`, + `Introspection result missing inputFields: ${inputObjectIntrospectionStr}.`, ); } return new GraphQLInputObjectType({ @@ -325,10 +324,9 @@ export function buildClientSchema( fieldIntrospection => fieldIntrospection.name, fieldIntrospection => { if (!fieldIntrospection.args) { + const fieldIntrospectionStr = inspect(fieldIntrospection); throw new Error( - `Introspection result missing field args: ${inspect( - fieldIntrospection, - )}.`, + `Introspection result missing field args: ${fieldIntrospectionStr}.`, ); } return { @@ -363,15 +361,15 @@ export function buildClientSchema( } function buildDirective(directiveIntrospection) { - const introspectionStr = inspect(directiveIntrospection); + const directiveIntrospectionStr = inspect(directiveIntrospection); if (!directiveIntrospection.args) { throw new Error( - `Introspection result missing directive args: ${introspectionStr}.`, + `Introspection result missing directive args: ${directiveIntrospectionStr}.`, ); } if (!directiveIntrospection.locations) { throw new Error( - `Introspection result missing directive locations: ${introspectionStr}.`, + `Introspection result missing directive locations: ${directiveIntrospectionStr}.`, ); } return new GraphQLDirective({ From 13e6bd00bf67a963359065956de58db269210973 Mon Sep 17 00:00:00 2001 From: spawnia Date: Sat, 21 Sep 2019 19:20:10 +0200 Subject: [PATCH 5/8] Inline devAssert --- src/utilities/buildClientSchema.js | 49 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index ba28263b23..8c2f692f97 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -13,43 +13,43 @@ import { GraphQLDirective } from '../type/directives'; import { specifiedScalarTypes } from '../type/scalars'; import { introspectionTypes, TypeKind } from '../type/introspection'; import { - type GraphQLSchemaValidationOptions, GraphQLSchema, + type GraphQLSchemaValidationOptions, } from '../type/schema'; import { - type GraphQLType, - type GraphQLInputType, - type GraphQLOutputType, - type GraphQLNamedType, - isInputType, - isOutputType, - GraphQLScalarType, - GraphQLObjectType, - GraphQLInterfaceType, - GraphQLUnionType, + assertInterfaceType, + assertNullableType, + assertObjectType, GraphQLEnumType, GraphQLInputObjectType, + type GraphQLInputType, + GraphQLInterfaceType, GraphQLList, + type GraphQLNamedType, GraphQLNonNull, - assertNullableType, - assertObjectType, - assertInterfaceType, + GraphQLObjectType, + type GraphQLOutputType, + GraphQLScalarType, + type GraphQLType, + GraphQLUnionType, + isInputType, + isOutputType, } from '../type/definition'; import { valueFromAST } from './valueFromAST'; import { - type IntrospectionQuery, - type IntrospectionType, - type IntrospectionScalarType, - type IntrospectionObjectType, - type IntrospectionInterfaceType, - type IntrospectionUnionType, type IntrospectionEnumType, type IntrospectionInputObjectType, - type IntrospectionTypeRef, type IntrospectionInputTypeRef, - type IntrospectionOutputTypeRef, + type IntrospectionInterfaceType, type IntrospectionNamedTypeRef, + type IntrospectionObjectType, + type IntrospectionOutputTypeRef, + type IntrospectionQuery, + type IntrospectionScalarType, + type IntrospectionType, + type IntrospectionTypeRef, + type IntrospectionUnionType, } from './getIntrospectionQuery'; type Options = {| @@ -72,10 +72,11 @@ export function buildClientSchema( introspection: IntrospectionQuery, options?: Options, ): GraphQLSchema { - const introspectionStr = inspect(introspection); devAssert( isObjectLike(introspection) && isObjectLike(introspection.__schema), - `Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: ${introspectionStr}.`, + `Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: ${inspect( + introspection, + )}.`, ); // Get the schema from the introspection result. From a37ed83f09dfc3f9a749d629b99818c45dd8cb33 Mon Sep 17 00:00:00 2001 From: spawnia Date: Sat, 21 Sep 2019 19:21:44 +0200 Subject: [PATCH 6/8] Revert import order --- src/utilities/buildClientSchema.js | 44 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index 8c2f692f97..3e4a348955 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -13,43 +13,43 @@ import { GraphQLDirective } from '../type/directives'; import { specifiedScalarTypes } from '../type/scalars'; import { introspectionTypes, TypeKind } from '../type/introspection'; import { - GraphQLSchema, type GraphQLSchemaValidationOptions, + GraphQLSchema, } from '../type/schema'; import { - assertInterfaceType, - assertNullableType, - assertObjectType, - GraphQLEnumType, - GraphQLInputObjectType, + type GraphQLType, type GraphQLInputType, - GraphQLInterfaceType, - GraphQLList, - type GraphQLNamedType, - GraphQLNonNull, - GraphQLObjectType, type GraphQLOutputType, - GraphQLScalarType, - type GraphQLType, - GraphQLUnionType, + type GraphQLNamedType, isInputType, isOutputType, + GraphQLScalarType, + GraphQLObjectType, + GraphQLInterfaceType, + GraphQLUnionType, + GraphQLEnumType, + GraphQLInputObjectType, + GraphQLList, + GraphQLNonNull, + assertNullableType, + assertObjectType, + assertInterfaceType, } from '../type/definition'; import { valueFromAST } from './valueFromAST'; import { + type IntrospectionQuery, + type IntrospectionType, + type IntrospectionScalarType, + type IntrospectionObjectType, + type IntrospectionInterfaceType, + type IntrospectionUnionType, type IntrospectionEnumType, type IntrospectionInputObjectType, + type IntrospectionTypeRef, type IntrospectionInputTypeRef, - type IntrospectionInterfaceType, - type IntrospectionNamedTypeRef, - type IntrospectionObjectType, type IntrospectionOutputTypeRef, - type IntrospectionQuery, - type IntrospectionScalarType, - type IntrospectionType, - type IntrospectionTypeRef, - type IntrospectionUnionType, + type IntrospectionNamedTypeRef, } from './getIntrospectionQuery'; type Options = {| From c9e3b6c0709f764aa521d8b77cf6c15028bf8da2 Mon Sep 17 00:00:00 2001 From: spawnia Date: Fri, 1 Nov 2019 12:33:45 +0100 Subject: [PATCH 7/8] Add a --- src/utilities/__tests__/buildClientSchema-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities/__tests__/buildClientSchema-test.js b/src/utilities/__tests__/buildClientSchema-test.js index eb3098c94a..de662b675a 100644 --- a/src/utilities/__tests__/buildClientSchema-test.js +++ b/src/utilities/__tests__/buildClientSchema-test.js @@ -53,7 +53,7 @@ describe('Type System: build schema from introspection', () => { query: Simple } - """This is simple type""" + """This is a simple type""" type Simple { """This is a string field""" string: String From eb398ba2a30c1399182b1ac3a2066d3e5cfb81c1 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Tue, 12 Nov 2019 00:35:32 +0200 Subject: [PATCH 8/8] Review fixes --- .../__tests__/buildClientSchema-test.js | 24 +++++++++---------- src/utilities/buildClientSchema.js | 7 +++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/utilities/__tests__/buildClientSchema-test.js b/src/utilities/__tests__/buildClientSchema-test.js index 32960f73c4..6ad7618fa7 100644 --- a/src/utilities/__tests__/buildClientSchema-test.js +++ b/src/utilities/__tests__/buildClientSchema-test.js @@ -604,12 +604,12 @@ describe('Type System: build schema from introspection', () => { it('throws when introspection is missing __schema property', () => { // $DisableFlowOnNegativeTest expect(() => buildClientSchema(null)).to.throw( - 'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: null', + 'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: null.', ); // $DisableFlowOnNegativeTest expect(() => buildClientSchema({})).to.throw( - 'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: {}', + 'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: {}.', ); }); @@ -653,7 +653,7 @@ describe('Type System: build schema from introspection', () => { delete introspection.__schema.queryType.name; expect(() => buildClientSchema(introspection)).to.throw( - 'Unknown type reference: {}', + 'Unknown type reference: {}.', ); }); @@ -669,7 +669,7 @@ describe('Type System: build schema from introspection', () => { delete queryTypeIntrospection.kind; expect(() => buildClientSchema(introspection)).to.throw( - 'Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema', + /Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema: { name: "Query", .* }\./, ); }); @@ -685,7 +685,7 @@ describe('Type System: build schema from introspection', () => { delete queryTypeIntrospection.interfaces; expect(() => buildClientSchema(introspection)).to.throw( - 'Introspection result missing interfaces: { kind: "OBJECT", name: "Query",', + /Introspection result missing interfaces: { kind: "OBJECT", name: "Query", .* }\./, ); }); @@ -715,7 +715,7 @@ describe('Type System: build schema from introspection', () => { delete queryTypeIntrospection.fields; expect(() => buildClientSchema(introspection)).to.throw( - 'Introspection result missing fields: { kind: "OBJECT", name: "Query",', + /Introspection result missing fields: { kind: "OBJECT", name: "Query", .* }\./, ); }); @@ -731,7 +731,7 @@ describe('Type System: build schema from introspection', () => { delete queryTypeIntrospection.fields[0].args; expect(() => buildClientSchema(introspection)).to.throw( - 'Introspection result missing field args: { name: "foo",', + /Introspection result missing field args: { name: "foo", .* }\./, ); }); @@ -783,7 +783,7 @@ describe('Type System: build schema from introspection', () => { delete someUnionIntrospection.possibleTypes; expect(() => buildClientSchema(introspection)).to.throw( - 'Introspection result missing possibleTypes: { kind: "UNION", name: "SomeUnion",', + /Introspection result missing possibleTypes: { kind: "UNION", name: "SomeUnion",.* }\./, ); }); @@ -799,7 +799,7 @@ describe('Type System: build schema from introspection', () => { delete someEnumIntrospection.enumValues; expect(() => buildClientSchema(introspection)).to.throw( - 'Introspection result missing enumValues: { kind: "ENUM", name: "SomeEnum",', + /Introspection result missing enumValues: { kind: "ENUM", name: "SomeEnum", .* }\./, ); }); @@ -815,7 +815,7 @@ describe('Type System: build schema from introspection', () => { delete someInputObjectIntrospection.inputFields; expect(() => buildClientSchema(introspection)).to.throw( - 'Introspection result missing inputFields: { kind: "INPUT_OBJECT", name: "SomeInputObject",', + /Introspection result missing inputFields: { kind: "INPUT_OBJECT", name: "SomeInputObject", .* }\./, ); }); @@ -832,7 +832,7 @@ describe('Type System: build schema from introspection', () => { delete someDirectiveIntrospection.locations; expect(() => buildClientSchema(introspection)).to.throw( - 'Introspection result missing directive locations: { name: "SomeDirective",', + /Introspection result missing directive locations: { name: "SomeDirective", .* }\./, ); }); @@ -849,7 +849,7 @@ describe('Type System: build schema from introspection', () => { delete someDirectiveIntrospection.args; expect(() => buildClientSchema(introspection)).to.throw( - 'Introspection result missing directive args: { name: "SomeDirective",', + /Introspection result missing directive args: { name: "SomeDirective", .* }\./, ); }); }); diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index af6a441fa9..45c96b2bc1 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -247,9 +247,9 @@ export function buildClientSchema( } if (!implementingIntrospection.interfaces) { + const implementingIntrospectionStr = inspect(implementingIntrospection); throw new Error( - 'Introspection result missing interfaces: ' + - inspect(implementingIntrospection), + `Introspection result missing interfaces: ${implementingIntrospectionStr}.`, ); } @@ -381,13 +381,14 @@ export function buildClientSchema( } function buildDirective(directiveIntrospection) { - const directiveIntrospectionStr = inspect(directiveIntrospection); if (!directiveIntrospection.args) { + const directiveIntrospectionStr = inspect(directiveIntrospection); throw new Error( `Introspection result missing directive args: ${directiveIntrospectionStr}.`, ); } if (!directiveIntrospection.locations) { + const directiveIntrospectionStr = inspect(directiveIntrospection); throw new Error( `Introspection result missing directive locations: ${directiveIntrospectionStr}.`, );