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

Siler Laravel Package

leocavalcante/siler

Siler is a zero-dependency PHP library/micro-framework of high-level functional abstractions for declarative apps and routing. Fast, flat-file friendly, and works well with Swoole. Note: the repository is archived; Nano is recommended as an alternative.

View on GitHub
Deep Wiki
Context7

description: >- On the previous guide you saw how to map resolvers (callables) from a existing SDL (.graphql or .gql). Annotations enables the other way around, it provides a GraphQL SDL from annotated PHP code.

@Annotations

Thank you Doctrine

Siler's GraphQL Annotations uses the super-powers from Doctrine's Annotations and like any other dependency, is a peer that we should explicitly require:

$ composer require doctrine/annotations

What is available:

There are 9 annotations fulfilling the GraphQL's ecosystem:

Class annotations are:

  • ObjectType
  • InterfaceType
  • InputType
  • EnumType
  • UnionType
  • Directive

Complementary method and property annotations are:

  • Field
  • Args
  • EnumVal

They follow a ubiquitous language to GraphQL spec, so if you know GraphQL, there is nothing new here, you probably already know what each of them does just by its name.

Hello, World!

Let's start by defining our root query:

<?php declare(strict_types=1);

namespace App;

use GraphQL\Type\Definition\ResolveInfo;
use Siler\GraphQL\Annotation\Field;
use Siler\GraphQL\Annotation\ObjectType;

/** [@ObjectType](https://github.com/ObjectType) */
class Query
{
    /** [@Field](https://github.com/Field)(description="A common greet") */
    public static function hello(): string
    {
        return 'Hello, World!';
    }
}

The ObjectType name will be inferred by the class name, so it will already be Query.

Then we just provide this class to the annotated function on the Siler\GraphQL namespace:

<?php declare(strict_types=1);

namespace App;

use function Siler\GraphQL\{annotated, init};

require_once __DIR__ . '/vendor/autoload.php';

$schema = annotated([Query::class]);
init($schema);

And that is it! It auto-magically servers the following SDL:

type Query {
  """
  A common greet
  """
  hello: String!
}

With the static hello method body already playing the resolver role, so:

query {
  hello
}

Returns:

{
  "data": {
    "hello": "Hello, World!"
  }
}

For a full-featured example, please take a look at: github.com/leocavalcante/siler/examples/graphql-annotations****

Caching

Parsing docblocks can be expensive, on production environments is recommended to cache this process by using a caching reader.

First, install doctrine/cache:

composer require doctrine/cache

Then pass a Doctrine\Common\Cache\Cache to Siler\GraphQL\Deannotator::cache() like:

Siler\GraphQL\Deannotator::cache(new ApcuCache());

{% hint style="info" %} Make sure you do this before the annotated() call. {% endhint %}

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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
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