-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using fastify-gql in place of Apollo Gateway does not work #184
Comments
Wow, good finding and thanks for checking this out. I’m a bit unsure how that would work... would you like to send a Pull Request to address this issue? Remember to add unit tests. |
I would help, but I don't know the proper expected implementation of the Gateway (in this case the expected way to handle conflicting directives when creating the combined schema). I tried looking for a specification, but could only find an implementation specification for the Federated services, and an API specification for the Gateway, but not a specification for implementing a Gateway. Under what basis was the Gateway implementation designed? By just reverse engineering the Apollo Gateway implementation? I could do my best to try different things regarding directives using the Apollo implementation and copy the observed functionality over to fastify-gql, if there's no better expected methodology. |
I just found this:
So, I guess we can strip directives from the service schemas before merging them? I'll see if doing that seems to bring parity in behavior. |
Amazing, I think that would work! |
Did some work on this today. The problem seems to be that, as stated above, the Gateway should not expose From where I'm seeing it, we need to refactor |
The problem seems to be partially resolved by passing // Add all extensions
federationSchema = extendSchema(
federationSchema,
{
kind: Kind.DOCUMENT,
definitions: extensions
},
{ assumeValid: isGateway },
) This change allows the service to run and successfully execute queries. However, I'm not sure if this is opening up the system to problems due to skipping validation. Furthermore, the |
Would you like to attempt a PR? I would not be able to help much in the coming weeks :(. I think your hot fix is feasible and should unstuck you. |
I'm not stuck per-se. I'm shopping around for a solution that can offer Federation as well as subscriptions, and am willing to put work into bridging gaps. I don't feel comfortable submitting a PR that might introduce bugs and/or repercussive implications due to not fully understanding the system. I really do think that the current implementation needs to change from depending on schema directives at query time to depending on configuration that is derived from the directives before they are removed. This will also lay a foundation for providing validation of compatibility across federated services, which Apollo Server currently provides. |
I am still curious as to what the answers are to questions I asked originally:
|
@frikille might be able to answer that. |
I've done some investigation on this whilst I was looking at #220 I think I have found the underlying issue, these are my findings:
|
I've created a quick PR to demonstrate the issue and a potential fix: #221 |
I don't have time to look into this, but just wanted to comment on
While this is true that this is expected, that doesn't mean that it's valid to attach the same directives to extended types. The way Federation defines how separate services need to attach directives to their own schemas does not dictate what is valid within the same schema.
Based on what I remember when testing, this is not the case. If you have a type with a directive, and extend the type with the same directive, then it will give the error. It makes sense that you'd be getting the error with multiple extensions of the same type with the same directive, for this reason. It's possible I'm remembering wrong, however. In any case, in order to abide by Apollo's documentation we still need to strip the directives from the final schema. Since this is necessary, then removing them before extending kills two birds with one stone. It just means we need to capture the configuration as defined by these directives beforehand. |
Let me rephrase that. The Apollo docs clearly state that when extending entities, the
As far as I can see, this is not the case - or at least it's not enforced at the The error we get in the demo repository (and also in fastify-gql own example in https://github.com/mcollina/fastify-gql/blob/master/examples/gateway-subscription.js) is thrown by the call to To prove that I made this small change https://github.com/mcollina/fastify-gql/pull/221/files#diff-d9185daf57698ed90d572d1966e61b16R253-R258 where extensions are added one at the time and that fixed the issue: a sign that
I agree with this. Regardless of what is actually causing the exception we are seeing, the correct implementation would be to replicate the behaviour of Apollo, which is to strip the directives in the federated schema. I took a look at Apollo's code and that appears to be happening in https://github.com/apollographql/apollo-server/blob/5bab3aedeeb1e70c636f3aa3ac7a147679f450f7/packages/apollo-federation/src/composition/normalize.ts#L20 (more specifically in https://github.com/apollographql/apollo-server/blob/5bab3aedeeb1e70c636f3aa3ac7a147679f450f7/packages/apollo-federation/src/composition/normalize.ts#L270). So, to sum up my point:
|
I've spent more time debugging this, and I have come to the conclusion that my understanding of the issue as expressed in the previous message was incomplete. Here's my new understanding:
gets added to the schema as is, still retaining the I'm working on a PR to replicate the behaviour by calling |
Hi,
As a proof of concept, I tried taking this demo repository and replace Apollo Gateway with fastify-gql. The federated services start fine (as expected). Then, when I try to start the Gateway server, I get this error:
My guess is that both the original definition for
Product
and its extended clause have a@key
directive, which are trying to be merged together. I wonder how Apollo handles this situation?Here's my fork to try it for yourself.
The text was updated successfully, but these errors were encountered: