Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Colja Laravel Package

d3mo17/colja

View on GitHub
Deep Wiki
Context7

Colja

A Symfony bundle to provide GraphQL functionality (by the use of Siler). Per default GraphQL requests (method POST) will be handled on request-uri /graphql.


 

Schema

There has to be defined one basic schema file in GraphQL Schema Definition Language (SDL). The path to this file has to be configured in the d_mo_colja.yaml-file (see here).

The basic schema file can be extended by multiple more files (see here).

To link a query or mutation (field) from the schema to a resolver callable in php you have to configure a classname and a method with the specified fieldname


 

Resolvers

A class which contains field resolvers, must extend the Class DMo\Colja\GraphQL\AbstractResolver. This is because the ResolverManager will be injected into each Resolver, so through this you will be able to get the symfony controller and container.

All Resolvers (callable functions) can be defined to expect four parameters:

  • $root
  • $args
  • $context
  • $info

The most important parameter is the second one: $args. It contains all arguments passed to a field.

Each Resolver can return a scalar value or an associative array. The array values can contain scalars or function references which act as field resolvers by themselves.

All field values which need to be "lazy-loaded" must be defined as resolver, because a resolver will only be called if the corresponding field was requested in a query. You can also realize recursive data structures with this technique (see example here).


 

GET-Requests

By default this bundle only supports the request method POST. But you can easily add support for the method GET. Just place the following in the routes.yaml of your symfony project:

d_mo_colja_endpoint_get:
    path:       /graphql
    controller: DMo\Colja\Controller\GraphQLController::endpoint
    methods:    GET


 

Setup Example

See also Colja examples for more information

a-symfony-project/
├─ bin/
├─ config/
│  ├─ graphql/
│  │  ├─ base.schema
│  ├─ packages/
│  │  ├─ .../
│  │  ├─ d_mo_colja.yaml
│  │  ├─ ...
|  ├─ bundles.php
│  ├─ .../
├─ src/
│  ├─ Controller/
│  ├─ .../
│  ├─ GraphQL/
│  │  ├─ DemoResolver.php
│  │  ├─ ...
├─ ...
├─ composer.json

base.schema

type Query {
    demo: String,
    demoArgs(name: String!, num: Int): String
}

d_mo_colja.yaml

d_mo_colja:
  schema: config/graphql/base.schema
  query:
    demo:
      class: App\GraphQL\DemoResolver
      method: demo
    demoArgs:
      class: App\GraphQL\DemoResolver
      method: demoWithArguments

bundles.php

<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    // ...
    DMo\Colja\DMoColjaBundle::class => ['all' => true],
];

DemoResolver.php

<?php

namespace App\GraphQL;

use DMo\Colja\GraphQL\AbstractResolver;

class DemoResolver extends AbstractResolver
{
    public function demo(array $root = null, array $args): string
    {
        return "Hello World!";
    }

    public function demoWithArguments(array $root = null, array $args): string
    {
        $num = array_key_exists('num', $args) ? $args['num'] : 17;
        return "Hello ${args['name']}. The magic number is $num!";
    }
}


 

License

The MIT License (MIT)

Copyright (c) 2021 Daniel Moritz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor