mathsgod/graphqlite-mixed-type

mixed type for graphqlite

Maintainers

Package info

github.com/mathsgod/graphqlite-mixed-type

pkg:composer/mathsgod/graphqlite-mixed-type

Statistics

Installs: 9 300

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

2.3.1 2026-05-26 07:15 UTC

This package is auto-updated.

Last update: 2026-05-26 07:17:54 UTC


README

PHP Composer

graphqlite-mixed-type

mixed input and output type support for thecodingmachine/graphqlite.

GraphQL does not natively support a mixed scalar type. This package adds a custom mixed scalar that can accept and return any value — objects, arrays, strings, numbers, or booleans — without requiring a predefined schema type.

Requirements

  • PHP 8.1+
  • thecodingmachine/graphqlite ^8.1

Installation

composer require mathsgod/graphqlite-mixed-type

Setup

Register the mapper factory when building your schema:

use GQL\Type\MixedTypeMapperFactory;

$factory = new SchemaFactory($cache, $container);
// ...
$factory->addRootTypeMapperFactory(new MixedTypeMapperFactory());

Usage

Output type

Use outputType: "mixed" on a #[Query] or #[Mutation] to return any value:

use TheCodingMachine\GraphQLite\Annotations\Query;

class Controllers
{
    /**
     * @param mixed $a
     */
    #[Query(outputType: "mixed")]
    public function mixedInput($a): mixed
    {
        return $a;
    }
}

Input type

Annotate a parameter with @param mixed to accept any input value:

/**
 * @param mixed $data
 */
#[Query(outputType: "mixed")]
public function echo(mixed $data): mixed
{
    return $data;
}

Example query

query {
    mixedInput(a: {hello: "world"})
}

Response:

{
  "data": {
    "mixedInput": {
      "hello": "world"
    }
  }
}

How it works

Class Role
MixedType Custom GraphQL scalar that passes any value through as-is
MixedTypeMapper Maps PHP mixed type to/from MixedType for inputs and outputs
MixedTypeMapperFactory Factory registered with SchemaFactory to plug in the mapper

Testing

composer install
vendor/bin/phpunit