PHPackages                             epalshin/object-to-graphql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. epalshin/object-to-graphql

ActiveLibrary[API Development](/categories/api)

epalshin/object-to-graphql
==========================

Utility helper for generating GraphQL types with webonyx/graphql-php

1.0.0(4y ago)103MITPHPPHP ^8.0

Since Jun 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/palshin/php-object-to-graphql)[ Packagist](https://packagist.org/packages/epalshin/object-to-graphql)[ Docs](https://github.com/palshin/object_to_graphql)[ GitHub Sponsors](https://github.com/palshin)[ RSS](/packages/epalshin-object-to-graphql/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

ObjectToGraphQL
===============

[](#objecttographql)

I noticed that in my own code (I use [Lighthouse PHP](https://github.com/nuwave/lighthouse) for implementation GraphQL API) quite often I first describe the input type in the schema, then I describe the object for this type (DTO). It creates a sense of repetition and makes type system maintenance more difficult, so I decided to add the ability to programmatically generate types for the schema by its type declaration in code. So in my project I expanded [this recommendation](https://lighthouse-php.com/5/digging-deeper/adding-types-programmatically.html#native-php-types) for third case: DTO for custom resolvers.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require epalshin/object-to-graphql
```

Usage
-----

[](#usage)

```
use GraphQL\Type\Definition\ObjectType;
use Palshin\ObjectToGraphQL\ObjectToGraphQL;
use Palshin\ObjectToGraphQL\Attributes\GraphQLArrayType;
use Palshin\ObjectToGraphQL\Attributes\GraphQLObjectType;

#[GraphQLObjectType(typeCategory: ObjectToGraphQL::TYPE_CATEGORY_INPUT)]
class ProductCreateDTO
{
  public string $name;

  public string $description;

  public float $price;

  public bool $isPublic;

  #[GraphQLArrayType(ObjectToGraphQL::STRING, allowsNull: false)]
  public array $photoUrls;

  public ?ProductCategoryCreateDTO $category;
}

class ProductCategoryCreateDTO
{
  public string $name;

  public string $description;

  public int $sortOrder;
}
$objectToGraphQL = new ObjectToGraphQL();
[ $productCreateDto, $productCategoryCreateDto ] = $objectToGraphQL->getObjectTypes(ProductCreateDTO::class);

// and now you can register $objectType in your schema
$mutationType = new ObjectType([
  'name' => 'Mutation',
  'fields' => [
    'productCreate' => [
      'type' => $product,
      'args' => [
        'input' => $productCreateDto,
      ],
      'resolve' => function($rootValue, $args) {
        // TODO
      }
    ]
  ]
]);
```

The resulting GraphQL schema will be:

```
input ProductCreateDTOInput {
  name: String!
  description: String!
  price: Float!
  isPublic: Boolean!
  photoUrls: [String!]!
  category: ProductCategoryCreateDTOInput
}
input ProductCategoryCreateDTOInput {
  name: String!
  description: String!
  sortOrder: Int!
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Eugene Palshin](https://github.com/palshin)
- [All Contributors](../../contributors)

TODO
----

[](#todo)

- Add cyclic addition of types to schema
- Add processing for union types
- Add processing for type category and suffixes parameters passing through attribute
- Add strict mode for early error detection
- Add custom exceptions
- Write more tests
- Add possibility for adding description for generated types

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1808d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b8a21b17dfa739c39cf7c54dcae47926976e715ab70fa9ed41255780a3934385?d=identicon)[palshin](/maintainers/palshin)

---

Top Contributors

[![palshin](https://avatars.githubusercontent.com/u/28474694?v=4)](https://github.com/palshin "palshin (22 commits)")

---

Tags

graphqlphppalshinobject\_to\_graphql

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/epalshin-object-to-graphql/health.svg)

```
[![Health](https://phpackages.com/badges/epalshin-object-to-graphql/health.svg)](https://phpackages.com/packages/epalshin-object-to-graphql)
```

###  Alternatives

[nuwave/lighthouse

A framework for serving GraphQL from Laravel

3.5k10.7M93](/packages/nuwave-lighthouse)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5723.1M30](/packages/thecodingmachine-graphqlite)[wp-graphql/wp-graphql

GraphQL API for WordPress

3.8k391.7k19](/packages/wp-graphql-wp-graphql)[overblog/graphql-bundle

This bundle provides tools to build a GraphQL server in your Symfony App.

8027.9M28](/packages/overblog-graphql-bundle)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[aimeos/ai-admin-graphql

Aimeos Admin GraphQL API extension

944100.0k4](/packages/aimeos-ai-admin-graphql)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
