rdey / graphql-federation-bundle

3 stars 0 forks source link

_service Query in sdl is breaking federation requirements #2

Closed Bastianowicz closed 1 year ago

Bastianowicz commented 1 year ago

First of all: Thank you for this repo, which (I agree to you) should not exist at all. Either way it is needed and you provided it.

Unfortunately we are experiencing an issue while integrating the federated schema into a mercurius or apollo gateway server. Maybe you have an idea how to solve this. We would also try to help implementing the fix.

Reproduction:

Expectation:

Experienced:

Setup

Config

# graphql.yaml
overblog_graphql:
  definitions:
    schema:
      query: RootQuery
    mappings:
      types:
        - type: attribute
          dir: "%kernel.project_dir%/src/GraphQL"
          suffix: ~
        - type: attribute
          dir: "%kernel.project_dir%/src/Module/*/Driver/GraphQL"
          suffix: ~
  security:
    enable_introspection: '%kernel.debug%'

Chances are we messed up the configuration somehow so we would love any kind of hint that you could provide.

magnusnordlander commented 1 year ago

I'm unable to reproduce this, neither in our production apps, nor in a reduced case I created here: https://github.com/magnusnordlander/federation-test

I'm not on the exact same version of dependencies as you, but I can't see how that would affect this. Can you provide some means of reproducing the issue?

Bastianowicz commented 1 year ago

Hey thank you for replying this quick. Can you please clarify what the expected behaviour (i.e. your experienced behaviour) is? Is it a) you don't have a _service query in your RootQuery Type in the sdl or b) you have a Service type defined in your sdl?

I think the main difference between our setup and your provided test repo is that we use attribute driven specification instead of config file driven specification. I debugged through the redeye- as well as the overblog code a little and the service query already exists when the schema is being envoked in overblogs request executor. How it gets in there is dark magic for me (I simply don't get it). What I did see though is that it uses the same method for resolving the schema as the request handler does. So hard erasing it during the resoltion leads to not having the service query at all. So this problem is kind of recursive and I don't have an idea how to patch that with little afford.

Do you think it might be related to the attributes and auto merging in rootQuery class? I'll append an example of how our Type definitions look like.

use Overblog\GraphQLBundle\Annotation as GQL;

#[GQL\Type(name: 'Profile')]
#[GQL\Description('Ein Profil eines Users')]
class ProfileType
{
    // @formatter:off
    public function __construct(

        #[GQL\Field(type: "ID!")]
        #[GQL\Description('Die UserId')]
        public readonly int $identifier,

        #[GQL\Field(type: "String!")]
        public readonly string $user_name,
    )
    {
    }
}
#[GQL\Type]
class RootQuery
{
}
magnusnordlander commented 1 year ago

The expected behavior is that _service exists when using Schema introspection, but not when querying _service.

See the following screenshot:

Screen Shot 2023-01-10 at 11 50 43
Bastianowicz commented 1 year ago

At least it is good to know that it is supposed to work as we expected :D Can you anticipate if the usage of attributes might have an impact on this misbehaviour of ours? image

magnusnordlander commented 1 year ago

I'm guessing the auto merging might be a possible culprit. If you're able to make this reproducible, I'd be happy to take a look at what's causing it.

Bastianowicz commented 1 year ago

So I created this reproduction repo which does show our problem in a more simplified manner. It is forked from your repo so the structure should be familiar. I also added a dockerfile so you can run it right away if you need to (i needed one anyway). What changed here is basically that I added the RootQuery of ours and added a new config to also look for attributed types. anyway you'll see what I did in the git log anyway. If I can provide any further help please let me know.

magnusnordlander commented 1 year ago

Okay, so the issue seems to be when the Query type isn't named Query, as in this case when it is named RootQuery. This is an issue in skillshare/apollo-federation-php rather than this repository: https://github.com/Skillshare/apollo-federation-php/blob/main/src/Utils/FederatedSchemaPrinter.php#L421

I'd suggest a work-around by renaming your Query type, but reporting this upstream would also be beneficial.

Bastianowicz commented 1 year ago

Works. Thank you so much for your support today. I'll consider raising another issue on the skillshare repository