PHPackages                             t3n/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. t3n/graphql

Abandoned → [oniva/graphql](/?search=oniva%2Fgraphql)ArchivedNeos-package[API Development](/categories/api)

t3n/graphql
===========

Neos Flow adapter for graphql

3.1.1(1y ago)16121.7k↑29%8[3 issues](https://github.com/t3n/graphql/issues)[1 PRs](https://github.com/t3n/graphql/pulls)3PHPPHP &gt;=7.2

Since Feb 14Pushed 8mo ago9 watchersCompare

[ Source](https://github.com/t3n/graphql)[ Packagist](https://packagist.org/packages/t3n/graphql)[ RSS](/packages/t3n-graphql/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (22)Used By (3)

Warning

**This plugin is no longer being maintained. As replacement we suggest **

t3n.GraphQL
===========

[](#t3ngraphql)

Flow Package to add graphql APIs to [Neos and Flow](https://neos.io) that also supports advanced features like schema stitching, validation rules, schema directives and more. This package doesn't provide a GraphQL client to test your API. We suggest to use the [GraphlQL Playground](https://github.com/prisma/graphql-playground)

Simply install the package via composer:

```
composer require "t3n/graphql"
```

Version 2.x supports neos/flow &gt;= 6.0.0

Configuration
-------------

[](#configuration)

In order to use your GraphQL API endpoint some configuration is necessary.

### Endpoints

[](#endpoints)

Let's assume that the API should be accessible under the URL .

To make this possible, you first have to add the route to your `Routes.yaml`:

```
- name: 'GraphQL API'
  uriPattern: 'api/'
  subRoutes:
    'GraphQLSubroutes':
      package: 't3n.GraphQL'
      variables:
        'endpoint': 'my-endpoint'
```

Don't forget to load your routes at all:

```
Neos:
  Flow:
    mvc:
      routes:
        'Your.Package':
          position: 'start'
```

Now the route is activated and available.

### Schema

[](#schema)

The next step is to define a schema that can be queried.

Create a `schema.graphql` file:

/Your.Package/Resources/Private/GraphQL/schema.root.graphql

```
type Query {
  ping: String!
}

type Mutation {
  pong: String!
}

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

Under the hood we use [t3n/graphql-tools](https://github.com/t3n/graphql-tools). This package is a php port from [Apollos graphql-tools](https://github.com/apollographql/graphql-tools/). This enables you to use some advanced features like schema stitching. So it's possible to configure multiple schemas per endpoint. All schemas will be merged internally together to a single schema.

Add a schema to your endpoint like this:

```
t3n:
  GraphQL:
    endpoints:
      'my-endpoint': # use your endpoint variable here
        schemas:
          root: # use any key you like here
            typeDefs: 'resource://Your.Package/Private/GraphQL/schema.root.graphql'
```

To add another schema just add a new entry below the `schemas` index for your endpoint.

You can also use the extend feature:

/Your.Package/Resources/Private/GraphQL/schema.yeah.graphql

```
extend type Query {
  yippie: String!
}
```

```
t3n:
  GraphQL:
    endpoints:
      'my-endpoint': #
        schemas:
          yeah:
            typeDefs: 'resource://Your.Package/Private/GraphQL/schema.yeah.graphql'
```

### Resolver

[](#resolver)

Now you need to add some Resolver. You can add a Resolver for each of your types. Given this schema:

```
type Query {
  product(id: ID!): Product
  products: [Product]
}

type Product {
  id: ID!
  name: String!
  price: Float!
}
```

You might want to configure Resolver for both types:

```
t3n:
  GraphQL:
    endpoints:
      'my-endpoint':
        schemas:
          mySchema:
            resolvers:
              Query: 'Your\Package\GraphQL\Resolver\QueryResolver'
              Product: 'Your\Package\GraphQL\Resolver\ProductResolver'
```

Each resolver must implement `t3n\GraphQL\ResolverInterface` !

You can also add resolvers dynamically so you don't have to configure each resolver separately:

```
t3n:
  GraphQL:
    endpoints:
      'my-endpoint':
        schemas:
          mySchema:
            resolverPathPattern: 'Your\Package\GraphQL\Resolver\Type\{Type}Resolver'
            resolvers:
              Query: 'Your\Package\GraphQL\Resolver\QueryResolver'
```

With this configuration the class `Your\Package\GraphQL\Resolver\Type\ProductResolver` would be responsible for queries on a Product type. The {Type} will evaluate to your type name.

As a third option you can create resolvers programmatically. Therefore you can register a class that implements the `t3n\GraphQL\ResolverGeneratorInterface`. This might be useful to auto generate a resolver mapping:

```
t3n:
  GraphQL:
    endpoints:
      'my-endpoint':
        schemas:
          mySchema:
            resolverGenerator: 'Your\Package\GraphQL\Resolver\ResolverGenerator'
```

The Generator must return an array with this structure: \['typeName' =&gt; \\Resolver\\Class\\Name\]

☝️ Note: Your Resolver can override each other. All resolver configurations are applied in this order:

- ResolverGenerator
- dynamic "{Type}Resolver"
- specific Resolver

#### Resolver Implementation

[](#resolver-implementation)

A implementation for our example could look like this (pseudocode):

```
