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 Php Laravel Package

webonyx/graphql-php

PHP implementation of the GraphQL specification, based on graphql-js. Build schemas, types, and execute queries/mutations in your PHP apps. Widely used, well-tested, and documented with examples and class reference.

View on GitHub
Deep Wiki
Context7

Protection Against Malicious Queries

GraphQL allows a large degree of dynamism and flexibility for clients to control what happens on the server during query execution. Malicious clients may abuse this by sending very deep and complex queries whose execution exhausts server resources.

At a basic level, it is recommended to limit the resources a single HTTP request can use through PHP settings such as:

In addition, graphql-php offers security mechanisms that are specific to GraphQL.

Query Complexity Analysis

This is a port of Query Complexity Analysis in Sangria.

Complexity analysis is a separate validation rule which calculates query complexity score before execution. Every field in the query gets a default score 1 (including ObjectType nodes). Total complexity of the query is the sum of all field scores. For example, the complexity of introspection query is 109.

If this score exceeds a threshold, a query is not executed and an error is returned instead.

Complexity analysis is disabled by default. You may enable it by setting a maximum query complexity:

use GraphQL\GraphQL;
use GraphQL\Validator\Rules\QueryComplexity;
use GraphQL\Validator\DocumentValidator;

$rule = new QueryComplexity(100);
DocumentValidator::addRule($rule);

GraphQL::executeQuery(/*...*/);

This will set the rule globally. Alternatively, you can provide validation rules per execution.

To customize field score add complexity function to field definition:

use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ObjectType;

$type = new ObjectType([
    'name' => 'MyType',
    'fields' => [
        'someList' => [
            'type' => Type::listOf(Type::string()),
            'args' => [
                'limit' => [
                    'type' => Type::int(),
                    'defaultValue' => 10
                ]
            ],
            'complexity' => fn (int $childrenComplexity, array $args): int => $childrenComplexity * $args['limit'],
        ]
    ]
]);

Limiting Query Depth

This is a port of Limiting Query Depth in Sangria.

This is a simpler approach that limits the nesting depth a query can have. For example, the depth of the default introspection query is 7.

This rule is disabled by default. You may enable it by setting a maximum query depth:

use GraphQL\GraphQL;
use GraphQL\Validator\Rules\QueryDepth;
use GraphQL\Validator\DocumentValidator;

$rule = new QueryDepth(10);
DocumentValidator::addRule($rule);

GraphQL::executeQuery(/*...*/);

This will set the rule globally. Alternatively, you can provide validation rules per execution.

Disabling Introspection

Introspection is a mechanism for fetching schema structure. It is used by tools like GraphiQL for auto-completion, query validation, etc.

Introspection is enabled by default. It means that anybody can get a full description of your schema by sending a special query containing meta fields __type and __schema .

If you are not planning to expose your API to the general public, it makes sense to disable this feature.

GraphQL PHP provides you separate validation rule which prohibits queries that contain __type or __schema fields. To disable introspection, add following rule:

use GraphQL\GraphQL;
use GraphQL\Validator\Rules\DisableIntrospection;
use GraphQL\Validator\DocumentValidator;

$rule = new DisableIntrospection(DisableIntrospection::ENABLED);
DocumentValidator::addRule($rule);

GraphQL::executeQuery(/*...*/);

This will set the rule globally. Alternatively, you can provide validation rules per execution.

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport