PHPackages                             stagem/php-graphql-scalars - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. stagem/php-graphql-scalars

ActiveLibrary[API Development](/categories/api)

stagem/php-graphql-scalars
==========================

PHP library of custom GraphQL Scalars for creating precise type-safe GraphQL schemas

424.7k↓33.3%2PHP

Since Jun 11Pushed 5y ago2 watchersCompare

[ Source](https://github.com/stagemteam/php-graphql-scalars)[ Packagist](https://packagist.org/packages/stagem/php-graphql-scalars)[ RSS](/packages/stagem-php-graphql-scalars/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP GraphQL Scalars
===================

[](#php-graphql-scalars)

Custom GraphQL Scalars for creating precise type-safe GraphQL schemas.

Requirements
------------

[](#requirements)

- PHP 7.2+
- [PHP Webonyx GraphQL](https://github.com/webonyx/graphql-php)

Installation
------------

[](#installation)

- using [composer](http://getcomposer.org): `composer require stagem/php-graphql-scalars`
- using other [PSR-4](http://www.php-fig.org/psr/psr-4/) compliant autoloader: clone this project to where your included libraries are and point your autoloader to look for the "\\Stagem\\GraphQL" namespace in the "src" directory of this project

Available types
---------------

[](#available-types)

- DateType
- DateTimeType
- IterableType
- JsonType
- EmailType
- SimpleObjectType

### DateType

[](#datetype)

A date string, such as 2012-12-31, compliant with the full-date format outlined in section 5.6 of the [RFC 3339](https://github.com/excitement-engineer/graphql-iso-date/blob/master/rfc3339.txt) profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar.

This scalar is a description of the date, as used for birthdays for example. It cannot represent an instant on the time-line.

### DateTimeType

[](#datetimetype)

The `DateTime` scalar type represents time data, represented as an [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) encoded UTC date string.

#### Result Coercion

[](#result-coercion)

PHP `DateTime` or `DateTimeImmutable` instances are coerced to a `DateTimeInterface::ATOM` (RFC 3339) compliant date string.

#### Input Coercion

[](#input-coercion)

When expected as an input type, most of valid ISO-8601 compliant date strings are accepted.

All next formats are valid and will be successfully parsed:

- "2010-12-07T23:00:00.000Z"
- "2010-12-07T23:00:00"
- "2010-12-07T23:00:00Z"
- "2010-12-07T23:00:00+01:00"

### IterableType &amp; JsonType

[](#iterabletype--jsontype)

Any valid JSON format.

### SimpleObjectType

[](#simpleobjecttype)

Any valid PHP object which can be converted to array. Additionally support `asArray` and `toArray` methods for conversion.

Usage
-----

[](#usage)

Simply create `DateTimeType` and use it in your GraphQl Schema.

> Remember any type must be unique.

```
