package Ġcom . ap ol log raph ql . apollo 3 . ast . internal Ċ Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Definition Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Directive Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Enum Type Definition Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Enum Type Extension Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Input ObjectType Definition Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Input ObjectType Extension Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Interface Type Definition Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Interface Type Extension Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Named Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Node Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL ObjectType Definition Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL ObjectType Extension Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Scalar Type Definition Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Scalar Type Extension Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Schema Definition Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Schema Extension Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Type System Extension Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Union Type Definition Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . G QL Union Type Extension Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . Issue Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . Source Location Ċ import Ġcom . ap ol log raph ql . apollo 3 . ast . Unrecognized Ant lr Rule ĊĊ Ċ internal Ġfun ĠValidation Scope . merge Extensions ( definitions : ĠList < G QL Definition >): ĠList < G QL Definition > Ġ{ ĊĠ Ġval Ġ( extensions , Ġother Definitions ) Ġ= Ġdefinitions . partition Ġ{ Ġit Ġis ĠG QL Type System Extension Ġ} ĊĊĠ Ġreturn Ġextensions . fold ( other Definitions ) Ġ{ Ġacc , Ġextension Ġ-> ĊĠĠĠ Ġwhen Ġ( extension ) Ġ{ ĊĠĠĠĠĠ Ġis ĠG QL Schema Extension Ġ-> Ġmerge Schema Extension ( acc , Ġschema Extension Ġ= Ġextension ) ĊĠĠĠĠĠ Ġis ĠG QL Scalar Type Extension Ġ-> Ġmerge < G QL Scalar Type Definition , ĠG QL Scalar Type Extension >( acc , Ġextension ) Ġ{ Ġmerge ( it , Ġextension ) Ġ} ĊĠĠĠĠĠ Ġis ĠG QL Interface Type Extension Ġ-> Ġmerge < G QL Interface Type Definition , ĠG QL Interface Type Extension >( acc , Ġextension ) Ġ{ Ġmerge ( it , Ġextension ) Ġ} ĊĠĠĠĠĠ Ġis ĠG QL ObjectType Extension Ġ-> Ġmerge < G QL ObjectType Definition , ĠG QL ObjectType Extension >( acc , Ġextension ) Ġ{ Ġmerge ( it , Ġextension ) Ġ} ĊĠĠĠĠĠ Ġis ĠG QL Input ObjectType Extension Ġ-> Ġmerge < G QL Input ObjectType Definition , ĠG QL Input ObjectType Extension >( acc , Ġextension ) Ġ{ Ġmerge ( it , Ġextension ) Ġ} ĊĠĠĠĠĠ Ġis ĠG QL Enum Type Extension Ġ-> Ġmerge < G QL Enum Type Definition , ĠG QL Enum Type Extension >( acc , Ġextension ) Ġ{ Ġmerge ( it , Ġextension ) Ġ} ĊĠĠĠĠĠ Ġis ĠG QL Union Type Extension Ġ-> Ġmerge < G QL Union Type Definition , ĠG QL Union Type Extension >( acc , Ġextension ) Ġ{ Ġmerge ( it , Ġextension ) Ġ} ĊĠĠĠĠĠ Ġelse Ġ-> Ġthrow ĠUn recognized Ant lr Rule (" Unrecognized Ġtype Ġsystem Ġextension ", Ġextension . source Location ) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ Ċ private Ġfun ĠValidation Scope . merge ( ĊĠĠĠ Ġunion Type Definition : ĠG QL Union Type Definition , ĊĠĠĠ Ġextension : ĠG QL Union Type Extension , Ċ ): ĠG QL Union Type Definition Ġ= Ġwith ( union Type Definition ) Ġ{ ĊĠ Ġreturn Ġcopy ( ĊĠĠĠĠĠ Ġdirectives Ġ= Ġmerge Directives ( directives , Ġextension . directives ), ĊĠĠĠĠĠ Ġmember Types Ġ= Ġmerge Uni ques OrThrow ( member Types , Ġextension . member Types ) ĊĠ Ġ) Ċ } Ċ Ċ private Ġfun ĠValidation Scope . merge ( ĊĠĠĠ Ġenum Type Definition : ĠG QL Enum Type Definition , ĊĠĠĠ Ġextension : ĠG QL Enum Type Extension , Ċ ): ĠG QL Enum Type Definition Ġ= Ġwith ( enum Type Definition ) Ġ{ ĊĠ Ġreturn Ġcopy ( ĊĠĠĠĠĠ Ġdirectives Ġ= Ġmerge Directives ( directives , Ġextension . directives ), ĊĠĠĠĠĠ Ġenum Values Ġ= Ġmerge Uni ques OrThrow ( enum Values , Ġextension . enum Values ), ĊĠ Ġ) Ċ } Ċ Ċ private Ġfun ĠValidation Scope . merge ( ĊĠĠĠ Ġinput ObjectType Definition : ĠG QL Input ObjectType Definition , ĊĠĠĠ Ġextension : ĠG QL Input ObjectType Extension , Ċ ): ĠG QL Input ObjectType Definition Ġ= Ġwith ( input ObjectType Definition ) Ġ{ ĊĠ Ġreturn Ġcopy ( ĊĠĠĠĠĠ Ġdirectives Ġ= Ġmerge Directives ( directives , Ġextension . directives ), ĊĠĠĠĠĠ Ġinput Fields Ġ= Ġmerge Uni ques OrThrow ( input Fields , Ġextension . input Fields ) ĊĠ Ġ) Ċ } Ċ Ċ private Ġfun ĠValidation Scope . merge ( ĊĠĠĠ Ġobject Type Definition : ĠG QL ObjectType Definition , ĊĠĠĠ Ġextension : ĠG QL ObjectType Extension , Ċ ): ĠG QL ObjectType Definition Ġ= Ġwith ( object Type Definition ) Ġ{ ĊĠ Ġreturn Ġcopy ( ĊĠĠĠĠĠ Ġdirectives Ġ= Ġmerge Directives ( directives , Ġextension . directives ), ĊĠĠĠĠĠ Ġfields Ġ= Ġmerge Uni ques OrThrow ( fields , Ġextension . fields ), ĊĠĠĠĠĠ Ġimplements Interfaces Ġ= Ġmerge Unique Interfaces OrThrow ( implements Interfaces , Ġextension . implements Interfaces , Ġextension . source Location ) ĊĠ Ġ) Ċ } Ċ Ċ private Ġfun ĠValidation Scope . merge ( ĊĠĠĠ Ġinterface Type Definition : ĠG QL Interface Type Definition , ĊĠĠĠ Ġextension : ĠG QL Interface Type Extension , Ċ ): ĠG QL Interface Type Definition Ġ= Ġwith ( interface Type Definition ) Ġ{ ĊĠ Ġreturn Ġcopy ( ĊĠĠĠĠĠ Ġfields Ġ= Ġmerge Uni ques OrThrow ( fields , Ġextension . fields ), ĊĠĠĠĠĠ Ġimplements Interfaces Ġ= Ġmerge Unique Interfaces OrThrow ( implements Interfaces , Ġextension . implements Interfaces , Ġextension . source Location ) ĊĠ Ġ) Ċ } Ċ Ċ private Ġfun ĠValidation Scope . merge Schema Extension ( ĊĠĠĠ Ġdefinitions : ĠList < G QL Definition >, ĊĠĠĠ Ġschema Extension : ĠG QL Schema Extension , Ċ ): ĠList < G QL Definition > Ġ= Ġwith ( definitions ) Ġ{ ĊĠ Ġvar Ġfound Ġ= Ġfalse ĊĠ Ġval Ġnew Definitions Ġ= Ġmutable ListOf < G QL Definition >() ĊĠ ĠforEach Ġ{ ĊĠĠĠ Ġif Ġ( it Ġis ĠG QL Schema Definition ) Ġ{ ĊĠĠĠĠĠ Ġnew Definitions . add ( merge ( it , Ġschema Extension )) ĊĠĠĠĠĠ Ġfound Ġ= Ġtrue ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠ Ġnew Definitions . add ( it ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĠ Ġif Ġ(! found ) Ġ{ ĊĠĠĠ Ġissues . add ( Issue . ValidationError (" Cannot Ġapply Ġschema Ġextension Ġon Ġnon Ġexisting Ġschema Ġdefinition ", Ġschema Extension . source Location )) ĊĠ Ġ} ĊĠ Ġreturn Ġnew Definitions Ċ } Ċ Ċ private Ġfun ĠValidation Scope . merge ( ĊĠĠĠ Ġscalar Type Definition : ĠG QL Scalar Type Definition , ĊĠĠĠ Ġscalar Type Extension : ĠG QL Scalar Type Extension , Ċ ): ĠG QL Scalar Type Definition Ġ= Ġwith ( scalar Type Definition ) Ġ{ ĊĠ Ġreturn Ġcopy ( ĊĠĠĠĠĠ Ġdirectives Ġ= Ġmerge Directives ( directives , Ġscalar Type Extension . directives ) ĊĠ Ġ) Ċ } Ċ Ċ private Ġinline Ġfun Ġ< re ified ĠT , ĠE > ĠValidation Scope . merge ( ĊĠĠĠ Ġdefinitions : ĠList < G QL Definition >, ĊĠĠĠ Ġextension : ĠE , ĊĠĠĠ Ġmerge : Ġ( T ) Ġ-> ĠT , Ċ ): ĠList < G QL Definition > Ġwhere ĠT Ġ: ĠG QL Definition , ĠT Ġ: ĠG QL Named , ĠE Ġ: ĠG QL Named , ĠE Ġ: ĠG QL Node Ġ= Ġwith ( definitions ) Ġ{ ĊĠ Ġvar Ġfound Ġ= Ġfalse ĊĠ Ġval Ġnew Definitions Ġ= Ġmutable ListOf < G QL Definition >() ĊĠ ĠforEach Ġ{ ĊĠĠĠ Ġif Ġ( it Ġis ĠT Ġ&& Ġit . name Ġ== Ġextension . name ) Ġ{ ĊĠĠĠĠĠ Ġif Ġ( found ) Ġ{ ĊĠĠĠĠĠĠĠ Ġissues . add ( Issue . ValidationError (" Multiple Ġ'${ extension . name }' Ġtypes Ġfound Ġwhile Ġmerging Ġextensions . ĠThis Ġis Ġa Ġbug , Ġcheck Ġvalidation Ġcode ", Ġextension . source Location )) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġnew Definitions . add ( merge ( it )) ĊĠĠĠĠĠ Ġfound Ġ= Ġtrue ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠ Ġnew Definitions . add ( it ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĠ Ġif Ġ(! found ) Ġ{ ĊĠĠĠ Ġissues . add ( Issue . ValidationError (" Cannot Ġfind Ġtype Ġ`${ extension . name }` Ġto Ġapply Ġextension ", Ġextension . source Location )) ĊĠ Ġ} ĊĠ Ġreturn Ġnew Definitions Ċ } Ċ Ċ private Ġfun ĠValidation Scope . merge ( ĊĠĠĠ Ġschema Definition : ĠG QL Schema Definition , ĊĠĠĠ Ġextension : ĠG QL Schema Extension , Ċ ): ĠG QL Schema Definition Ġ= Ġwith ( schema Definition ) Ġ{ ĊĠ Ġreturn Ġcopy ( ĊĠĠĠĠĠ Ġdirectives Ġ= Ġmerge Directives ( directives , Ġextension . directives ), ĊĠĠĠĠĠ Ġroot Operation Type Definitions Ġ= Ġmerge Uni ques OrThrow ( root Operation Type Definitions , Ġextension . operation Types Definition ) Ġ{ Ġit . operation Type Ġ} ĊĠ Ġ) Ċ } Ċ Ċ private Ġfun ĠValidation Scope . merge Directives ( ĊĠĠĠ Ġlist : ĠList < G QL Directive >, ĊĠĠĠ Ġother : ĠList < G QL Directive >, Ċ ): ĠList < G QL Directive > Ġ{ ĊĠ Ġval Ġresult Ġ= Ġmutable ListOf < G QL Directive >() ĊĊĠ Ġresult . addAll ( list ) ĊĠ Ġfor Ġ( directive Ġin Ġother ) Ġ{ ĊĠĠĠ Ġif Ġ( result . any Ġ{ Ġit . name Ġ== Ġdirective . name Ġ} Ġ) Ġ{ ĊĠĠĠĠĠ Ġval Ġdefinition Ġ= Ġdirective Definitions [ directive . name ] Ġ?: Ġerror (" Cannot Ġfind Ġdirective Ġdefinition Ġ'${ directive . name }") ĊĠĠĠĠĠ Ġif Ġ(! definition . repeat able ) Ġ{ ĊĠĠĠĠĠĠĠ Ġissues . add ( Issue . ValidationError (" Cannot Ġadd Ġnon - repeat able Ġdirective Ġ`${ directive . name }` ", Ġdirective . source Location )) ĊĠĠĠĠĠĠĠ Ġcontinue ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġresult . add ( directive ) ĊĠ Ġ} ĊĊĠ Ġreturn Ġresult Ċ } Ċ Ċ private Ġinline Ġfun Ġ< re ified ĠT > ĠIssues Scope . merge Uni ques OrThrow ( ĊĠĠĠ Ġlist : ĠList < T >, ĊĠĠĠ Ġothers : ĠList < T >, Ċ ): ĠList < T > Ġwhere ĠT Ġ: ĠG QL Named , ĠT Ġ: ĠG QL Node Ġ= Ġwith ( list ) Ġ{ ĊĠ Ġreturn Ġ( this Ġ+ Ġothers ). apply Ġ{ ĊĠĠĠ Ġgroup By Ġ{ Ġit . name Ġ}. entries . first OrNull Ġ{ Ġit . value . size Ġ> Ġ 1 Ġ} ?. let Ġ{ ĊĠĠĠĠĠ Ġissues . add ( Issue . ValidationError (" Cannot Ġmerge Ġalready Ġexisting Ġnode Ġ`${ it . key }` ", Ġit . value . first (). source Location )) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ Ċ private Ġfun ĠIssues Scope . merge Unique Interfaces OrThrow ( ĊĠĠĠ Ġlist : ĠList < String >, ĊĠĠĠ Ġothers : ĠList < String >, ĊĠĠĠ Ġsource Location : ĠSource Location , Ċ ): ĠList < String > Ġ= Ġwith ( list ) Ġ{ ĊĠ Ġreturn Ġ( this Ġ+ Ġothers ). apply Ġ{ ĊĠĠĠ Ġgroup By Ġ{ Ġit Ġ}. entries . first OrNull Ġ{ Ġit . value . size Ġ> Ġ 1 Ġ} ?. let Ġ{ ĊĠĠĠĠĠ Ġissues . add ( Issue . ValidationError (" Cannot Ġmerge Ġinterface Ġ${ it . value . first ()} Ġas Ġit 's Ġalready Ġdefined ", Ġsource Location )) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } ĊĊ Ċ private Ġinline Ġfun Ġ< re ified ĠT Ġ: ĠG QL Node > ĠIssues Scope . merge Uni ques OrThrow ( ĊĠĠĠ Ġlist : ĠList < T >, ĊĠĠĠ Ġothers : ĠList < T >, ĊĠĠĠ Ġname : Ġ( T ) Ġ-> ĠString , Ċ ): ĠList < T > Ġ= Ġwith ( list ) Ġ{ ĊĠ Ġreturn Ġ( this Ġ+ Ġothers ). apply Ġ{ ĊĠĠĠ Ġgroup By Ġ{ Ġname ( it ) Ġ}. entries . first OrNull Ġ{ Ġit . value . size Ġ> Ġ 1 Ġ} ?. let Ġ{ ĊĠĠĠĠĠ Ġissues . add ( Issue . ValidationError (" Cannot Ġmerge Ġalready Ġexisting Ġnode Ġ`${ it . key }` ", Ġit . value . first (). source Location )) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } ĊĊ