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

Consistent error messages in buildClientSchema #2186

Merged
merged 10 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/utilities/__tests__/buildClientSchema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
spawnia marked this conversation as resolved.
Show resolved Hide resolved
);

// $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: {}.',
);
});

Expand Down Expand Up @@ -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: {}.',
);
});

Expand All @@ -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", .* }\./,
);
});

Expand All @@ -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", .* }\./,
);
});

Expand Down Expand Up @@ -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", .* }\./,
);
});

Expand All @@ -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", .* }\./,
);
});

Expand Down Expand Up @@ -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",.* }\./,
);
});

Expand All @@ -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", .* }\./,
);
});

Expand All @@ -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", .* }\./,
);
});

Expand All @@ -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", .* }\./,
);
});

Expand All @@ -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", .* }\./,
);
});
});
Expand Down
7 changes: 4 additions & 3 deletions src/utilities/buildClientSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`,
);
}

Expand Down Expand Up @@ -381,13 +381,14 @@ export function buildClientSchema(
}

function buildDirective(directiveIntrospection) {
const directiveIntrospectionStr = inspect(directiveIntrospection);
spawnia marked this conversation as resolved.
Show resolved Hide resolved
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}.`,
);
Expand Down