https://github.com/thecodingmachine/graphqlite-misc-types
A collection of non-standard GraphQL types to be used with GraphQLite.
https://github.com/thecodingmachine/graphqlite-misc-types
Last synced: about 1 year ago
JSON representation
A collection of non-standard GraphQL types to be used with GraphQLite.
- Host: GitHub
- URL: https://github.com/thecodingmachine/graphqlite-misc-types
- Owner: thecodingmachine
- Created: 2019-04-26T15:13:11.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-27T10:35:28.000Z (about 4 years ago)
- Last Synced: 2025-04-11T18:59:48.054Z (about 1 year ago)
- Language: PHP
- Size: 19.5 KB
- Stars: 1
- Watchers: 8
- Forks: 5
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://packagist.org/packages/thecodingmachine/graphqlite-misc-types)
[](https://packagist.org/packages/thecodingmachine/graphqlite-misc-types)
[](https://packagist.org/packages/thecodingmachine/graphqlite-misc-types)
[](https://packagist.org/packages/thecodingmachine/graphqlite-misc-types)
[](https://scrutinizer-ci.com/g/thecodingmachine/graphqlite-misc-types/?branch=master)
[](https://travis-ci.org/thecodingmachine/graphqlite-misc-types)
[](https://coveralls.io/github/thecodingmachine/graphqlite-misc-types?branch=master)
# GraphQLite miscellaneous types
This package is an add-on to the [GraphQLite](http://graphqlite.thecodingmachine.io/) PHP library.
It contains a set of GraphQL scalar types that can be added to GraphQLite.
## Install
```console
$ composer require thecodingmachine/graphqlite-misc-types
```
## "Any" scalar type
This types adds support for a "AnyScalar" type that can be any of "string", "int", "float" or "bool".
### Usage
```php
/**
* @Query()
* @param scalar $scalar
* @return scalar
*/
public function echoScalar($scalar)
{
return $scalar;
}
```
Use the "scalar" type-hint in the DocBlock to cast a value to "AnyScalar".
### Registering AnyScalar
#### Using the SchemaFactory
If you are using the `SchemaFactory` to initialize GraphQLite, use this code to add support for `AnyScalar`:
```php
$schemaFactory->addRootTypeMapper(new \TheCodingMachine\GraphQLite\Types\AnyScalar\AnyScalarTypeMapper());
```
#### Using the Symfony bundle
If you are using the Symfony bundle to initialize GraphQLite, register the `AnyScalarTypeMapper` as a service:
```yaml
# config/services.yaml
services:
TheCodingMachine\GraphQLite\Types\AnyScalar\AnyScalarTypeMapper:
tags: ['graphql.root_type_mapper']
```