项目作者: thecodingmachine

项目描述 :
Use PHP Annotations to declare your GraphQL API
高级语言: PHP
项目地址: git://github.com/thecodingmachine/graphqlite.git
创建时间: 2019-01-29T13:09:22Z
项目社区:https://github.com/thecodingmachine/graphqlite

开源协议:

下载



GraphQLite logo


GraphQLite


GraphQL in PHP made easy.


Documentation · Contributing



Latest Stable Version


Total Downloads


License


Continuous Integration


Code Coverage


A GraphQL library for PHP that allows you to use attributes (or annotations) to define your schema and write your queries and mutations using simple-to-write controllers.

Features

  • Create a complete GraphQL API by simply annotating your PHP classes
  • Framework agnostic, but with Symfony and Laravel integrations available!
  • Comes with batteries included :battery:: queries, mutations, subscriptions, mapping of arrays/iterators, file uploads, extendable types and more!

Basic example

First, declare a mutation in your controller:

  1. class ProductController
  2. {
  3. #[Mutation]
  4. public function updateProduct(Product $product): Product
  5. {
  6. // Some code that gets and updates a Product
  7. return $product;
  8. }
  9. }

Then, annotate the Product class to declare what fields are exposed to the GraphQL API:

  1. #[Type]
  2. #[Input(update: true)]
  3. class Product
  4. {
  5. #[Field]
  6. public function getName(): string
  7. {
  8. return $this->name;
  9. }
  10. #[Field]
  11. public function setName(string $name): void
  12. {
  13. $this->name = $name;
  14. }
  15. // ...
  16. }

That’s it, you’re good to go :tada: mutate away!

  1. {
  2. updateProduct(product: {
  3. name: 'John Doe'
  4. }) {
  5. name
  6. }
  7. }

Want to learn more? Head to the documentation!

Contributing

Contributions are welcomed via pull requests. If you’d like to discuss prior to submitting a PR, consider a discussion. If it’s a bug/issue, you can submit an issue first.

All PRs should have sufficient test coverage for any additions or changes. PRs will not be merged without these.