Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.
/ SwagGraphQL Public archive

GraphQL API POC for early Shopware 6.0. Not maintained since then

Notifications You must be signed in to change notification settings

shopwareLabs/SwagGraphQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f37ca67 · Aug 7, 2024

History

41 Commits
Apr 12, 2019
Apr 15, 2019
Apr 11, 2019
Apr 12, 2019
Apr 11, 2019
Apr 10, 2019
Apr 12, 2019
Apr 12, 2019
Apr 11, 2019
Mar 1, 2019
Feb 1, 2019
Nov 13, 2018
Jan 29, 2019
Feb 8, 2019
Apr 10, 2019
Jan 11, 2019
Mar 1, 2019
Aug 7, 2024

Repository files navigation

Attention!

This was a POC for a GraphQL API fore a very early Shopware 6.0 state. It is unmaintained and untested for newer versions since then. Handle with care!

SwagGraphQL

A simple plugin that exposes an GraphQL-API for the Shopware Platform Core-API.

Installation

Clone this repo in your custom/plugins folder of your Shopware Platform Template.

run:

cd custom/plugins/SwagGraphQL
composer install
cd ../../..
bin/console plugin:install SwagGraphQL
bin/console plugin:activate SwagGraphQL

After installation the GraphQL endpoint is available under {baseUrl}/graphql/query.

Getting started

Getting started with GraphQL.

The easiest way to fiddle around with the Shopware GraphQL-API is to use GraphiQL, for example as a Chrome-Extension

Custom Fields

You can define your custom fields, by implementing the GraphQLField Interface and tagging your Field either with the swag_graphql.queries or swag_graphql.mutations tag. In either case you have to specify the name under which the field will be queryable inside the service tag, either as mutation or query

####Example:

in services.xml:

<service id="SwagGraphQL\Actions\GenerateUserKeyAction">
    <tag name="swag_graphql.queries" query="generate_user_key"></tag>
</service>

your class:

class GenerateUserKeyAction implements GraphQLField
{
    public function returnType(): Type
    {
        return new ObjectType([
            'name' => 'UserAccessKey',
            'fields' => [
                'accessKey' => [
                    'type' => Type::nonNull(Type::id())
                ],
                'secretAccessKey' => [
                    'type' => Type::nonNull(Type::id())
                ]
            ]
        ]);
    }

    public function defineArgs(): array
    {
        return [];
    }

    public function description(): string
    {
        return 'Generates the access keys for a user.';
    }

    public function resolve($rootValue, $args, Context $context, ResolveInfo $info)
    {
        return [
            'accessKey' => AccessKeyHelper::generateAccessKey('user'),
            'secretAccessKey' => AccessKeyHelper::generateSecretAccessKey(),
        ];
    }
}

Dependencies

It uses webonyx/graphql-php for the GraphQL part and the Shopware 6 Framework-Bundle for schema generation and query resolving.

The Tests also depend on the Shopware 6 Content-Bundle.

Known Problems

Nested connections don't really work. The connection information (total, pageInfo and aggregation) aren't returned.