Skip to content

Latest commit

 

History

History
133 lines (113 loc) · 3.17 KB

types.rst

File metadata and controls

133 lines (113 loc) · 3.17 KB

Data Types

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.

Data Type Mappings

Data Type Mappings
GraphQL and Doctrine PHP Javascript
bigint string integer or 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
datetime DateTime ISO 8601 date string
datetime_immutable DateTimeImmutable ISO 8601 date string
datetimetz DateTime ISO 8601 date string
datetimetz_immutable DateTimeImmutable ISO 8601 date string
decimal string float
float float float
int & integer integer integer
json string string of json
simple_array array of strings array of strings
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

See also Doctrine Mapping Types.

Using 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
                },
            ],
        ],
    ]),
]);

Custom Types

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.