oli/graphql-utils

GraphQL Utilities

0.1 2020-10-31 17:57 UTC

This package is auto-updated.

Last update: 2024-10-29 06:06:01 UTC


README

Build Status License: MIT Codecov.io

Utils for use with webonyx/graphql-php

Quick start

composer require oligus/graphql-utils

sdf

Type Registry

Scalars exposed as static methods of GraphQLUtils\TypeRegistry class:

<?php
use GraphQLUtils\TypeRegistry;

// Built-in Scalar types (wrapped from graphql):
TypeRegistry::string();     // String type
TypeRegistry::int();        // Int type
TypeRegistry::float();      // Float type
TypeRegistry::boolean();    // Boolean type
TypeRegistry::id();         // ID type

// Custom Scalar types:
TypeRegistry::uuid();       // UUID type
TypeRegistry::date();       // Date type
TypeRegistry::dateTime();   // DateTime (Atom) type

Custom Types

UUID Type

TypeRegistry::uuid()

Validates and returns a UUID object of type ramsey/uuid

Date Type

TypeRegistry::date($format)

Validates and returns a DateTime object according to format of your own choosing. You can only initialize the date type with format once. Initializing the date with a spcific format e.g.TypeRegistry::date('d/m/Y') will mean all subsequent requests will be in the same format.

Default format: Y-m-d

Date Time Type

Date time in ATOM format, RFC3339.

Format: Y-m-d\TH:i:sP

Money Type

TypeRegistry::money()

Validates and returns instance of Money (moneyphp/money), a PHP implementation of the Money pattern.