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

Graphql Bundle Laravel Package

overblog/graphql-bundle

View on GitHub
Deep Wiki
Context7

Scalars

Here all supported built‐in Scalars:

  • Int
  • Float
  • String
  • Boolean
  • ID

Custom Scalar

With YAML

Here a simple example of how to add a custom Scalar:

DateTime:
    type: custom-scalar
    config:
        serialize: ["AppBundle\\DateTimeType", "serialize"]
        parseValue: ["AppBundle\\DateTimeType", "parseValue"]
        parseLiteral: ["AppBundle\\DateTimeType", "parseLiteral"]
<?php

namespace AppBundle;

use GraphQL\Language\AST\Node;

class DateTimeType
{
    /**
     * [@param](https://github.com/param) \DateTimeInterface $value
     *
     * [@return](https://github.com/return) string
     */
    public static function serialize(\DateTimeInterface $value)
    {
        return $value->format('Y-m-d H:i:s');
    }

    /**
     * [@param](https://github.com/param) mixed $value
     *
     * [@return](https://github.com/return) \DateTimeInterface
     */
    public static function parseValue($value)
    {
        return new \DateTimeImmutable($value);
    }

    /**
     * [@param](https://github.com/param) Node $valueNode
     *
     * [@return](https://github.com/return) \DateTimeInterface
     */
    public static function parseLiteral(Node $valueNode)
    {
        return new \DateTimeImmutable($valueNode->value);
    }
}

If you prefer reusing a scalar type

MyEmail:
    type: custom-scalar
    config:
        scalarType: '@=newObject("App\\Type\\EmailType")'

With annotation

You can create your custom-scalar type using the GraphQLType annotation with only one class. For example:

<?php

namespace AppBundle;

use Overblog\GraphQLBundle\Annotation as GQL;

/**
 * Class DatetimeType
 *
 * [@GQL](https://github.com/GQL)\Scalar(name="DateTime")
 */
class DatetimeType
{
    /**
     * [@param](https://github.com/param) \DateTime $value
     *
     * [@return](https://github.com/return) string
     */
    public static function serialize(\DateTime $value)
    {
        return $value->format('Y-m-d H:i:s');
    }

    /**
     * [@param](https://github.com/param) mixed $value
     *
     * [@return](https://github.com/return) mixed
     */
    public static function parseValue($value)
    {
        return new \DateTime($value);
    }

    /**
     * [@param](https://github.com/param) Node $valueNode
     *
     * [@return](https://github.com/return) string
     */
    public static function parseLiteral($valueNode)
    {
        return new \DateTime($valueNode->value);
    }
}
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle