📣 GraphQLConf 2025 • Sept 08-10 • Amsterdam • Early bird tickets available & sponsorship opportunities open • Learn more

Code Using GraphQL

Sort by:
API Platform
API Platform is a fully-featured, flexible and extensible API framework built on top of Symfony.
README

The following class is enough to create both a Relay-compatible GraphQL server and a hypermedia API supporting modern REST formats (JSON-LD, JSONAPI…):

<?php
 
namespace AppEntity;
 
use ApiPlatformCoreAnnotationApiResource;
use DoctrineORMMapping as ORM;
 
/**
 * Greet someone!
 *
 * @ApiResource
 * @ORMEntity
 */
class Greeting
{
    /**
     * @ORMId
     * @ORMColumn(type="guid")
     */
    public $id;
 
    /**
     * @var string Your nice message
     *
     * @ORMColumn
     */
    public $hello;
}

Other API Platform features include data validation, authentication, authorization, deprecations, cache and GraphiQL integration.

Gato GraphQL
Interact with all your data in WordPress
GraPHPinator
A GraphQL implementation for modern PHP. Includes features from latest draft, middleware directives and modules with extra functionality.
README

GraPHPinator is feature complete PHP implementation of GraphQL server. Its job is transformation of query string into resolved Json result for a given Schema.

  • Aims to be compliant with the latest draft of GraphQL specification.
  • Fully typesafe, and therefore minimum required PHP version is 8.0. Sacrafices a tiny bit of convenience for huge amount of clarity and safety - no random configuration arrays, no mixed types, no variable function arguments - this library doesnt try to save you from verbosity, but makes sure you always know what you’ve got.
  • Code first.
  • Flexible. Easy to extend with extra functionality using Modules or middleware Directives.
  • Includes some opt-in extensions which are out of scope of official specs:
  • Project is composed from multiple smaller packages, which may be used standalone:
    • Tokenizer - Lexical analyzer of GraphQL document.
    • Parser - Syntactic analyzer of GraphQL document.
graphql-attribute-schema
Easily build your GraphQL schema for webonyx/graphql-php using PHP attributes instead of large configuration arrays.
README

Easily build your GraphQL schema for webonyx/graphql-php using PHP attributes instead of large configuration arrays.

A simple example:

use Jerowork\GraphqlAttributeSchema\Attribute\Enum;
use Jerowork\GraphqlAttributeSchema\Attribute\Field;
use Jerowork\GraphqlAttributeSchema\Attribute\InputType;
use Jerowork\GraphqlAttributeSchema\Attribute\Mutation;
use Jerowork\GraphqlAttributeSchema\Attribute\Query;
use Jerowork\GraphqlAttributeSchema\Attribute\Type;
 
final readonly class CreateUserMutation
{
    #[Mutation]
    public function createUser(CreateUserInputType $input): User
    {
        // Business logic to create a user
    }
}
 
final readonly class UserQuery
{
    #[Query(description: 'Get a user')]
    public function user(int $userid): User
    {
        // Fetch and return user data
    }
}
 
#[InputType]
final readonly class CreateUserInputType
{
    public function __construct(
        #[Field]
        public int $userId,
        #[Field]
        public string $name,
        #[Field(name: 'phoneNumber')]
        public ?string $phone,
    ) {}
}
 
#[Type]
final readonly class User
{
    // Define fields as class properties
    public function __construct(
        #[Field]
        public int $userId,
        #[Field]
        public string $name,
        public ?string $phone,
        #[Field(description: 'The status of the user')]
        public UserStatusType $status,
    ) {}
 
    // Define fields with methods for additional logic
    #[Field]
    public function getPhoneNumber(): string
    {
        return sprintf('+31%s', $this->phone);
    }
}
 
#[Enum(description: 'The status of the user')]
enum UserStatusType: string
{
    case Created = 'CREATED';
    case Removed = 'REMOVED';
}

This will result in the following GraphQL schema:

type Mutation {
  createUser(input: CreateUserInput!): User!
}
 
type Query {
  user(userId: Int!): User!
}
 
input CreateUserInput {
  userId: Int!
  name: String!
  phoneNumber: String
}
 
type User {
  userId: Int!
  name: String!
  status: UserStatus!
  phoneNumber: String
}
 
enum UserStatus {
  CREATED
  REMOVED
}

Available attributes: Mutation, Query, Type, InterfaceType, InputType, Enum, EnumValue, Field, Arg, Autowire, Scalar, Cursor

graphql-php
A PHP port of GraphQL reference implementation
graphql-relay-php
A library to help construct a graphql-php server supporting react-relay.
GraphQLBundle
A GraphQL server for Symfony
GraphQLite
GraphQLite is a library that offers an annotations-based syntax for GraphQL schema definition.
README

It is framework agnostic with bindings available for Symfony and Laravel. This code declares a “product” query and a “Product” Type:

class ProductController
{
    /**
     * @Query()
     */
    public function product(string $id): Product
    {
        // Some code that looks for a product and returns it.
    }
}
 
/**
 * @Type()
 */
class Product
{
    /**
     * @Field()
     */
    public function getName(): string
    {
        return $this->name;
    }
    // ...
}

Other GraphQLite features include validation, security, error handling, loading via data-loader pattern…

Lighthouse
A GraphQL server for Laravel
Railt
A PHP GraphQL Framework.
serge
Use GraphQL to define your Domain Model for CQRS/ES and let serge generate code to handle GraphQL requests.
Siler
Siler is a PHP library powered with high-level abstractions to work with GraphQL.
README

To run a Siler hello world script:

type Query {
  hello: String
}
<?php
declare(strict_types=1);
require_once '/path/to/vendor/autoload.php';
 
use SilerDiactoros;
use SilerGraphql;
use SilerHttp;
 
$typeDefs = file_get_contents(__DIR__.'/schema.graphql');
$resolvers = [
    'Query' => [
        'hello' => 'world',
    ],
];
$schema = Graphqlschema($typeDefs, $resolvers);
 
echo "Server running at http://127.0.0.1:8080";
 
Httpserver(Graphqlpsr7($schema), function (Throwable $err) {
    var_dump($err);
    return Diactorosjson([
        'error'   => true,
        'message' => $err->getMessage(),
    ]);
})()->run();

It also provides functionality for the construction of a WebSocket Subscriptions Server based on how Apollo works.

WPGraphQL
A free, open-source WordPress plugin that provides an extendable GraphQL schema and API for any WordPress site