freshcells / graphqlite-misc-types
A collection of non-standard GraphQL types to be used with GraphQLite.
Installs: 5 053
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- php: >=7.4
- thecodingmachine/graphqlite: ^5 || ^6
- webonyx/graphql-php: ^14.9
Requires (Dev)
- phpstan/phpstan: ^1.8.2
- phpunit/phpunit: ^9.0.0
- symfony/cache: ^4
Suggests
- ext-json: Needed for JSON type
This package is auto-updated.
Last update: 2024-10-08 19:34:06 UTC
README
This package is an add-on to the GraphQLite PHP library. It contains a set of GraphQL scalar types that can be added to GraphQLite.
This is a takeover drop-in fork of https://github.com/thecodingmachine/graphqlite-misc-types which seems to be abandoned.
We left the namespace as TheCodingMachine
to assure drop-in replacement.
Install
$ composer require freshcells/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
/** * @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
:
$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:
# config/services.yaml services: TheCodingMachine\GraphQLite\Types\AnyScalar\AnyScalarTypeMapper: tags: ['graphql.root_type_mapper']
"JSON" type
This type adds support for a "JSON" type that can be used to represent JSON data.
Using the Symfony bundle
If you are using the Symfony bundle to initialize GraphQLite, register the JSONScalarTypeMapperFactory
as a service:
# config/services.yaml services: TheCodingMachine\GraphQLite\Types\JSONScalar\JSONScalarTypeMapperFactory: tags: ['graphql.root_type_mapper_factory']