PHPackages                             oligus/schema - 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. oligus/schema

ActiveLibrary[API Development](/categories/api)

oligus/schema
=============

Object oriented GraphQL schema

1.0.0-beta2(6y ago)3252[2 issues](https://github.com/oligus/schema/issues)1MITPHPPHP &gt;=7.3CI failing

Since Oct 20Pushed 6y ago1 watchersCompare

[ Source](https://github.com/oligus/schema)[ Packagist](https://packagist.org/packages/oligus/schema)[ RSS](/packages/oligus-schema/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (8)Versions (9)Used By (1)

GraphQL Schema
==============

[](#graphql-schema)

GraphQL schema library.

[![Build Status](https://camo.githubusercontent.com/10f2781d69af9dec04c8e8c23e7eb758aad2f8e640542ff8f1920ce2f6f22df1/68747470733a2f2f7472617669732d63692e6f72672f6f6c696775732f736368656d612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/oligus/schema)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Codecov.io](https://camo.githubusercontent.com/a0f3e56584652424e7d0aa5b97cebad292ad001cc0ceca79a17365b535298497/68747470733a2f2f636f6465636f762e696f2f67682f6f6c696775732f736368656d612f6272616e63682f6d61737465722f6772617068732f62616467652e737667)](https://codecov.io/gh/oligus/schema)

Install
-------

[](#install)

```
$ composer require oligus/schema
```

Contents
--------

[](#contents)

[Quick start](#quick-start)
[Types](#types)
 [Type modifiers](#type-modifiers)
 [Scalar](#scalar)
 [Built in scalar types](#built-in-scalar-types)
 [Objects](#objects)
 [Interfaces](#interfaces)
 [Enums](#enums)
 [Inputs](#inputs)
[Fields](#fields)
 [Arguments](#arguments)
 [Argument values](#argument-values)
[Development](#development)

Quick start
-----------

[](#quick-start)

```
$schema = new Schema();
// Add directive
$directive = new DirectiveType('upper');
$directive->addLocation(ExecutableDirectiveLocation::FIELD());
$schema->addDirective($directive);

// Add interface
$interface = (new InterfaceType('Entity'))
    ->addField(new Field('id', new IDType(), new TypeModifier(false)))
    ->addField(new Field('name', new StringType()));
$schema->addInterface($interface);

// Add scalar
$scalar = new ScalarType('Url');
$schema->addScalar($scalar);

// Add object
$object = (new ObjectType('User'))
    ->addField(new Field('id', new IDType(), new TypeModifier(false)))
    ->addField(new Field('name', new StringType()))
    ->addField(new Field('age', new IntegerType()))
    ->addField(new Field('balance', new FloatType()))
    ->addField(new Field('isActive', new BooleanType()));

$object->addField(new Field('friends', $object, new TypeModifier(true, true, false)))
    ->addField(new Field('homepage', $scalar))
    ->implements($interface);

$schema->addObject($object);

// Add query object
$query =  (new ObjectType('Query'))
    ->addField(new Field('me', $object, new TypeModifier(true)));
$field = (new Field('friends', $object, new TypeModifier(true, true, false)))
    ->addArgument(new Argument('limit', new IntegerType(), new TypeModifier(), new ValueInteger(10)));
$query->addField($field);

$schema->addObject($query);

// Add input object
$input = (new InputType('ListUsersInput'))
    ->addField(new Field('limit', new IntegerType()))
    ->addField(new Field('since_id', new IDType()));

$schema->addInput($input);

// Add mutation object
$mutation =  new ObjectType('Mutation');
$field = (new Field('users', $object, new TypeModifier(true, true, false)))
    ->addArgument(new Argument('params', $input));
$mutation->addField($field);
$schema->addObject($mutation);

// Add union
$union = (new UnionType('MyUnion'))
    ->addObjectType(new ObjectType('Dog'))
    ->addObjectType(new ObjectType('Cat'))
    ->addObjectType(new ObjectType('Bird'));

$schema->addUnion($union);

// Set root types
$schema->setQuery($query);
$schema->setMutation($mutation);

$serializer = new SchemaSerializer();
$serializer->serialize($schema);
```

*Result:*

```
directive @upper on FIELD

interface Entity {
  id: ID!
  name: String
}

scalar Url

union MyUnion = Dog | Cat | Bird

type User implements Entity {
  id: ID!
  name: String
  age: Int
  balance: Float
  isActive: Boolean
  friends: [User]!
  homepage: Url
}

type Query {
  me: User
  friends(limit: Int = 10): [User]!
}

type Mutation {
  users(params: ListUsersInput): [User]!
}

input ListUsersInput {
  limit: Int
  since_id: ID
}

schema {
  query: Query
  mutation: Mutation
}
```

Types
-----

[](#types)

The fundamental unit of any GraphQL Schema is the type. There are six kinds of named type definitions in GraphQL, and two wrapping types.

[GrapQL Spec](https://facebook.github.io/graphql/June2018/#sec-Types)

*Available types:*

```
ScalarType

BooleanType
FloatType
IDType
IntegerType
StringType

InterfaceType
```

Type modifiers
--------------

[](#type-modifiers)

Type modifiers are used in conjunction with types, add modifier to a type to modify the type in question.

#### Definition

[](#definition)

`TypeModifier(?bool $nullable, ?bool $listable, ?bool $nullableList)`

*Modifiers*

TypeSyntaxExampleNullable Type&lt;type&gt;StringNon-null Type&lt;type&gt;!String!List Type\[&lt;type&gt;\]\[String\]List of Non-null Types\[&lt;type&gt;!\]\[String!\]Non-null List Type\[&lt;type&gt;\]!\[String\]!Non-null List of Non-null Types\[&lt;type&gt;!\]!\[String!\]!#### Examples

[](#examples)

```
$typeModifier = new TypeModifier($nullable = false, $listable = true, $nullableList = false);
$type = new BooleanType($typeModifier);
```

*Result:*

```
[bool!]!
```

Scalar
------

[](#scalar)

Scalar types represent primitive leaf values in a GraphQL type system. GraphQL responses take the form of a hierarchical tree; the leaves on these trees are GraphQL scalars.

[GrapQL Spec](https://facebook.github.io/graphql/June2018/#sec-Scalars)

#### Definition

[](#definition-1)

`Scalar(string $name, ?string $description)`

#### Examples

[](#examples-1)

```
$scalar = new ScalarType('Url', 'Url description');
```

*Result:*

```
"""
Url description
"""
scalar Url
```

### Built in scalar types

[](#built-in-scalar-types)

GraphQL provides a basic set of well‐defined Scalar types. A GraphQL server should support all of these types.

**Built in types:** *Boolean, Float, ID, Integer, String*

[GrapQL Spec](https://facebook.github.io/graphql/June2018/#sec-Scalars)

#### Definition

[](#definition-2)

`Type(?TypeModifier $modifier)`

Where &lt;**TYPE**&gt; is Boolean, Float, ID, Integer or String

#### Examples

[](#examples-2)

```
$type = new BooleanType();
```

*Result:*

```
Boolean
```

### Objects

[](#objects)

GraphQL queries are hierarchical and composed, describing a tree of information. While Scalar types describe the leaf values of these hierarchical queries, Objects describe the intermediate levels.

[GrapQL Spec](https://facebook.github.io/graphql/June2018/#sec-Objects)

#### Definition

[](#definition-3)

`ObjectType(string $name, ?string $description = null)`

#### Examples

[](#examples-3)

```
$object = new ObjectType('Wine');
$object->addField(new Field('name', new StringType()));
$object->addField(new Field('age', new IntegerType()));
$object->addField(new Field('size', new IntegerType()));
```

*Result:*

```
type Wine {
  name: String
  age: Int
  size: Int
}
```

*Implement interface*

```
$interface = new InterfaceType('Wine');
$interface->addField(new Field('name', new StringType()));
$object->implements($interface);
```

*Result:*

```
type Wine implements Name {
  name: String
  age: Int
  size: Int
}
```

### Interfaces

[](#interfaces)

GraphQL interfaces represent a list of named fields and their arguments. GraphQL objects can then implement these interfaces which requires that the object type will define all fields defined by those interfaces.

[GrapQL Spec](https://facebook.github.io/graphql/June2018/#sec-Interfaces)

#### Definition

[](#definition-4)

`InterfaceType(string $name, ?string $description = null)`

#### Examples

[](#examples-4)

```
$interface = new InterfaceType('Wine');
$interface->addField(new Field('name', new StringType()));
$interface->addField(new Field('age', new IntegerType()));
$interface->addField(new Field('size', new IntegerType()));
```

*Result:*

```
interface Wine {
  name: String
  age: Int
  size: Int
}
```

### Unions

[](#unions)

GraphQL Unions represent an object that could be one of a list of GraphQL Object types, but provides for no guaranteed fields between those types. They also differ from interfaces in that Object types declare what interfaces they implement, but are not aware of what unions contain them.

[GrapQL Spec](https://facebook.github.io/graphql/June2018/#sec-Unions)

#### Definitions

[](#definitions)

`UnionType(string $name, ?string $description = null)`

*Add object:*

`addObjectType(ObjectType $objectType): void`

#### Examples

[](#examples-5)

```
$union = new UnionType('Animals');
$union->addObjectType(new ObjectType('Dog'));
$union->addObjectType(new ObjectType('Cat'));
```

*Result:*

```
union Animals = Dog | Cat
```

Enums
-----

[](#enums)

GraphQL Enum types, like scalar types, also represent leaf values in a GraphQL type system. However Enum types describe the set of possible values.

[GrapQL Spec](https://facebook.github.io/graphql/June2018/#sec-Enums)

#### Definitions

[](#definitions-1)

`EnumType(string $name, ?string $description = null, array $enums = [])`

*Add enum:*

`add(string $enum)`

#### Examples

[](#examples-6)

```
$enum = new EnumType('Direction', 'Different directions', ['SOUTH', 'NORTH']);
$enum->addEnum('EAST');
$enum->addEnum('WEST');
```

*Result:*

```
"""
Different directions
"""
enum Direction {
  SOUTH
  NORTH
  EAST
  WEST
}
```

Directives
----------

[](#directives)

A GraphQL schema describes directives which are used to annotate various parts of a GraphQL document as an indicator that they should be evaluated differently by a validator, executor, or client tool such as a code generator.

[GrapQL Spec](https://spec.graphql.org/June2018/#sec-Type-System.Directives)

#### Definitions

[](#definitions-2)

`EnumType(string $name, ?string $description = null, array $enums = [])`

*Add locations:*

`add(ExecutableDirectiveLocation $location)`

#### Examples

[](#examples-7)

```
$directive = new DirectiveType('example', 'Example directive');
$directive->addLocation(ExecutableDirectiveLocation::FIELD());
$directive->addLocation(ExecutableDirectiveLocation::INLINE_FRAGMENT());
```

*Result:*

```
"""
Example directive
"""
directive @example on FIELD | FRAGMENT_SPREAD
```

Inputs
------

[](#inputs)

Fields may accept arguments to configure their behavior. These inputs are often scalars or enums, but they sometimes need to represent more complex values.

[GrapQL Spec](https://facebook.github.io/graphql/June2018/#sec-Input-Objects)

#### Definition

[](#definition-5)

`InputType(string $name, ?string $description = null)`

*Add field:*

`addField(Field $field): void`

#### Examples

[](#examples-8)

```
$object = new InputType('Animal');
$object->addField(new Field('name', new StringType()));
$object->addField(new Field('age', new IntegerType()));
$object->addField(new Field('weight', new IntegerType()));
```

*Result:*

```
input Animal {
  name: String
  age: Int
  weight: Int
}
```

Fields
------

[](#fields)

A selection set is primarily composed of fields. A field describes one discrete piece of information available to request within a selection set.

[GrapQL Spec](https://facebook.github.io/graphql/June2018/#sec-Language.Fields)

#### Definition

[](#definition-6)

`Field(string $name, Type $type, ?TypeModifier $typeModifier, ?string $description)`

#### Examples

[](#examples-9)

```
$field = new Field('simpleField', new IntegerType());
```

*Result:*

```
simpleField: Int
```

*With type modifier:*

```
$field = new Field('simpleField', new IntegerType(), new TypeModifier($nullable = false));
```

*Result:*

```
simpleField: Int!
```

*With type argument:*

```
$field = new Field('booleanListArgField', new BooleanType(), new TypeModifier(true, true));

$argument = new Argument('booleanListArg', new BooleanType(), new TypeModifier(true, true, false));
$field->addArgument($argument);
```

Arguments
---------

[](#arguments)

Fields are conceptually functions which return values, and occasionally accept arguments which alter their behavior. These arguments often map directly to function arguments within a GraphQL server’s implementation.

[GrapQL Spec](https://facebook.github.io/graphql/June2018/#sec-Language.Arguments)

#### Definition

[](#definition-7)

`Argument(string $name, Type $type, ?TypeModifier $typeModifier, ?Value $defaultVale)`

#### Examples

[](#examples-10)

```
$argument = new Argument('booleanArg', new BooleanType());
```

*Result:*

```
booleanArg: Boolean
```

*With type modifier:*

```
$argument = new Argument('intArg', new IntegerType(), new TypeModifier(false));
// intArg: Int! = 0
```

*With type default value:*

```
$argument = new Argument('intArg', new IntegerType(), null, new ValueInteger(0));
// intArg: Int = 0
```

### Argument values

[](#argument-values)

Set simple scalar values for default values in arguments.

#### Definition

[](#definition-8)

`Value(mixed $value)`

*Available values:*`ValueBoolean, ValueFloat, ValueInteger, ValueNull, ValueString`

#### Examples

[](#examples-11)

```
$bool = new ValueBoolean(true);
$bool->getValue(); // true
echo $bool; // 'true'
```

Development
-----------

[](#development)

Download and build docker container

```
$ make
```

Access docker image

```
$  make bash
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance7

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.2% 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

Every ~480 days

Total

2

Last Release

2273d ago

PHP version history (2 changes)1.0.0-beta1PHP &gt;=7.2

1.0.0-beta2PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/8739794f901a8c9568dc308bb8af786d8e5a94feea41877e04d8ec918930b021?d=identicon)[oligus](/maintainers/oligus)

---

Top Contributors

[![oligus](https://avatars.githubusercontent.com/u/2466591?v=4)](https://github.com/oligus "oligus (71 commits)")[![NicklasWallgren](https://avatars.githubusercontent.com/u/1784879?v=4)](https://github.com/NicklasWallgren "NicklasWallgren (3 commits)")[![cinamo](https://avatars.githubusercontent.com/u/7139230?v=4)](https://github.com/cinamo "cinamo (2 commits)")[![baboons](https://avatars.githubusercontent.com/u/3737821?v=4)](https://github.com/baboons "baboons (1 commits)")

---

Tags

graphqlgraphql-schema

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/oligus-schema/health.svg)

```
[![Health](https://phpackages.com/badges/oligus-schema/health.svg)](https://phpackages.com/packages/oligus-schema)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[netflie/whatsapp-cloud-api

The first PHP SDK to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

640431.7k4](/packages/netflie-whatsapp-cloud-api)[chartmogul/chartmogul-php

ChartMogul API PHP Client

181.4M](/packages/chartmogul-chartmogul-php)[php-twinfield/twinfield

Library for using the Twinfield Soap Service.

33769.2k1](/packages/php-twinfield-twinfield)[paddlehq/paddle-php-sdk

Paddle's PHP SDK for Paddle Billing.

53301.7k](/packages/paddlehq-paddle-php-sdk)[flowpack/elasticsearch

This package provides wrapper functionality for the Elasticsearch engine.

34485.9k4](/packages/flowpack-elasticsearch)

PHPackages © 2026

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