Skip to content

Provides an extensible GraphQL schema and API for your WSC page.

License

Notifications You must be signed in to change notification settings

tkirchDev/dev.tkirch.wsc.graphql

Repository files navigation

dev.tkirch.wsc.graphql

GitHub PHPCS check

Provides an extensible GraphQL schema and API for your WSC page.

Table of contents

Installation

Download the latest release of this version here and install the package normally via the WSC.

Build extension yourself

Windows

Clone the project and execute the make.bat file. Then the package is packed so that it is ready to install.

Documentation

Send request

The default server is available at http://domain.tld/graphql/. For general information, take a look at GraphQL.

With the following mutation you can generate a long-lived token (you create the access data for this in the acp).

mutation {
    generateToken(key: "exampleKey", secret: "exampleSecret", type:"longlife") {
        value
    }
}

The output looks then e.g. like this:

{
    "data": {
        "generateToken": {
            "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbklEIjo2LCJleHAiOjE5MjYwMDc3NjZ9.02NE6IxapsB1NY3Qf4NzC9j_baJ--Cdfc0wVH42409E"
        }
    }
}

To authenticate themselves to a request, they set the Authorization Header (Do not forget the Bearer in front of the token.). Here is an example:

{
    "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbklEIjo2LCJleHAiOjE5MjYwMDc3NjZ9.02NE6IxapsB1NY3Qf4NzC9j_baJ--Cdfc0wVH42409E"
}

Extend a resolver

In the following example we extend the QueryResover with the field foo which returns bar.

Extend the eventListener.xml by:

<eventlistener name="fooBarListener">
    <eventclassname>graphql\system\resolver\QueryResolver</eventclassname>
    <eventname>afterSetFieldResolvers</eventname>
    <listenerclassname>graphql\system\event\listener\FooBarListener</listenerclassname>
    <inherit>1</inherit>
</eventlistener>

Create the file graphql\system\event\listener\FooBarListener.class.php with the content:

<?php
namespace graphql\system\event\listener;

use wcf\system\event\listener\IParameterizedEventListener;

class FooBarListener implements IParameterizedEventListener
{

    public function execute($eventObj, $className, $eventName, array &$parameters)
    {
        if ($eventName == 'afterSetFieldResolvers') {
            $eventObj->appendFieldResolvers([
                'foo' => function () {
                    return 'bar';
                },
            ]);
        }
    }
}

About

Provides an extensible GraphQL schema and API for your WSC page.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published