File tree Expand file tree Collapse file tree
packages/apollo-language-server/src/project Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020 - <First ` apollo-graphql ` related entry goes here>
2121- ` apollo-language-server `
2222 - Add debugging util classes for better error/warning handling [ #1429 ] ( https://github.com/apollographql/apollo-tooling/pull/1429 )
23+ - Add error for duplicate client operation names [ #1466 ] ( https://github.com/apollographql/apollo-tooling/pull/1466 )
2324- ` apollo-tools `
2425 - <First ` apollo-tools ` related entry goes here>
2526- ` vscode-apollo `
Original file line number Diff line number Diff line change 88 TypeSystemExtensionNode ,
99 isTypeSystemExtensionNode ,
1010 DefinitionNode ,
11- GraphQLSchema
11+ GraphQLSchema ,
12+ Kind
1213} from "graphql" ;
1314
1415import {
@@ -203,6 +204,7 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
203204
204205 fileWasDeleted ( uri : DocumentUri ) {
205206 this . removeGraphQLDocumentsFor ( uri ) ;
207+ this . checkForDuplicateOperations ( ) ;
206208 }
207209
208210 documentDidChange ( document : TextDocument ) {
@@ -216,6 +218,24 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
216218 } else {
217219 this . removeGraphQLDocumentsFor ( document . uri ) ;
218220 }
221+ this . checkForDuplicateOperations ( ) ;
222+ }
223+
224+ checkForDuplicateOperations ( ) : void {
225+ const operations = Object . create ( null ) ;
226+ for ( const document of this . documents ) {
227+ if ( ! document . ast ) continue ;
228+ for ( const definition of document . ast . definitions ) {
229+ if ( definition . kind === Kind . OPERATION_DEFINITION && definition . name ) {
230+ if ( operations [ definition . name . value ] ) {
231+ throw new Error (
232+ `️️There are multiple definitions for the ${ definition . name . value } operation. All operations in a project must have unique names. If generating types, only the types for the first definition found will be generated.`
233+ ) ;
234+ }
235+ operations [ definition . name . value ] = definition ;
236+ }
237+ }
238+ }
219239 }
220240
221241 private removeGraphQLDocumentsFor ( uri : DocumentUri ) {
You can’t perform that action at this time.
0 commit comments