File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
packages/apollo-language-server/src Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,33 @@ describe("extractGraphQLDocuments", () => {
9393 expect ( documents [ 0 ] . syntaxErrors . length ) . toBe ( 0 ) ;
9494 expect ( documents [ 0 ] . ast . definitions . length ) . toBe ( 2 ) ;
9595 } ) ;
96+
97+ it ( "works with a generic tagname" , ( ) => {
98+ const textDocument = mockTextDocument ( `
99+ gql <TResponse, TOther> \`
100+ {
101+ hero {
102+ ...Hero_character
103+ }
104+ }
105+
106+ \${Hero.fragments.character}
107+
108+ {
109+ reviews(episode: NEWHOPE) {
110+ ...ReviewList_reviews
111+ }
112+ }
113+
114+ \${ReviewList.fragments.reviews}
115+ \`
116+ ` ) ;
117+ const documents = extractGraphQLDocuments ( textDocument ) ;
118+
119+ expect ( documents . length ) . toEqual ( 1 ) ;
120+ expect ( documents [ 0 ] . syntaxErrors . length ) . toBe ( 0 ) ;
121+ expect ( documents [ 0 ] . ast . definitions . length ) . toBe ( 2 ) ;
122+ } ) ;
96123 } ) ;
97124
98125 describe ( "extracting documents from ReasonML extension nodes" , ( ) => {
Original file line number Diff line number Diff line change @@ -89,11 +89,14 @@ function extractGraphQLDocumentsFromJSTemplateLiterals(
8989
9090 const documents : GraphQLDocument [ ] = [ ] ;
9191
92- const regExp = new RegExp ( `${ tagName } \\s*\`([\\s\\S]+?)\`` , "gm" ) ;
92+ const regExp = new RegExp (
93+ `${ tagName } \\s*(?:<([\\sa-zA-Z0-9_,<>]+)>)?\\s*\`([\\s\\S]+?)\`` ,
94+ "gm"
95+ ) ;
9396
9497 let result ;
9598 while ( ( result = regExp . exec ( text ) ) !== null ) {
96- const contents = replacePlaceholdersWithWhiteSpace ( result [ 1 ] ) ;
99+ const contents = replacePlaceholdersWithWhiteSpace ( result [ 2 ] ) ;
97100 const position = document . positionAt ( result . index + ( tagName . length + 1 ) ) ;
98101 const locationOffset : SourceLocation = {
99102 line : position . line + 1 ,
You can’t perform that action at this time.
0 commit comments