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

ActiveNeos-package[API Development](/categories/api)

wwwision/cr-graphql
===================

Simple GraphQL API for the Neos Content Repository

0.2.0(4y ago)3511MITPHP

Since Oct 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/bwaidelich/Wwwision.CR.GraphQL)[ Packagist](https://packagist.org/packages/wwwision/cr-graphql)[ RSS](/packages/wwwision-cr-graphql/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

Wwwision.CR.GraphQL
===================

[](#wwwisioncrgraphql)

Simple GraphQL Adapter for the Neos Content Repository

Description
-----------

[](#description)

This package provides a simple GraphQL API for Neos Content Repositories. It can be used in a Neos distribution or with a standalone Content Repository.

**Disclaimer:** This is merely an experiment. Feel free to use it or copy and adjust it to your needs, but please be aware of the limitations:

### Limitations

[](#limitations)

- The API just provides **read access** to nodes of the **live workspace**(this might change slightly in the future, but this won't become a fully fledged CR API!)
- The API is just a slim wrapper on top of the Content Repository PHP API. Other than the default Neos rendering, there is no caching in place yet!
- CR nodes can be nested infinitely, GraphQL queries can't (see examples below)

Installation
------------

[](#installation)

Install this package via [composer](https://getcomposer.org/):

```
composer require wwwision/cr-graphql

```

### Routes

[](#routes)

This package comes with corresponding routes, but they won't be active by default. This can be changed via some `Settings.yaml`:

```
Neos:
  Flow:
    mvc:
      routes:
        'Wwwision.CR.GraphQL':
          position: 'start'
          variables:
            path: 'graphql'
```

*Note:* The `path` variable defines the URL path, the GraphQL API will be exposed to, with the above example this will be `https://your-server.tld/graphql`.

### Adjust policies

[](#adjust-policies)

If installed in a [Neos](https://neos.io) distribution, the GraphQL controller is usually not allowed to be called by unauthenticated users. This can be changed with the following lines in a `Configuration/Policy.yaml` file:

```
privilegeTargets:

  'Neos\Flow\Security\Authorization\Privilege\Method\MethodPrivilege':

    'Some.Package:GraphQL.Endpoint':
      matcher: 'method(t3n\GraphQL\Controller\GraphQLController->queryAction(endpoint=="Wwwision_CR_GraphQL"))'

roles:

  'Neos.Flow:Everybody':
    privileges:
      -
        privilegeTarget: 'Some.Package:GraphQL.Endpoint'
        permission: GRANT
```

Usage
-----

[](#usage)

If installed correctly, you should be able to query the GraphQL endpoint. You can try it via cURL:

```
curl 'http://localhost:8081/graphql' -H 'content-type: application/json' --data-binary '{"operationName":null,"variables":{},"query":"{rootNode {identifier}}"}'

```

This should return something like

```
{"data":{"rootNode":{"identifier":"a1839a7e-8600-4ff3-ab9e-27d54fd8b3d9"}}}
```

### Node properties

[](#node-properties)

The properties of a node are represented via a `NodeProperties` scalar. In practice this means, that the properties will be converted to plain JSON in the result. This package uses the [Symfony Serializer](https://symfony.com/doc/current/components/serializer.html) to convert non-scalar properties. The common object types (DateTime, node references, assets &amp; images) are covered by custom Normalizers. You can easily configure additional types or change the behavior of the existing ones.

#### Add custom normalizers

[](#add-custom-normalizers)

This package already provides a `AssetNormalizer` that converts asset to an JSON object like:

```
{
  "title": "",
  "mediaType": "",
  "url": ""
}
```

To add a custom conversion for Video assets we could create a new Normalizer:

```
