From ba18fbf02957428de426a8bfd9b9dcb9eeac3ff6 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 16 Apr 2020 10:07:49 -0400 Subject: [PATCH 1/6] Fix silent codegen errors on syntax errors During document parsing, syntax errors are silently added to the document, but errors are never thrown. This PR checks at the _command-level_ for these errors and if they exist, prints them to the user. I didn't want to change at the document setup level, because I have a feeling the silent erroring was intention for the sake of the operation registry or something. So I added in an error where it was immediately causing an issue, in the client codegen command. --- packages/apollo/src/commands/client/codegen.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/apollo/src/commands/client/codegen.ts b/packages/apollo/src/commands/client/codegen.ts index 221575fb90..c06010093a 100644 --- a/packages/apollo/src/commands/client/codegen.ts +++ b/packages/apollo/src/commands/client/codegen.ts @@ -187,6 +187,19 @@ export default class Generate extends ClientCommand { // are valid documents project.validate(); + // to prevent silent erroring of syntax errors, we check the project's + // documents to make sure there are no errors. If there are, we error here + // instead of project initialization + for (const document of this.project.documents) { + if (document.syntaxErrors) { + const errors = document.syntaxErrors.map( + e => + `Syntax error in ${document.source.name}: ${e.message}\n` + ); + throw new Error(errors.toString()); + } + } + const operations = Object.values(this.project.operations); const fragments = Object.values(this.project.fragments); From 9cf7391a26e27159f58bd9c000f1cbed384688a7 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 16 Apr 2020 13:42:55 -0400 Subject: [PATCH 2/6] pls dont break :') --- packages/apollo/src/commands/client/codegen.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/apollo/src/commands/client/codegen.ts b/packages/apollo/src/commands/client/codegen.ts index c06010093a..7a5db0ec1e 100644 --- a/packages/apollo/src/commands/client/codegen.ts +++ b/packages/apollo/src/commands/client/codegen.ts @@ -190,15 +190,15 @@ export default class Generate extends ClientCommand { // to prevent silent erroring of syntax errors, we check the project's // documents to make sure there are no errors. If there are, we error here // instead of project initialization - for (const document of this.project.documents) { - if (document.syntaxErrors) { - const errors = document.syntaxErrors.map( - e => - `Syntax error in ${document.source.name}: ${e.message}\n` - ); - throw new Error(errors.toString()); - } - } + // for (const document of this.project.documents) { + // if (document.syntaxErrors) { + // const errors = document.syntaxErrors.map( + // e => + // `Syntax error in ${document.source.name}: ${e.message}\n` + // ); + // throw new Error(errors.toString()); + // } + // } const operations = Object.values(this.project.operations); const fragments = Object.values(this.project.fragments); From 257755667f3820a4d4ca582c0786686deb912cea Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 16 Apr 2020 13:46:16 -0400 Subject: [PATCH 3/6] pls be nice --- packages/apollo-language-server/src/document.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/apollo-language-server/src/document.ts b/packages/apollo-language-server/src/document.ts index 4825239b1b..886d16ca92 100644 --- a/packages/apollo-language-server/src/document.ts +++ b/packages/apollo-language-server/src/document.ts @@ -32,6 +32,7 @@ export class GraphQLDocument { source, rangeOfTokenAtLocation(error.locations[0], source.body) ); + console.log(error.message, source.name); this.syntaxErrors.push({ severity: DiagnosticSeverity.Error, message: error.message, From 873d46d8e4ad782cc2963fc72df82749fbf1af50 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 16 Apr 2020 13:49:52 -0400 Subject: [PATCH 4/6] maybe --- .../apollo-language-server/src/document.ts | 1 - packages/apollo/src/commands/client/codegen.ts | 18 +++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/apollo-language-server/src/document.ts b/packages/apollo-language-server/src/document.ts index 886d16ca92..4825239b1b 100644 --- a/packages/apollo-language-server/src/document.ts +++ b/packages/apollo-language-server/src/document.ts @@ -32,7 +32,6 @@ export class GraphQLDocument { source, rangeOfTokenAtLocation(error.locations[0], source.body) ); - console.log(error.message, source.name); this.syntaxErrors.push({ severity: DiagnosticSeverity.Error, message: error.message, diff --git a/packages/apollo/src/commands/client/codegen.ts b/packages/apollo/src/commands/client/codegen.ts index 7a5db0ec1e..c06010093a 100644 --- a/packages/apollo/src/commands/client/codegen.ts +++ b/packages/apollo/src/commands/client/codegen.ts @@ -190,15 +190,15 @@ export default class Generate extends ClientCommand { // to prevent silent erroring of syntax errors, we check the project's // documents to make sure there are no errors. If there are, we error here // instead of project initialization - // for (const document of this.project.documents) { - // if (document.syntaxErrors) { - // const errors = document.syntaxErrors.map( - // e => - // `Syntax error in ${document.source.name}: ${e.message}\n` - // ); - // throw new Error(errors.toString()); - // } - // } + for (const document of this.project.documents) { + if (document.syntaxErrors) { + const errors = document.syntaxErrors.map( + e => + `Syntax error in ${document.source.name}: ${e.message}\n` + ); + throw new Error(errors.toString()); + } + } const operations = Object.values(this.project.operations); const fragments = Object.values(this.project.fragments); From 421f7c3fb0821f905d352fd925d4803d87fbd696 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 16 Apr 2020 13:58:34 -0400 Subject: [PATCH 5/6] fix array length check --- packages/apollo/src/commands/client/codegen.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apollo/src/commands/client/codegen.ts b/packages/apollo/src/commands/client/codegen.ts index c06010093a..bd7a4350a2 100644 --- a/packages/apollo/src/commands/client/codegen.ts +++ b/packages/apollo/src/commands/client/codegen.ts @@ -191,7 +191,7 @@ export default class Generate extends ClientCommand { // documents to make sure there are no errors. If there are, we error here // instead of project initialization for (const document of this.project.documents) { - if (document.syntaxErrors) { + if (document.syntaxErrors.length) { const errors = document.syntaxErrors.map( e => `Syntax error in ${document.source.name}: ${e.message}\n` From 74ab8956735443ee911aa5d07ec20391c7085fed Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 16 Apr 2020 14:02:22 -0400 Subject: [PATCH 6/6] update types --- packages/apollo-language-server/src/graphqlTypes.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/apollo-language-server/src/graphqlTypes.ts b/packages/apollo-language-server/src/graphqlTypes.ts index dea9dd152b..19c7fd9572 100644 --- a/packages/apollo-language-server/src/graphqlTypes.ts +++ b/packages/apollo-language-server/src/graphqlTypes.ts @@ -1722,6 +1722,7 @@ export interface IntrospectionDirectiveInput { description?: string | null; locations: IntrospectionDirectiveLocation[]; args: IntrospectionInputValueInput[]; + isRepeatable?: boolean | null; } /** @@ -1765,6 +1766,7 @@ export interface IntrospectionSchemaInput { mutationType?: IntrospectionTypeRefInput | null; subscriptionType?: IntrospectionTypeRefInput | null; directives: IntrospectionDirectiveInput[]; + description?: string | null; } /**