Skip to content

How to determine is it query or mutation field executed from field middleware? #477

Answered by andrew-demb
andrew-demb asked this question in Q&A
Discussion options

You must be logged in to vote

After many investigation iterations, I found, that important information bypassed with GraphQL\Type\Definition\ResolveInfo (https://github.com/webonyx/graphql-php/blob/0.13.x/docs/reference.md#graphqltypedefinitionresolveinfo).

It is pretty complex to inject it into the resolver (and don't break other arguments bypassing) from the middleware perspective, but it just works.

Here's a working example of how to know about operation type in the middleware (example with checking for query operation type).

<?php
declare(strict_types=1);

namespace App\Graphql;

use GraphQL\Type\Definition\FieldDefinition;
use GraphQL\Type\Definition\ResolveInfo;
use TheCodingMachine\GraphQLite\Middlewares\FieldH…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@andrew-demb
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by andrew-demb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants