webonyx/graphql-php includes the basic GraphQL types.
This library has many other types that are primarily used to map Doctrine types to GraphQL types.
Doctrine (GraphQL type if another) |
PHP |
Javascript |
|---|---|---|
ascii_string |
string |
string |
bigint |
string |
integer or string |
binary (as Blob) |
string (binary) |
Base64 encoded string |
blob |
string (binary) |
Base64 encoded string |
boolean |
boolean |
boolean |
date |
DateTime |
string as Y-m-d |
date_immutable |
DateTimeImmutable |
string as Y-m-d |
dateinterval |
DateInterval |
ISO 8601 duration string, e.g. P1DT2H or -P1D |
datetime |
DateTime |
ISO 8601 date string |
datetime_immutable |
DateTimeImmutable |
ISO 8601 date string |
datetime_utc (as datetime) |
DateTime |
ISO 8601 date string in UTC |
datetime_utc_immutable (as datetime_immutable) |
DateTimeImmutable |
ISO 8601 date string in UTC |
datetimetz |
DateTime |
ISO 8601 date string |
datetimetz_immutable |
DateTimeImmutable |
ISO 8601 date string |
decimal |
string |
string, which keeps its precision |
enum |
string |
string |
float |
float |
float |
guid |
string |
string |
int & integer |
integer |
integer |
json |
array |
string of json, or the value with |
json_object, jsonb and jsonb_object (as json) |
stdClass or array |
string of json, or the value with |
number |
|
string |
simple_array |
array of strings |
array of strings |
smallfloat |
float |
float |
smallint |
integer |
integer |
string |
string |
string |
text |
string |
string |
time |
DateTime |
string as H:i:s or H:i:s.u |
time_immutable |
DateTimeImmutable |
string as H:i:s or H:i:s.u |
datetime_utc, datetime_utc_immutable, enum, json_object,
jsonb, jsonb_object, number and smallfloat are types of DBAL 4.
A decimal or number is a string in GraphQL, which keeps its precision. An input or
filter value of it is also a string; convert a number value to a
BcMath\Number before setting it on an entity.
A dateinterval is stored as a string, which does not order as the duration
does, so it has only the eq, neq, in, notin and isnull
filters.
A datetime or datetime_immutable column stores a date and time without
an offset, and Doctrine reads it in PHP’s default timezone. A value sent to a
DateTime or DateTimeImmutable argument or input, such as
2004-02-12T15:19:21+05:00, is therefore converted to the default timezone,
keeping its instant, so it is filtered and stored as that instant. A
DateTimeTZ value keeps its offset, for a datetimetz column on a
database which stores one; on a database which does not, such as MySQL or
SQLite, send a datetimetz value in the default timezone.
A DateTime, DateTimeImmutable, DateTimeTZ or DateTimeTZImmutable
value may have a fraction of a second, such as 2004-02-12T15:19:21.123Z,
which JavaScript’s Date.toISOString() gives. PHP holds microseconds, so
digits after the sixth are dropped. A value is serialized with its fraction,
as 2004-02-12T15:19:21.123000+00:00, only when it has one; a value of whole
seconds is serialized as 2004-02-12T15:19:21+00:00. A datetime column
stores whole seconds unless its type is given a precision.
A field mapped with an enumType is represented by the value of the enum,
the value stored in the database, as the field’s type. An input or filter
value of it is also the value; use Enum::from() to convert it before
setting it on an entity. A custom hydrator strategy is given the enum case.
See also Doctrine Mapping Types.
You may use any of the above types freely such as a blob for an input type.
use ApiSkeletons\Doctrine\ORM\GraphQL\Type\TypeContainer;
$schema = new Schema([
'mutation' => new ObjectType([
'name' => 'mutation',
'fields' => [
'uploadFile' => [
'type' => $driver->type(ArtistFile::class),
'args' => [
'file' => $driver->type('blob'),
],
'resolve' => function ($root, array $args, $context, ResolveInfo $info) use ($driver) {
/**
* $args['file'] will be sent base64 encoded then
* unencoded in the PHP type so by the time it gets
* here it is already an uploaded file
*/
// ...save to doctrine blob column
},
],
],
]),
]);
If your schema has a timestamp type, that data type is not supported
by this library. But adding the type is just a matter of creating a
new Timestamp type extending GraphQL\Type\Definition\ScalarType then adding
the type to the type container.
$driver->get(TypeContainer::class) ->set('timestamp', fn() => new Timestamp());
See also Serve a CSV Field as a GraphQL Array.
This is documentation for API-Skeletons/doctrine-orm-graphql. Please add your ★ star to the project.