{"id":33962661,"url":"https://github.com/palshin/php-object-to-graphql","last_synced_at":"2026-04-02T17:29:04.789Z","repository":{"id":56978370,"uuid":"373738252","full_name":"palshin/php-object-to-graphql","owner":"palshin","description":"Utility helper for generating GraphQL types with webonyx/graphql-php","archived":false,"fork":false,"pushed_at":"2021-06-04T13:32:59.000Z","size":42,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-14T10:39:59.395Z","etag":null,"topics":["graphql","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palshin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null},"funding":{"github":"palshin"}},"created_at":"2021-06-04T06:08:00.000Z","updated_at":"2025-11-04T05:11:51.000Z","dependencies_parsed_at":"2022-08-21T08:10:51.312Z","dependency_job_id":null,"html_url":"https://github.com/palshin/php-object-to-graphql","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/palshin/php-object-to-graphql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palshin%2Fphp-object-to-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palshin%2Fphp-object-to-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palshin%2Fphp-object-to-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palshin%2Fphp-object-to-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palshin","download_url":"https://codeload.github.com/palshin/php-object-to-graphql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palshin%2Fphp-object-to-graphql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31311584,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","php"],"created_at":"2025-12-12T22:05:55.184Z","updated_at":"2026-04-02T17:29:04.780Z","avatar_url":"https://github.com/palshin.png","language":"PHP","funding_links":["https://github.com/sponsors/palshin"],"categories":[],"sub_categories":[],"readme":"# ObjectToGraphQL\n\nI 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.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require epalshin/object-to-graphql\n```\n\n## Usage\n\n```php\n\nuse GraphQL\\Type\\Definition\\ObjectType;\nuse Palshin\\ObjectToGraphQL\\ObjectToGraphQL;\nuse Palshin\\ObjectToGraphQL\\Attributes\\GraphQLArrayType;\nuse Palshin\\ObjectToGraphQL\\Attributes\\GraphQLObjectType;\n\n#[GraphQLObjectType(typeCategory: ObjectToGraphQL::TYPE_CATEGORY_INPUT)]\nclass ProductCreateDTO\n{\n  public string $name;\n\n  public string $description;\n\n  public float $price;\n  \n  public bool $isPublic;\n\n  #[GraphQLArrayType(ObjectToGraphQL::STRING, allowsNull: false)]\n  public array $photoUrls;\n\n  public ?ProductCategoryCreateDTO $category;\n}\n\nclass ProductCategoryCreateDTO\n{\n  public string $name;\n  \n  public string $description;\n  \n  public int $sortOrder;\n}\n$objectToGraphQL = new ObjectToGraphQL();\n[ $productCreateDto, $productCategoryCreateDto ] = $objectToGraphQL-\u003egetObjectTypes(ProductCreateDTO::class);\n\n// and now you can register $objectType in your schema\n$mutationType = new ObjectType([\n  'name' =\u003e 'Mutation',\n  'fields' =\u003e [\n    'productCreate' =\u003e [\n      'type' =\u003e $product,\n      'args' =\u003e [\n        'input' =\u003e $productCreateDto,\n      ],\n      'resolve' =\u003e function($rootValue, $args) {\n        // TODO\n      }\n    ]\n  ]\n]);\n\n```\n\nThe resulting GraphQL schema will be:\n\n```graphql\ninput ProductCreateDTOInput {\n  name: String!\n  description: String!\n  price: Float!\n  isPublic: Boolean!\n  photoUrls: [String!]!\n  category: ProductCategoryCreateDTOInput\n}\ninput ProductCategoryCreateDTOInput {\n  name: String!\n  description: String!\n  sortOrder: Int!\n}\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Eugene Palshin](https://github.com/palshin)\n- [All Contributors](../../contributors)\n\n## TODO\n- [x] Add cyclic addition of types to schema\n- [x] Add processing for union types\n- [x] Add processing for type category and suffixes parameters passing through attribute\n- [x] Add strict mode for early error detection\n- [x] Add custom exceptions\n- [ ] Write more tests\n- [ ] Add possibility for adding description for generated types\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalshin%2Fphp-object-to-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalshin%2Fphp-object-to-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalshin%2Fphp-object-to-graphql/lists"}