File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,19 +19,29 @@ public function getGraphQLQuery() {
1919 $ includes = [];
2020
2121 if ($ this instanceof \Twig_Template) {
22+ /** @var \Twig_Template $parent */
23+ $ parent = $ this ->graphqlParent ? $ this ->loadTemplate ($ this ->graphqlParent ) : NULL ;
24+
2225 // If there is no query for this template, try to get one from the
2326 // parent template.
2427 if ($ this ->graphqlQuery ) {
2528 $ query = $ this ->graphqlQuery ;
2629 }
27- elseif ($ this -> graphqlParent ) {
28- $ query = $ this -> loadTemplate ( $ this -> graphqlParent ) ->getGraphQLQuery ();
30+ elseif ($ parent ) {
31+ $ query = $ parent ->getGraphQLQuery ();
2932 }
3033
3134 // Recursively collect all included fragments.
3235 $ includes = array_map (function ($ template ) {
3336 return $ this ->loadTemplate ($ template )->getGraphQLQuery ();
3437 }, $ this ->getGraphQLIncludes ());
38+
39+ // Always add includes from parent templates.
40+ if ($ parent ) {
41+ $ includes += array_map (function ($ template ) {
42+ return $ this ->loadTemplate ($ template )->getGraphQLQuery ();
43+ }, $ parent ->getGraphQLIncludes ());
44+ }
3545 }
3646
3747
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ function setUp() {
2828 'dynamic_include ' => '{% graphql %}a{% endgraphql %}{% include sub_fragment with { foo: "bar" } %} ' ,
2929 'fragment ' => '{% graphql %}b{% endgraphql %}{% include "sub_fragment" %} ' ,
3030 'sub_fragment ' => '{% graphql %}c{% endgraphql %} ' ,
31+ 'extend_include ' => '{% graphql %}a{% endgraphql %}{% extends "fragment" %} '
3132 ]));
3233 $ this ->twig ->addExtension (new GraphQLTwigExtension ());
3334 }
@@ -66,4 +67,8 @@ function testDynamicInclude() {
6667 $ this ->assertGraphQLQuery ('dynamic_include ' , "a " );
6768 }
6869
70+ function testExtendInclude () {
71+ $ this ->assertGraphQLQuery ('extend_include ' , "a \nc " );
72+ }
73+
6974}
You can’t perform that action at this time.
0 commit comments