wp-graphql / wp-graphql-smart-cache

Smart Caching & Cache Invalidation for WPGraphQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fatal error when i try to activate the plugin

stephanedemotte opened this issue · comments

Hello

I try to test the plugin, the install run fine with composer require wp-graphql/wp-graphql-smart-cache
But when i try to activate it, i've got this warning

Warning: require(/home/stephane/Projects/website/web/plugins/wp-graphql-smart-cache/vendor/autoload.php): Failed to open stream: No such file or directory in /home/stephane/Projects/website/web/plugins/wp-graphql-smart-cache/wp-graphql-smart-cache.php on line 41

@stephanedemotte thanks for reporting this. I will try and reproduce.

If you install by downloading the zip from the latest release, do you get the same error or only when installing from Composer?

@jasonbahl nop when i use the "zip" version i can activate the plugin, but the cache doesn't work... the plugin is activated, i've set the max-age and the expiration but the query is never cached, the graphqlSmartCache return always an empty array (the test is made via the GraphiQpl Ide)

@stephanedemotte can you screenshot your "GraphQL > Settings > Cache" tab so I can see how the settings are configured?

Also @stephanedemotte are you making requests as an authenticated user? Authenticated requests bypass the cache. Only public requests will be cached and returned from the cache.

In the GraphiQL IDE in the WP Admin, you can toggle between authenticated and public by clicking the user avatar button next to the Play button:

CleanShot 2022-11-11 at 10 41 28

@stephanedemotte I've opened a PR (#179) which I believe will help prevent the error you experienced when installing from Composer.

Currently the plugin has a hard require __DIR__ . '/vendor/autoload.php';

But, for folks installing with Composer, the autoload.php is in the parent project, not in the plugin, so that's why you saw the fatal error, we were trying to require a file that didn't exist.

The PR wraps that require statement with a file_exists() check to ensure the file exists before trying to load it.

The parent project's autoloader should load all the classes needed by this plugin, but we also do a check for the WPGraphQL\SmartCache\Document class to determine if the plugin can be loaded or not.

If that class doesn't exist, the parent autoloader didn't load it properly and we prevent execution and should avoid errors.

you're right i've been authenticated, when i use public request it work !

thank you !