GraphQLResponse
extends Response
in package
Response class that represents a GraphQL response. Unlike other responses, this response does not represent a successful or failed response, but rather a generic one where the error details are embedded in the response data.
This is essentially a wrapper around the ExecutionResult object from the GraphQL library.
Table of Contents
Properties
- $_links : ResourceLinkSet
- $code : int
- $data : Model|ModelSet
- $execution_result : ExecutionResult
- $help_text : string
- $message : mixed
- $response_id : string
- $status : string
Methods
- __construct() : mixed
- Constructs a new GraphQLResponse object.
- get_class_fqn() : string
- Obtains the fully qualified name of the called class.
- get_class_shortname() : string
- Obtains the shortname of the called class.
- get_classes_in_namespace() : array<string|int, mixed>
- Obtains all classes associated with this class's current namespace.
- get_http_status_message() : string
- Fetch HTTP status message associated with a given HTTP status code.
- log_error() : void
- Logs an error to the syslog.
- to_graphql_response() : GraphQLResponse
- Converts a standard Response object into a GraphQLResponse object. This is useful for converting standard REST API responses into responses that better adhere to the GraphQL specification.
- to_openapi_schema() : array<string|int, mixed>
- Obtains the OpenAPI schema for this GraphQLResponse object.
- to_representation() : array<string|int, mixed>
- Converts this GraphQLResponse object to an array representation of its contents.
Properties
$_links
public
ResourceLinkSet
$_links
= new ResourceLinkSet()
$code
public
int
$code
= 200
The HTTP status code that corresponds with the API response. Note: For GraphQL, all responses are considered successful, so this is always set to 200.
$data
public
Model|ModelSet
$data
= new GraphQL()
$execution_result
public
ExecutionResult
$execution_result
The GraphQL ExecutionResult object that contains the query results.
$help_text
public
string
$help_text
= 'The GraphQL query execution completed. All GraphQL responses return a 200 OK regardless of whether ' . 'the query was successful or not. Use the "errors" field in the response data to determine if the query ' . 'was successful.'
A description for this response to use in documentation.
$message
public
mixed
$message
= ''
$response_id
public
string
$response_id
= ''
$status
public
string
$status
The HTTP status message that corresponds with the HTTP status code.
Methods
__construct()
Constructs a new GraphQLResponse object.
public
__construct([mixed $message = '' ][, string $response_id = '' ][, Model|ModelSet $data = new GraphQL() ][, ResourceLinkSet $_links = new ResourceLinkSet() ]) : mixed
Parameters
- $message : mixed = ''
-
The verbose message to include in the Response. (unused)
- $response_id : string = ''
-
A unique response ID that can be used to identify this specific response. This should be unique from any other Response object in the codebase! (unused)
- $data : Model|ModelSet = new GraphQL()
-
The GraphQL Model object that contains the GraphQL ExecutionResult object.
- $_links : ResourceLinkSet = new ResourceLinkSet()
-
A ResourceLinkSet containing applicable ResourceLinks for this response. (unused)
get_class_fqn()
Obtains the fully qualified name of the called class.
public
get_class_fqn() : string
Return values
string —The FQN for this object's class.
get_class_shortname()
Obtains the shortname of the called class.
public
get_class_shortname() : string
Return values
string —The shortname for this object's class.
get_classes_in_namespace()
Obtains all classes associated with this class's current namespace.
public
get_classes_in_namespace([bool $shortnames = false ]) : array<string|int, mixed>
Parameters
- $shortnames : bool = false
Return values
array<string|int, mixed> —An array of classes currently in this object's namespace
get_http_status_message()
Fetch HTTP status message associated with a given HTTP status code.
public
final static get_http_status_message(int $http_status) : string
Parameters
- $http_status : int
-
The HTTP status code to fetch the descriptive message for.
Return values
string —The HTTP status message associated with the give HTTP response code OR unknown
if not found.
log_error()
Logs an error to the syslog.
public
static log_error(string $message) : void
Parameters
- $message : string
-
The error message to write to the syslog
to_graphql_response()
Converts a standard Response object into a GraphQLResponse object. This is useful for converting standard REST API responses into responses that better adhere to the GraphQL specification.
public
static to_graphql_response(Response $response) : GraphQLResponse
Parameters
- $response : Response
-
The Response object to convert.
Return values
GraphQLResponse —The converted GraphQLResponse object.
to_openapi_schema()
Obtains the OpenAPI schema for this GraphQLResponse object.
public
to_openapi_schema() : array<string|int, mixed>
Return values
array<string|int, mixed> —This Response object as an OpenAPI schema.
to_representation()
Converts this GraphQLResponse object to an array representation of its contents.
public
to_representation() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array containing the response details.