PHPackages                             mll-lab/graphql-php-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. mll-lab/graphql-php-scalars

ActiveLibrary[API Development](/categories/api)

mll-lab/graphql-php-scalars
===========================

A collection of custom scalar types for usage with https://github.com/webonyx/graphql-php

v6.4.1(10mo ago)1394.2M—0.2%1420MITPHPPHP ^8CI passing

Since Sep 28Pushed 2mo ago2 watchersCompare

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

READMEChangelog (10)Dependencies (14)Versions (30)Used By (20)

graphql-php-scalars
===================

[](#graphql-php-scalars)

A collection of custom scalar types for usage with

[![Validate](https://github.com/mll-lab/graphql-php-scalars/workflows/Validate/badge.svg)](https://github.com/mll-lab/graphql-php-scalars/actions)[![codecov](https://camo.githubusercontent.com/a8c041e82cb1652048acf53e10f03804a6c7449acf7b43ab6627fdc52d6cb121/68747470733a2f2f636f6465636f762e696f2f67682f6d6c6c2d6c61622f6772617068716c2d7068702d7363616c6172732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/mll-lab/graphql-php-scalars)

[![GitHub license](https://camo.githubusercontent.com/d41dcb80a8a3c3d09b72fd913f8926d979c9e18774d566403f1c3ba19f2a0371/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6c6c2d6c61622f6772617068716c2d7068702d7363616c6172732e737667)](https://github.com/mll-lab/graphql-php-scalars/blob/master/LICENSE)[![Packagist](https://camo.githubusercontent.com/4853a4b08aeb661467ac0594b91128c226be77c1ac038c7949085de81f80db61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6c6c2d6c61622f6772617068716c2d7068702d7363616c6172732e737667)](https://packagist.org/packages/mll-lab/graphql-php-scalars)[![Packagist](https://camo.githubusercontent.com/84b2c7bcaeaf7c23d7dabccab3226816ca5f9d8f46f3b9fcc76c58defd2636cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6c6c2d6c61622f6772617068716c2d7068702d7363616c6172732e737667)](https://packagist.org/packages/mll-lab/graphql-php-scalars)

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

[](#installation)

```
composer require mll-lab/graphql-php-scalars
```

Usage
-----

[](#usage)

You can use the provided Scalars just like any other type in your schema definition. Check [SchemaUsageTest](tests/SchemaUsageTest.php) for an example.

### [BigInt](src/BigInt.php)

[](#bigint)

An arbitrarily long sequence of digits that represents a big integer.

### [Date](src/Date.php)

[](#date)

A date string with format `Y-m-d`, e.g. `2011-05-23`.

The following conversion applies to all date scalars:

- Outgoing values can either be valid date strings or `\DateTimeInterface` instances.
- Incoming values must always be valid date strings and will be converted to `\DateTimeImmutable` instances.

### [DateTime](src/DateTime.php)

[](#datetime)

A datetime string with format `Y-m-d H:i:s`, e.g. `2018-05-23 13:43:32`.

### [DateTimeTz](src/DateTimeTz.php)

[](#datetimetz)

A datetime string with format `Y-m-d\TH:i:s.uP`, e.g. `2020-04-20T16:20:04+04:00`, `2020-04-20T16:20:04Z`.

### [Email](src/Email.php)

[](#email)

A [RFC 5321](https://tools.ietf.org/html/rfc5321) compliant email.

### [IntRange](src/IntRange.php)

[](#intrange)

Allows defining numeric scalars where the values must lie between a defined minimum and maximum.

```
use MLL\GraphQLScalars\IntRange;

final class UpToADozen extends IntRange
{
    protected static function min(): int
    {
        return 1;
    }

    protected static function max(): int
    {
        return 12;
    }
}
```

### [JSON](src/JSON.php)

[](#json)

Arbitrary data encoded in JavaScript Object Notation. See .

This expects a string in JSON format, not an arbitrary JSON value or GraphQL literal.

```
type Query {
  foo(bar: JSON!): JSON!
}

# Wrong, the given value is a GraphQL literal object
{
  foo(bar: { baz: 2 })
}

# Correct, the given value is a JSON string representing an object
{
  foo(bar: "{ \"bar\": 2 }")
}
```

```
// Wrong, the variable value is a JSON object
{
  "query": "query ($bar: JSON!) { foo(bar: $bar) }",
  "variables": {
    "bar": {
      "baz": 2
    }
  }
}

// Correct, the variable value is a JSON string representing an object
{
  "query": "query ($bar: JSON!) { foo(bar: $bar) }",
  "variables": {
    "bar": "{ \"bar\": 2 }"
  }
}
```

JSON responses will contain nested JSON strings.

```
{
  "data": {
    "foo": "{ \"bar\": 2 }"
  }
}
```

### [Mixed](src/MixedScalar.php)

[](#mixed)

Loose type that allows any value. Be careful when passing in large `Int` or `Float` literals, as they may not be parsed correctly on the server side. Use `String` literals if you are dealing with really large numbers to be on the safe side.

### [Null](src/NullScalar.php)

[](#null)

Always `null`. Strictly validates value is non-null, no coercion.

### [Regex](src/Regex.php)

[](#regex)

The `Regex` class allows you to define a custom scalar that validates that the given value matches a regular expression.

The quickest way to define a custom scalar is the `make` factory method. Just provide a name and a regular expression, you will receive a ready-to-use custom regex scalar.

```
use MLL\GraphQLScalars\Regex;

$hexValue = Regex::make(
    'HexValue',
    'A hexadecimal color is specified with: `#RRGGBB`, where `RR` (red), `GG` (green) and `BB` (blue) are hexadecimal integers between `00` and `FF` specifying the intensity of the color.',
    '/^#?([a-f0-9]{6}|[a-f0-9]{3})$/'
);
```

You may also define your regex scalar as a class.

```
use MLL\GraphQLScalars\Regex;

// The name is implicitly set through the class name here
class HexValue extends Regex
{
    /** The description that is used for schema introspection. */
    public ?string $description = /** @lang Markdown */ in_array($name, [
       'Vladar',
       'Benedikt',
       'Christopher',
    ]),
);
```

Or you may simply extend the class, check out the implementation of the [Email](src/Email.php) scalar to see how.

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance72

Regular maintenance activity

Popularity59

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 96.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~88 days

Recently: every ~214 days

Total

29

Last Release

322d ago

Major Versions

v1.0.2 → v2.0.02018-12-21

v2.1.0 → v3.0.02020-02-20

v3.1.0 → v4.0.02020-12-13

v4.1.1 → v5.0.02021-12-03

v5.4.1 → v6.0.02023-01-20

PHP version history (6 changes)v0.1.0PHP &gt;=7.0

v2.0.0PHP &gt;=7.1

v3.0.0PHP &gt;=7.2

v4.0.0PHP ^7.2 || ^8.0

v5.0.0PHP ^7.4 || ^8

v6.0.0PHP ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ff5d1af2c0f601f7ed7e75e15be0aa4c062149b57fd5aace4e44cc37b8b7a40?d=identicon)[spawnia](/maintainers/spawnia)

---

Top Contributors

[![spawnia](https://avatars.githubusercontent.com/u/12158000?v=4)](https://github.com/spawnia "spawnia (122 commits)")[![simPod](https://avatars.githubusercontent.com/u/327717?v=4)](https://github.com/simPod "simPod (2 commits)")[![bepsvpt](https://avatars.githubusercontent.com/u/8221099?v=4)](https://github.com/bepsvpt "bepsvpt (1 commits)")[![danon](https://avatars.githubusercontent.com/u/13367735?v=4)](https://github.com/danon "danon (1 commits)")

---

Tags

phpgraphql

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mll-lab-graphql-php-scalars/health.svg)

```
[![Health](https://phpackages.com/badges/mll-lab-graphql-php-scalars/health.svg)](https://phpackages.com/packages/mll-lab-graphql-php-scalars)
```

###  Alternatives

[rubix/server

Deploy your Rubix ML models to production with scalable stand-alone inference servers.

632.3k](/packages/rubix-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
