odder/lighthouse-scalars

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

0.1.3 2024-03-10 19:32 UTC

This package is auto-updated.

Last update: 2024-10-10 20:49:44 UTC


README

Latest Version on Packagist Tests Coverage PHP version webonyx/graphql-php Total Downloads License

This package provides a set of custom scalars for the webonyx/graphql-php library, which is used under the hood by Lighthouse, a PHP port of the popular GraphQL server.

Supported Scalars

The following scalars are supported:

😍😍😍:

Numbers:

Localization:

Geography:

Internet:

Markup:

Installation

You can install the package via composer:

composer require odder/lighthouse-scalars

Usage

Using Lighthouse

You can opt-in to the scalars you want by registering them in the TypeRegistry in a service provider. For example, you can register the PositiveFloat and Emoji scalars in the AppServiceProvider:

use Odder\LighthouseScalars\Scalars;
use Nuwave\Lighthouse\Schema\TypeRegistry;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        ...
    }

    public function register(TypeRegistry $typeRegistry)
    {
        $typeRegistry->register(Scalars::PositiveFloat);
        $typeRegistry->register(Scalars::Emoji);
    }
}

After you have registered the Scalars you need in the TypeRegistry, you can use them in your schema:

type Query {
  mood: Emoji!
  naturalNumber: PositiveFloat!
}

Testing

This package includes a set of tests for each scalar. To run the tests, use the following command:

composer test

Documentation

For more information on how to use each scalar, please refer to the documentation.

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on how to contribute to this project.

License

The MIT License (MIT). Please see License File for more information.

Credits

Security

If you discover any security-related issues, please email hi@odder.dev instead of using the issue tracker.