/graphql-types

Generic GraphQL types

Primary LanguagePHPMIT LicenseMIT

Generic GraphQL Types

Build Status License: MIT Codecov.io

A collection of generic types for use with webonyx/graphql-php

Quick start

TOC

Adding types

With type decorator
$schema = BuildSchema::build($source, TypeConfigDecorator::resolve());

If you already have a type config decorator, you can add specific types to your current type config decorator:

...
switch($typeConfig['name']) {
    case 'UUID':
        $typeConfig = array_merge($typeConfig, UuidType::config());
        break;
}
...
Directly

You can also just add types directly

$uuid = new UuidType();

Scalar types

DateTime

The DateTime scalar type represents time data, represented as an ISO-8601 encoded UTC date string.

GraphQL definition:

scalar DateTime

Query result:

{
    "data": {
        "record": {
            "dateTime": "2020-11-05T12:33:45+00:00"
        }
    }
}

Email

Standard email validation

GraphQL definition:

scalar Email

Money

The Money scalar type represents the lowest denominator of a currency.

Will resolve to moneyphp/money type.

GraphQL definition:

scalar Money

UUID

The UUID scalar type represents a universally unique identifier (UUID).

Will resolve to ramsey/uuid type.

GraphQL definition:

scalar UUID

URL

URL a Uniform Resource Locator.

GraphQL definition:

scalar URL