GraphQL schema library.
| Method | Parameters |
|---|---|
| addInterface | InterfaceType |
Available types:
GQLSchema\Types\Scalars\BooleanType
GQLSchema\Types\Scalars\FloatType
GQLSchema\Types\Scalars\IDType
GQLSchema\Types\Scalars\IntegerType
GQLSchema\Types\Scalars\StringType
GQLSchema\Types\InterfaceTypeType modifiers are used in conjunction with types, add modifier to a type to modify the type in question.
| Type | Syntax | Example |
|---|---|---|
| Nullable Type | <type> | String |
| Non-null Type | <type>! | String! |
| List Type | [<type>] | [String] |
| List of Non-null Types | [<type>!] | [String!] |
| Non-null List Type | [<type>]! | [String]! |
| Non-null List of Non-null Types | [<type>!]! | [String!]! |
Example:
$typeModifier = new TypeModifier($nullable = false, $listable = true, $nullableList = false);
$type = new BooleanType($typeModifier);
echo $type; // [bool!]!Example:
$type = new BooleanType();
echo $type; // BoolExample:
$fields = new FieldCollection();
$fields->add(new Field('name', new StringType()));
$fields->add(new Field('age', new IntegerType()));
$fields->add(new Field('size', new IntegerType()));
$interface = new InterfaceType('Wine', $fields, 'My interface description');
// Yields
"""
My interface description
"""
interface Wine {
name: String
age: Int
size: Int
}Example:
$fields = new FieldCollection();
$fields->add(new Field('name', new StringType()));
$fields->add(new Field('age', new IntegerType()));
$fields->add(new Field('size', new IntegerType()));
$object = new ObjectType('Wine', $fields, 'My object description');
echo $object;
// Yields
type Wine {
name: String
age: Int
size: Int
}
// Add interface
$fields = new FieldCollection();
$fields->add(new Field('name', new StringType()));
$interface = new InterfaceType('Name', $fields);
$object->addInterface($interface);
echo $object;
// Yields
type Wine implements Name {
name: String
age: Int
size: Int
}Example:
// Simple
$field = new Field('simpleField', new IntegerType());
echo $field; // simpleField: Int
// With arguments
$arguments = new ArgumentCollection();
$arguments->add(new Argument(new BooleanType(new TypeModifier($nullable = false)), null, 'booleanArg'));
$arguments->add(new Argument(new IntegerType(new TypeModifier($nullable = false)), null, 'integerArg'));
$arguments->add(new Argument(new StringType(new TypeModifier($nullable = false)), new ValueString('test'), 'stringArg'));
$field = new Field('testField', new IntegerType(new TypeModifier(false)), $arguments);
echo $field; // testField(booleanArg: Boolean!, integerArg: Int!, stringArg: String! = "test"): Int!'Create arguments
Example:
// Boolean with no default value
$arg = new Argument(new BooleanType(), null, 'argName');
echo $arg; // argName: Boolean
// Boolean collection non nullable
$arg = new Argument(new BooleanType(new TypeModifier($nullable = true, $listable = true, $nullableList = false), null, 'argName');
echo $arg; // argName: [Boolean]!
// Boolean with default value
$arg = new Argument(new BooleanType(), new ValueBoolean(false), 'argName');
echo $arg; // argName: Boolean = falseSet simple scalar values for default values in the schema.
Available values:
GQLSchema\Values\ValueBoolean
GQLSchema\Values\ValueFloat
GQLSchema\Values\ValueInteger
GQLSchema\Values\ValueNull
GQLSchema\Values\ValueStringExample:
$bool = new ValueBoolean(true);
$bool->getValue(); // true
echo $bool; // 'true'
$float = new ValueFloat(23.45);
$float->getValue(); // 23.45
echo $float; // '23.45'
$int = new ValueInteger(5);
$float->getValue(); // 5
echo $float; // '5'
$null = new ValueNull();
$null->getValue(); // null
echo $null; // 'null'
$string = new ValueString('test string);
$string->getValue(); // 'test string'
echo $string; // '"test string"'Download and build docker container
$ makeAccess docker image
$ make bash