Call to undefined method error when twig debug mode is enabled

Created on 24 November 2023, about 1 year ago
Updated 1 August 2024, 5 months ago

At the moment it is not possible for me to use graphq_twig 3.x in twig debug mode.
I get the following errors:

Error: Call to undefined method Drupal\graphql_twig\GraphQLTwigEnvironment::getGraphQlServer() in __TwigTemplate_a5866ae94e80cde5a46571670087e86d->display() (line 115 of /app/web/modules/contrib/graphql_twig/src/GraphQLTemplateTrait.php).
Error: Call to undefined method Drupal\graphql_twig\GraphQLTwigEnvironment::getGraphQlServer() in __TwigTemplate_a5866ae94e80cde5a46571670087e86d->display() (line 140 of /app/web/modules/contrib/graphql_twig/src/GraphQLTemplateTrait.php).

I'm using graphql 8.x-3.4 with graphql_twig 3.0.0-beta2 and Drupal core 10.1.6 with enabled twig debug mode:

  twig.config:
    debug: true
    auto_reload: true
    cache: false

Any ideas what the issue could be?

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @InaW
  • Merge request !7Fix debug mode → (Open) created by InaW
  • Status changed to Needs review 11 months ago
  • The error occurs where the debug button is rendered:

            $context['graphql_debug'] = [
              '#markup' => sprintf(
                '<div class="graphql-twig-debug-child"><div class="%s" data-graphql-query="%s" data-graphql-variables="%s" data-graphql-server="%s"></div></div>',
                'graphql-twig-debug-wrapper',
                htmlspecialchars($query),
                htmlspecialchars(json_encode($arguments)),
                $this->env->getGraphQlServer()->id()
              ),
            ];
    

    Since the method getGraphQlServer() does not exist in graphql_twig 3.x (but in graphql_twig 4.x does) I reverted the changes and implemented it like it was in 3.0.0-beta1 and set the from url fix to /graphql/explorer

     $form = $('<form method="post" target="_blank"></form>').attr('action', Drupal.url('graphql/explorer')).appendTo(this),
    
  • 🇩🇪Germany larskleiner

    Thanks for opening the merge request. With that patch applied, I still get the following error:

    Error: Cannot access protected property GraphQL\Error\Error::$message in __TwigTemplate_511eccd1dbfb90f954c68860ff9ce526->display() (line 121 of modules/contrib/graphql_twig/src/GraphQLTemplateTrait.php).

    I re-rolled the patch with an additional fix for this error.

  • 🇮🇳India radheymkumar Jaipur, Rajasthan, India

    Wokring patch

    Thanks

    • 47523310 committed on 3.x
      Issue #3404044 by InaW, larskleiner: Call to undefined method error when...
  • Status changed to Fixed 5 months ago
  • 🇬🇧United Kingdom 3li U.K. 🇬🇧
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024