wwwision/types-graphql

Maintainers

👁 bwaidelich

Package info

github.com/bwaidelich/types-graphql

pkg:composer/wwwision/types-graphql

Fund package maintenance!

bwaidelich

Paypal

Statistics

Installs: 14 792

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

1.4.0 2025-07-27 12:36 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 0b424d4d817649b1459e06380b603bc128ed703b

  • bwaidelich <b.waidelich.woop@wwwision.de>

This package is auto-updated.

Last update: 2026-06-27 14:48:32 UTC


README

Integration for the wwwision/types package that allows to generate GraphQL schemas from PHP code

Usage

This package can be installed via composer:

composer require wwwision/types-graphql

To generate a GraphQL schema, create a class with at least one public method with a Query attribute:

final class SomeApi {

 #[Query]
 public function ping(string $input): string
 {
 return strtoupper($input);
 }
}

Now, this API can be used to create a GraphQL schema:

// ...
$generator = new GraphQLGenerator();
$schema = $generator->generate(SomeApi::class)->render();

assert($schema === 'type Query {
 ping(input: String!): String!
}
');

Advanced types

If you API class refers to more complex types (using attributes from the wwwision/types package) in method parameters or return types, they will be added to the schema too.

Type constraints

The GraphQL schema does not have a notion of advanced type constraints. But the GraphQLGenerator can turn them into graphql-constraint directives that can be interpreted by consumers. It also adds the constraint rules to descriptions of the corresponding fields.

Custom resolvers

With version 1.2.0 custom functions can be registered that extend the behavior of types dynamically.

Note The signature of the custom resolver closure has to contain the extended type as first argument and specify the return type, for example: new CustomResolver('SomeObject', 'someCustomField', fn (SomeObject $thisIsRequired, string $thisIsOptional): bool => true)

Contribution

Contributions in the form of issues or pull requests are highly appreciated

License

See LICENSE