gatsbyjs/gatsby-source-wordpress-experimental

RootQueries with arguments not working

Oliweer opened this issue · 1 comments

Hi i'm using WPGraphQL with WPGraphQL Polylang and it registers a RootQuery for string translations at:

wp-graphql-polylang/src/StringsTranslations.php

        register_graphql_field('RootQuery', 'translateString', [
            'type' => 'String',
            'description' => __(
                'Translate string using pll_translate_string() (Polylang)',
                'wp-graphql-polylang'
            ),
            'args' => [
                'string' => [
                    'type' => [
                        'non_null' => 'String',
                    ],
                ],
                'language' => [
                    'type' => [
                        'non_null' => 'LanguageCodeEnum',
                    ],
                ],
            ],
            'resolve' => function ($source, $args, $context, $info) {
                return pll_translate_string($args['string'], $args['language']);
            },
        ]);

Which shows up in the builtin GraphiQL in WordPress but not when building.

I thought it might be an issue with WPGraphQL Polylang, or the enum but i added this, which does show up under wp { stringyWingy } but it doesn't allow arguments and just returns ""

        register_graphql_field('RootQuery', 'stringyWingy', [
            'type' => 'String',
            'args' => [
                'string' => [
                    'type' => 'String',
                ],
                'language' => [
                    'type' => 'String',
                ],
            ],
            'resolve' => function ($root, $args, $context, $info) {
                return strval($args['string'].$args['language']);
            },
        ]);

I tested it with the standard gatsby starter and just added gatsby-source-wordpress-experimental

Hi @Oliweer , this is a current limitation of this plugin that can't be easily overcome. When you use this plugin you aren't using WPGraphQL directly - this plugin uses the WPGQL schema to build a brand new GraphQL schema based on the WPGQL schema but they aren't the same. See this page for more info https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/docs/features/graphql-wordpress-and-gatsby.md

If you want to use wpgql directly for some things you can pair this plugin with gatsby-source-graphql and your input args will work there.