GraphQL
The Graphql class is a utility for interacting with GraphQL APIs. It provides a single static function to send queries or mutations to a GraphQL endpoint and retrieve the results.
Since the method is static, you do not need to create an instance of this class.
request
Sends a query or a mutation to a specified GraphQL API endpoint.
Parameters
url: The endpoint URL of the GraphQL API.document: The GraphQL query or mutation, written in standard GraphQL syntax.variables: An optional object containing any variables required by the document.headers: An optional object for sending request headers, commonly used for authentication.
Example: Simple Query This example queries for a list of movies.
# url
https://api.example.com/graphql
# document
query {
movies {
id
title
releaseYear
}
}Example: Query with Variables This example fetches a single movie by its ID, which is passed as a variable.
Example: Mutation This example creates a new movie.
Example: Query with Authentication This example sends an Authorization header with a Bearer token.
Output The data payload returned by the GraphQL API in response to the query or mutation.
Last updated