GraphQLSchema
extends Schema
in package
Defines a Schema that represents this API in GraphQL format. This class is used to generate a GraphQL schema file.
Table of Contents
Constants
- SCHEMA_DIR = '/usr/local/pkg/RESTAPI/.resources/schemas/'
- The directory where schema files are stored.
Properties
- $content_type : string
- $field_enum_types : array<string|int, mixed>
- $file_name : string
- $file_path : string
- $model_input_object_types : array<string|int, mixed>
- $model_object_types : array<string|int, mixed>
- $query_params_type : CustomScalarType
Methods
- __construct() : mixed
- build_schema_url() : void
- Builds a unique endpoint URL for this schema in the pfSense webroot directory.
- endpoint_to_mutations() : array<string|int, mixed>
- Converts an Endpoint object into a GraphQL mutations config. This method is responsible for defining the GraphQL mutation operations that are equivalent to the HTTP request methods supported by the Endpoint.
- endpoint_to_operation_name() : string
- Uses the URL from a given endpoint and converts it to a GraphQL query/mutation name with a given operation prefix.
- endpoint_to_queries() : array<string|int, mixed>
- Converts an Endpoint object into a GraphQL Query config. This method is responsible for defining the GraphQL query operations that are applicable/equivalent to the Endpoint
- field_to_enum() : EnumType
- Converts a Field object into a GraphQL EnumType object. This turns a Field objects 'choices' into an EnumType.
- field_to_type() : Type
- Converts a Field object into a GraphQL schema field Type 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_control_param_args() : array<string|int, mixed>
- Obtains common control parameters as GraphQL mutation operation arguments
- get_endpoint_mutation_types() : array<string|int, mixed>
- Generates all GraphQL Mutation Types all Endpoint's.
- get_endpoint_query_types() : array<string|int, mixed>
- Generates all GraphQL Query Types all Endpoint's with GET methods.
- get_model_input_object_type() : InputObjectType
- Obtains the GraphQL InputObjectType for a given Model.
- get_model_input_object_types() : array<string|int, mixed>
- Obtains GraphQL InputObjectType objects for all Models.
- get_model_object_type() : ObjectType
- Obtains the GraphQL ObjectType object for a given Model.
- get_model_object_types() : array<string|int, mixed>
- Obtains GraphQL ObjectType objects for all Models.
- get_query_query() : array<string|int, mixed>
- Obtains a GraphQL 'query' operation config for a given Endpoint object. This is the GraphQL equivalent to a REST API GET Endpoint that is 'many' enabled.
- get_query_read() : array<string|int, mixed>
- Obtains a GraphQL 'read' operation config for a given Endpoint object. This is the GraphQL equivalent to a REST API GET Endpoint that is not 'many' enabled.
- get_schema() : Schema
- Obtains the top-level GraphQL Schema object.
- get_schema_str() : string
- Obtains the schema as a string. This method must be implemented by the child class and is used to generate the schema file for this class.
- log_error() : void
- Logs an error to the syslog.
- model_to_mutation_args() : array<string|int, mixed>
- Converts a Model object into a GraphQL mutation operation arguments config.
- model_to_object_type() : ObjectType|InputObjectType
- Converts a given Model object to a GraphQL ObjectType or InputObjectType.
- read_schema_from_file() : string
- Reads the schema from file.
- save_schema() : void
- Saves the schema to file.
- get_mutation_create() : array<string|int, mixed>
- Obtains a GraphQL mutation operation config that can be used to create a new object for the assigned Model.
- get_mutation_delete() : array<string|int, mixed>
- Obtains a GraphQL mutation operation config that can be used to delete a new object for the assigned Model.
- get_mutation_delete_all() : array<string|int, mixed>
- Obtains a GraphQL mutation operation config that can be used to delete all existing objects for the assigned Model. This is the GraphQL equivalent to a REST API DELETE Endpoint that is 'many' enabled and has the 'all` parameter set to true.
- get_mutation_delete_many() : array<string|int, mixed>
- Obtains a GraphQL mutation operation config that can be used to delete many existing objects for the assigned Model using a query. This is the GraphQL equivalent to a REST API DELETE Endpoint that is 'many' enabled.
- get_mutation_replace_all() : array<string|int, mixed>
- Obtains a GraphQL mutation operation config that can be used to replace all existing objects for the assigned Model.
- get_mutation_update() : array<string|int, mixed>
- Obtains a GraphQL mutation operation config that can be used to update a new object for the assigned Model.
Constants
SCHEMA_DIR
The directory where schema files are stored.
public
mixed
SCHEMA_DIR
= '/usr/local/pkg/RESTAPI/.resources/schemas/'
Properties
$content_type
public
string
$content_type
= 'text/plain'
The content type for this schema. This is used to determine how the schema is formatted and displayed when accessed via the URL.
$field_enum_types
public
array<string|int, mixed>
$field_enum_types
= []
An array containing all the GraphQL EnumType objects that represent Fields in this API. The array key is the EnumType name and the value is the GraphQL EnumType object.
$file_name
public
string
$file_name
= 'graphql.gql'
The file name for this schema.
$file_path
public
string
$file_path
The full file path to the schema file.
$model_input_object_types
public
array<string|int, mixed>
$model_input_object_types
= []
An array containing all the GraphQL InputObjectType objects that represent Models in this API. The array key is the Model class's FQN and the value is the GraphQL InputObjectType object.
$model_object_types
public
array<string|int, mixed>
$model_object_types
= []
An array containing all the GraphQL ObjectType objects that represent Models in this API. The array key is the Model class's FQN and the value is the GraphQL ObjectType object.
$query_params_type
public
CustomScalarType
$query_params_type
A custom scalar type for arbitrary query parameters.
Methods
__construct()
public
__construct() : mixed
Tags
build_schema_url()
Builds a unique endpoint URL for this schema in the pfSense webroot directory.
public
build_schema_url() : void
endpoint_to_mutations()
Converts an Endpoint object into a GraphQL mutations config. This method is responsible for defining the GraphQL mutation operations that are equivalent to the HTTP request methods supported by the Endpoint.
public
endpoint_to_mutations(Endpoint $endpoint) : array<string|int, mixed>
Parameters
- $endpoint : Endpoint
-
The Endpoint object to convert to GraphQL mutation operations.
Tags
Return values
array<string|int, mixed>endpoint_to_operation_name()
Uses the URL from a given endpoint and converts it to a GraphQL query/mutation name with a given operation prefix.
public
endpoint_to_operation_name(string $operation, Endpoint $endpoint) : string
Parameters
- $operation : string
-
The operation type/prefix for the GraphQL query/mutation.
- $endpoint : Endpoint
-
The Endpoint object to convert to a GraphQL query/mutation name.
Tags
Return values
stringendpoint_to_queries()
Converts an Endpoint object into a GraphQL Query config. This method is responsible for defining the GraphQL query operations that are applicable/equivalent to the Endpoint
public
endpoint_to_queries(Endpoint $endpoint) : array<string|int, mixed>
Parameters
- $endpoint : Endpoint
-
The Endpoint object to convert to a GraphQL query operation.
Tags
Return values
array<string|int, mixed>field_to_enum()
Converts a Field object into a GraphQL EnumType object. This turns a Field objects 'choices' into an EnumType.
public
field_to_enum(Field $field) : EnumType
Parameters
- $field : Field
-
The Field object to convert to a GraphQL EnumType.
Tags
Return values
EnumType —The GraphQL EnumType object that represents this Field.
field_to_type()
Converts a Field object into a GraphQL schema field Type object.
public
field_to_type(Field $field[, Type|null $type = null ][, bool $ignore_required = false ]) : Type
Parameters
- $field : Field
-
The Field object to convert to a GraphQL schema field Type object.
- $type : Type|null = null
-
A nested GraphQL schema field Type object that represents this Field's Type.
- $ignore_required : bool = false
-
Whether this Field should be non-nullable or not.
Tags
Return values
Type —The GraphQL schema field Type object that represents this Field.
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_control_param_args()
Obtains common control parameters as GraphQL mutation operation arguments
public
static get_control_param_args() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>get_endpoint_mutation_types()
Generates all GraphQL Mutation Types all Endpoint's.
public
get_endpoint_mutation_types() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>get_endpoint_query_types()
Generates all GraphQL Query Types all Endpoint's with GET methods.
public
get_endpoint_query_types() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>get_model_input_object_type()
Obtains the GraphQL InputObjectType for a given Model.
public
get_model_input_object_type(string $model_name) : InputObjectType
Parameters
- $model_name : string
-
The FQN of the Model to obtain the GraphQL Type object for.
Tags
Return values
InputObjectTypeget_model_input_object_types()
Obtains GraphQL InputObjectType objects for all Models.
public
get_model_input_object_types() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>get_model_object_type()
Obtains the GraphQL ObjectType object for a given Model.
public
get_model_object_type(string $model_name) : ObjectType
Parameters
- $model_name : string
-
The FQN of the Model to obtain the GraphQL Type object for.
Tags
Return values
ObjectTypeget_model_object_types()
Obtains GraphQL ObjectType objects for all Models.
public
get_model_object_types() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>get_query_query()
Obtains a GraphQL 'query' operation config for a given Endpoint object. This is the GraphQL equivalent to a REST API GET Endpoint that is 'many' enabled.
public
get_query_query(Endpoint $endpoint) : array<string|int, mixed>
Parameters
- $endpoint : Endpoint
-
The Endpoint object to convert to a GraphQL query operation.
Return values
array<string|int, mixed> —The GraphQL 'query' operation config for this Endpoint object.
get_query_read()
Obtains a GraphQL 'read' operation config for a given Endpoint object. This is the GraphQL equivalent to a REST API GET Endpoint that is not 'many' enabled.
public
get_query_read(Endpoint $endpoint) : array<string|int, mixed>
Parameters
- $endpoint : Endpoint
-
The Endpoint object to convert to a GraphQL query operation.
Return values
array<string|int, mixed> —The GraphQL 'read' operation config for this Endpoint object.
get_schema()
Obtains the top-level GraphQL Schema object.
public
get_schema() : Schema
Tags
Return values
Schemaget_schema_str()
Obtains the schema as a string. This method must be implemented by the child class and is used to generate the schema file for this class.
public
get_schema_str() : string
Tags
Return values
string —The schema as a string.
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
model_to_mutation_args()
Converts a Model object into a GraphQL mutation operation arguments config.
public
model_to_mutation_args(Model $model[, bool $require_id = true ][, bool $only_id = false ][, bool $ignore_required = false ][, array<string|int, mixed> $exclude_fields = [] ]) : array<string|int, mixed>
Parameters
- $model : Model
-
The Model object to convert to a GraphQL mutation operation arguments config.
- $require_id : bool = true
-
Whether an ID is required for this mutation operation.
- $only_id : bool = false
-
Whether only the ID is required for this mutation operation.
- $ignore_required : bool = false
-
Whether to ignore required fields for this mutation operation.
- $exclude_fields : array<string|int, mixed> = []
-
An array of field names to exclude from the mutation operation.
Return values
array<string|int, mixed> —The GraphQL mutation operation arguments config for this Model object.
model_to_object_type()
Converts a given Model object to a GraphQL ObjectType or InputObjectType.
public
model_to_object_type(Model $model[, bool $input = false ]) : ObjectType|InputObjectType
Parameters
- $model : Model
-
The Model object to convert to a GraphQL ObjectType or InputObjectType.
- $input : bool = false
-
Whether this ObjectType should be an InputObjectType or not.
Tags
Return values
ObjectType|InputObjectType —A GraphQL ObjectType definition for the given Model object.
read_schema_from_file()
Reads the schema from file.
public
read_schema_from_file() : string
Return values
string —The schema as a string.
save_schema()
Saves the schema to file.
public
save_schema() : void
get_mutation_create()
Obtains a GraphQL mutation operation config that can be used to create a new object for the assigned Model.
protected
get_mutation_create(Endpoint $endpoint) : array<string|int, mixed>
This is the GraphQL equivalent to a REST API POST Endpoint that is not 'many' enabled.
Parameters
- $endpoint : Endpoint
-
The Endpoint object to convert to a GraphQL mutation operation.
Tags
Return values
array<string|int, mixed>get_mutation_delete()
Obtains a GraphQL mutation operation config that can be used to delete a new object for the assigned Model.
protected
get_mutation_delete(Endpoint $endpoint) : array<string|int, mixed>
This is the GraphQL equivalent to a REST API DELETE Endpoint that is not 'many' enabled.
Parameters
- $endpoint : Endpoint
-
The Endpoint object to convert to a GraphQL mutation operation.
Tags
Return values
array<string|int, mixed>get_mutation_delete_all()
Obtains a GraphQL mutation operation config that can be used to delete all existing objects for the assigned Model. This is the GraphQL equivalent to a REST API DELETE Endpoint that is 'many' enabled and has the 'all` parameter set to true.
protected
get_mutation_delete_all(Endpoint $endpoint) : array<string|int, mixed>
Parameters
- $endpoint : Endpoint
-
The Endpoint object to convert to a GraphQL mutation operation.
Tags
Return values
array<string|int, mixed>get_mutation_delete_many()
Obtains a GraphQL mutation operation config that can be used to delete many existing objects for the assigned Model using a query. This is the GraphQL equivalent to a REST API DELETE Endpoint that is 'many' enabled.
protected
get_mutation_delete_many(Endpoint $endpoint) : array<string|int, mixed>
Parameters
- $endpoint : Endpoint
-
The Endpoint object to convert to a GraphQL mutation operation.
Tags
Return values
array<string|int, mixed>get_mutation_replace_all()
Obtains a GraphQL mutation operation config that can be used to replace all existing objects for the assigned Model.
protected
get_mutation_replace_all(Endpoint $endpoint) : array<string|int, mixed>
This is the GraphQL equivalent to a REST API PUT Endpoint that is 'many' enabled.
Parameters
- $endpoint : Endpoint
-
The Endpoint object to convert to a GraphQL mutation operation.
Tags
Return values
array<string|int, mixed>get_mutation_update()
Obtains a GraphQL mutation operation config that can be used to update a new object for the assigned Model.
protected
get_mutation_update(Endpoint $endpoint) : array<string|int, mixed>
This is the GraphQL equivalent to a REST API PATCH Endpoint that is not 'many' enabled.
Parameters
- $endpoint : Endpoint
-
The Endpoint object to convert to a GraphQL mutation operation.