odder / lighthouse-scalars
A collection of custom scalar types for usage with https://github.com/webonyx/graphql-php
Requires
- php: ^8.0
- ezyang/htmlpurifier: ^4.17
- nesbot/carbon: ^3.0
- p3k/emoji-detector: ^1.0
- webonyx/graphql-php: ^15
Requires (Dev)
- pestphp/pest: ^1.23
README
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:
😍😍😍:
Emoji
- see Emoji
Numbers:
PositiveFloat
- see Positive numberNegativeFloat
- see Negative numberPositiveInt
- see Positive integerNegativeInt
Localization:
CurrencyCode
- see ISO 4217 alpha-3CountryCode
- see ISO 3166-1 alpha-2Email
- see RFC 5322LanguageCode
- see ISO 639-1Locale
- Simple locale string. see Locale (en
,en-US
,en-GB
,fr
,fr-FR
,fr-CA
, etc.)
Geography:
Latitude
- Extends GeoCoordinate. see LatitudeLongitude
- Extends GeoCoordinate. see LongitudeGeoCoordinate
- see Geographic coordinate systemCountryCode
- see ISO 3166-1 alpha-2
Internet:
URL
- see URLURI
- see URIIPv4
- see IPv4IPv6
- see IPv6SemVer
- see Semantic VersioningUUID
- Using UUID4. see UUID
Markup:
JSON
- see JSONHTML
- Sanitised using HTML Purifier to prevent XSS attacks. see HTMLMarkdown
- see Markdown
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.