cms icon indicating copy to clipboard operation
cms copied to clipboard

GraphQL API does not work in 5.5.0

Open thomas4Bitcraft opened this issue 1 year ago • 10 comments

Bug description

The GraphQL Api does not work in the latest Statamic Version. No query is possible, the explorer window is empty and there is also an error in the Docs.

image-1

How to reproduce

Query:

query MyQuery {
  ping
}

Result: {"errors":[{"message":"Cannot query field "ping" on type "Query".","locations":[{"line":2,"column":3}],"extensions":{"file":"/home/vagrant/code/xyz/vendor/webonyx/graphql-php/src/Validator/Rules/FieldsOnCorrectType.php","line":43}}]}

Logs

No response

Environment

Environment
Application Name: xyz
Laravel Version: 11.7.0
PHP Version: 8.2.7
Composer Version: 2.7.6
Environment: local
Debug Mode: ENABLED
URL: xyz.com
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: null
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 2
Sites: 2 (DE, EN)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.5.0 PRO

Statamic Addons
bitcraft/simple-seo: dev-master
statamic/eloquent-driver: 4.0.0

Statamic Eloquent Driver
Asset Containers: eloquent
Assets: eloquent
Blueprints: eloquent
Collection Trees: eloquent
Collections: eloquent
Entries: eloquent
Forms: eloquent
Global Sets: eloquent
Global Variables: eloquent
Navigation Trees: eloquent
Navigations: eloquent
Revisions: eloquent
Taxonomies: eloquent
Terms: eloquent

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

thomas4Bitcraft avatar May 27 '24 14:05 thomas4Bitcraft

It seems to be fine. Are there any errors in your log file?

jasonvarga avatar May 27 '24 14:05 jasonvarga

@jasonvarga Yes I have this error in the logs:

[2024-05-27 14:04:30] local.ERROR: Cannot query field "ping" on type "Query". {"exception":"[object] (GraphQL\\Error\\Error(code: 0): Cannot query field \"ping\" on type \"Query\". at /home/vagrant/code/xyz/vendor/webonyx/graphql-php/src/Validator/Rules/FieldsOnCorrectType.php:43)
[stacktrace]
#0 /home/vagrant/code/xyz/vendor/webonyx/graphql-php/src/Language/Visitor.php(390): GraphQL\\Validator\\Rules\\FieldsOnCorrectType->GraphQL\\Validator\\Rules\\{closure}()
#1 /home/vagrant/code/xyz/vendor/webonyx/graphql-php/src/Language/Visitor.php(453): GraphQL\\Language\\Visitor::GraphQL\\Language\\{closure}()
#2 /home/vagrant/code/xyz/vendor/webonyx/graphql-php/src/Language/Visitor.php(263): GraphQL\\Language\\Visitor::GraphQL\\Language\\{closure}()
#3 /home/vagrant/code/xyz/vendor/webonyx/graphql-php/src/Validator/DocumentValidator.php(118): GraphQL\\Language\\Visitor::visit()
#4 /home/vagrant/code/xyz/vendor/webonyx/graphql-php/src/GraphQL.php(154): GraphQL\\Validator\\DocumentValidator::validate()
#5 /home/vagrant/code/xyz/vendor/webonyx/graphql-php/src/GraphQL.php(96): GraphQL\\GraphQL::promiseToExecute()
#6 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/GraphqlExecutionMiddleware.php(32): GraphQL\\GraphQL::executeQuery()
#7 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/AbstractExecutionMiddleware.php(31): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\GraphqlExecutionMiddleware->handle()
#8 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\AbstractExecutionMiddleware->resolve()
#9 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/AbstractExecutionMiddleware.php(33): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#10 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/AddAuthUserContextValueMiddleware.php(28): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\AbstractExecutionMiddleware->Rebing\\GraphQL\\Support\\ExecutionMiddleware\\{closure}()
#11 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/AbstractExecutionMiddleware.php(31): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\AddAuthUserContextValueMiddleware->handle()
#12 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\AbstractExecutionMiddleware->resolve()
#13 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/AbstractExecutionMiddleware.php(33): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#14 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/AutomaticPersistedQueriesMiddleware.php(42): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\AbstractExecutionMiddleware->Rebing\\GraphQL\\Support\\ExecutionMiddleware\\{closure}()
#15 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/AbstractExecutionMiddleware.php(31): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\AutomaticPersistedQueriesMiddleware->handle()
#16 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\AbstractExecutionMiddleware->resolve()
#17 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/AbstractExecutionMiddleware.php(33): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#18 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/ValidateOperationParamsMiddleware.php(39): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\AbstractExecutionMiddleware->Rebing\\GraphQL\\Support\\ExecutionMiddleware\\{closure}()
#19 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Support/ExecutionMiddleware/AbstractExecutionMiddleware.php(31): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\ValidateOperationParamsMiddleware->handle()
#20 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Rebing\\GraphQL\\Support\\ExecutionMiddleware\\AbstractExecutionMiddleware->resolve()
#21 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#22 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(129): Illuminate\\Pipeline\\Pipeline->then()
#23 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/GraphQL.php(169): Illuminate\\Pipeline\\Pipeline->thenReturn()
#24 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/GraphQL.php(151): Rebing\\GraphQL\\GraphQL->executeViaMiddleware()
#25 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/GraphQL.php(137): Rebing\\GraphQL\\GraphQL->executeAndReturnResult()
#26 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/GraphQLController.php(41): Rebing\\GraphQL\\GraphQL->execute()
#27 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/Helpers.php(24): Rebing\\GraphQL\\GraphQLController->Rebing\\GraphQL\\{closure}()
#28 /home/vagrant/code/xyz/vendor/rebing/graphql-laravel/src/GraphQLController.php(37): Rebing\\GraphQL\\Helpers::applyEach()
#29 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Rebing\\GraphQL\\GraphQLController->query()
#30 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\\Routing\\Controller->callAction()
#31 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Routing/Route.php(260): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#32 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Routing/Route.php(206): Illuminate\\Routing\\Route->runController()
#33 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Routing/Router.php(806): Illuminate\\Routing\\Route->run()
#34 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#35 /home/vagrant/code/xyz/vendor/statamic/cms/src/Http/Middleware/HandleToken.php(13): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#36 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Statamic\\Http\\Middleware\\HandleToken->handle()
#37 /home/vagrant/code/xyz/vendor/statamic/cms/src/Http/Middleware/RequireStatamicPro.php(17): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#38 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Statamic\\Http\\Middleware\\RequireStatamicPro->handle()
#39 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#40 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Routing/Router.php(805): Illuminate\\Pipeline\\Pipeline->then()
#41 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Routing/Router.php(784): Illuminate\\Routing\\Router->runRouteWithinStack()
#42 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Routing/Router.php(748): Illuminate\\Routing\\Router->runRoute()
#43 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Routing/Router.php(737): Illuminate\\Routing\\Router->dispatchToRoute()
#44 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\\Routing\\Router->dispatch()
#45 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#46 /home/vagrant/code/xyz/vendor/statamic/cms/src/Http/Middleware/StopImpersonating.php(12): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#47 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Statamic\\Http\\Middleware\\StopImpersonating->handle()
#48 /home/vagrant/code/xyz/vendor/statamic/cms/src/Http/Middleware/DisableFloc.php(17): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#49 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Statamic\\Http\\Middleware\\DisableFloc->handle()
#50 /home/vagrant/code/xyz/vendor/statamic/cms/src/Http/Middleware/CheckMultisite.php(15): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#51 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Statamic\\Http\\Middleware\\CheckMultisite->handle()
#52 /home/vagrant/code/xyz/vendor/statamic/cms/src/Http/Middleware/CheckComposerJsonScripts.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#53 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Statamic\\Http\\Middleware\\CheckComposerJsonScripts->handle()
#54 /home/vagrant/code/xyz/vendor/statamic/cms/src/Http/Middleware/PoweredByHeader.php(18): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#55 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Statamic\\Http\\Middleware\\PoweredByHeader->handle()
#56 /home/vagrant/code/xyz/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(59): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#57 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle()
#58 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#60 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#61 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#62 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(51): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#63 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#64 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#65 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\ValidatePostSize->handle()
#66 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(110): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#67 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#68 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#69 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\HandleCors->handle()
#70 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#71 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#72 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#73 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then()
#74 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#75 /home/vagrant/code/xyz/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1172): Illuminate\\Foundation\\Http\\Kernel->handle()
#76 /home/vagrant/code/xyz/public/index.php(17): Illuminate\\Foundation\\Application->handleRequest()
#77 {main}
"} 

thomas4Bitcraft avatar May 27 '24 15:05 thomas4Bitcraft

@jasonvarga Could the reason be the eloquent addon?

thomas4Bitcraft avatar May 27 '24 16:05 thomas4Bitcraft

Seems to be working fine for me, even with the Eloquent Driver 🤔

What does your config/statamic/graphql.php file look like?

duncanmcclean avatar May 28 '24 12:05 duncanmcclean

@duncanmcclean This is the current config:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | GraphQL
    |--------------------------------------------------------------------------
    |
    | Here you may enable the GraphQL API, and select which resources
    | are available to be queried, depending on your site's needs.
    |
    | https://statamic.dev/graphql
    |
    */

    'enabled' => env('STATAMIC_GRAPHQL_ENABLED', true),

    'resources' => [
        'collections' => true,
        'navs' => true,
        'taxonomies' => false,
        'assets' => true,
        'globals' => true,
        'forms' => true,
        'sites' => true,
        'users' => false,
    ],

    /*
    |--------------------------------------------------------------------------
    | Queries
    |--------------------------------------------------------------------------
    |
    | Here you may list queries to be added to the Statamic schema.
    |
    | https://statamic.dev/graphql#custom-queries
    |
    */

    'queries' => [
        //
    ],

    /*
    |--------------------------------------------------------------------------
    | Middleware
    |--------------------------------------------------------------------------
    |
    | Here you may list middleware to be added to the Statamic schema.
    |
    | https://statamic.dev/graphql#custom-middleware
    |
    */

    'middleware' => [
        //
    ],

    /*
    |--------------------------------------------------------------------------
    | Caching
    |--------------------------------------------------------------------------
    |
    | By default, Statamic will cache each request until the specified
    | expiry, or until content is changed. See the documentation for
    | more details on how to customize your cache implementation.
    |
    | https://statamic.dev/graphql#caching
    |
    */

    'cache' => [
        'expiry' => 60,
    ],

];

thomas4Bitcraft avatar May 28 '24 13:05 thomas4Bitcraft

Thanks! Your GraphQL looks pretty much the same as mine.

I'm still unable to replicate, even using the Eloquent Driver. GraphQL queries are executing as expected... 🤔

CleanShot 2024-07-12 at 12 10 45

Are you able to replicate the issue on a fresh Statamic site?

duncanmcclean avatar Jul 12 '24 11:07 duncanmcclean

Are you able to try uninstalling the bitcraft/simple-seo addon to see if that makes a difference at all?

duncanmcclean avatar Jul 12 '24 11:07 duncanmcclean

Just following up, can you try to install the Simple SEO addon to see if that helps at all? It's the only difference I can see between our sites. It looks like a private addon so I can't test with it.

duncanmcclean avatar Aug 29 '24 21:08 duncanmcclean

In the past I had a similar issue because the main navigation blueprint had no fields assigned to it. It had some in the navigation UI but not in the blueprint.

arcs- avatar Sep 13 '24 11:09 arcs-

That's the reason for this issue. Have a nav with no blueprint fields. This is definitely a bug. A workaround for now is adding a hidden field to your nav's blueprint.

jasonvarga avatar Sep 13 '24 13:09 jasonvarga

Should be closed by https://github.com/statamic/cms/pull/11537 and fixed in v5.51.0+

ryanmitchell avatar Mar 19 '25 07:03 ryanmitchell