Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rizwan157's avatar

How To Consume GraphQL API in Laravel?

I've to use third party GraphQL API in Laravel. I've to book a meeting from that API. I'm confused about how can I implement it.

Its an appointment booking platform. I've to book a meeting using GraphQL API.

There is a mutation given by the third party that I've to use.

mutation { createMeeting(input: { meetingName: "API Video Conference Test", scheduledDateTime: "Fri Apr 24 2020 13:45:00 -0500", scheduledTimeZone: "EDT/UTC-05:00", enableTwilio: 1, }) { message result status } }

I've installed "nuwave/lighthouse" I've also installed GraphQL playground. In PlayGround APIs are working well.

Do I need to use Guzzle / Curl to submit the data? If yes then how can I pass the mutation parameter?

Can any champ help me regarding this?

Regards, Rizwan Saleem

0 likes
1 reply
dannielb's avatar

Hello!

I believe that Graphql API mutations in the end are HTTP POST requests, I haven't tested the code, but you can do something like:

$client = new Client([
    'headers' => [ 'Content-Type' => 'application/json' ]
]); // GuzzleHttp

$data = [
	'input' => [
                'meetingName' => 'API Video Conference Test',
                'scheduledDateTime' => 'Fri Apr 24 2020 13:45:00 -0500',
                'scheduledTimeZone' => 'EDT/UTC-05:00',
                'enableTwillion' => 1
          ]
];

$response = $client->post($url, [
            'body' => "mutation { createMeeting(" . json_encode($data) . ") { message result status } } "
]);

$json = json_decode($response->getBody()->getContents());

Reference: https://www.apollographql.com/blog/4-simple-ways-to-call-a-graphql-api-a6807bcdb355

2 likes

Please or to participate in this conversation.