Installing vendor library using composer

Installing vendor library using composer


0

I’m trying to use the https://github.com/webonyx/graphql-php/ library to make graphql requests..
But for some reason it doesn’t work, and I can’t figure out why.

I’m using this command to install:

composer require webonyx/graphql-php

Vendor folder with content + composer.json / composer.lock appears in the project folder.

When I try a simple code like:

<?php

require_once 'vendor/autoload.php';

use GraphQLClient;
use GraphQLQuery;


// Replace with your actual GraphQL endpoint and API key
$graphqlEndpoint = 'https://platformurl';

// Set up the GraphQL client
$client = new Client($graphqlEndpoint);

?>

Fatal error: Uncaught Error: Class "GraphQLClient" not found in
/url/test.php:14 Stack trace: #0 {main} thrown in /url/test.php on
line 14

When I check composer.json it contains this:

{
    "require": {
        "webonyx/graphql-php": "^15.7"
    }
}

I tried composer install / update..
I tried a require with the direct link to graphql folder.
But there is no difference.

I found that there was no src/client.php file in the graphql-php library folder but I don’t know if this is necessary or how that comes (chatGPT said this is the reason why it doesn’t works)..

PHP Version is PHP 8+. What could be the reason?

2 Answers
2


0

If your useing autoload after adding new class you should run composer dump-autoload to cached list of classes


0

As you have seen, there is no GraphQLClient (or Query) classes. Wherever you got the "simple code" from is not how the package is used. I suggest looking in the examples directory and other documentation in the repository to see how it can actually be used.



Leave a Reply

Your email address will not be published. Required fields are marked *