Download the PHP package cis-bv/gql-builder without Composer
On this page you can find all versions of the php package cis-bv/gql-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package gql-builder
PHP GraphQL Query-Builder
Inspired by the Builder-Part of the PHP GraphQL Client by mghonemiy this builder provides a simple way to generate Graph-QL-Queries and provide the string.
This library don't include any Client or Response-Decoding functionality and requires the handling of Client-Request and -Responses separately.
Installation
Usage
The main entry point for usage is the Query-class. You can simply create a Query with either a static or typical instantiate call.
Create a Query
To create a simple query (here querying a device_list
and retrieve id
and name
of each device) you have three ways:
The example above will create the following query:
If you set the Pretty-Flag:
The query will have a pretty output:
Please keep in mind that these examples are the easiest implementation that it is possible and the "global" query will only be set if scalar fields are within the Selection-Set.
The clean and correct way (and also a more complex example) will be the generation of an "empty" root-query and define all Queries within the selection set:
The example above also includes Arguments for Filtering (here a more complex FilterQueryType) and using a Variable.
The following query (when set to Pretty Print) will be generated and is a real life example for a Strawberry GraphQL-Endpoint:
Static Query-Builder
Within a selection Set you generally can create a new Query with the following code:
But you can also use a static build:
This is a short version and will return a new Query Instance.
Earlier we also have seen the Query::create(...$parameters)
statement. Another Advantage of this call is that Variables can be easily created as Arrays without the new Variable(...$parameters)
statement.
For easier understanding the named parameter style of PHP8 is used: