-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Federating two postgraphile endpoints with Apollo Federation results in "Query.query can only be defined once" error with Relay support or "Union type _Entity" error without Relay support #8
Comments
Heyo, you're entering experimental territory there :) "Postgraphile with Federation support but without Relay support" should be working if you try it with #3 (Feedback very much appreciated). For the "Postgraphile with both Federation and Relay support", I want to get a PR into graphile-engine, so that you can disable and/or rename the fields "Query.nodeId" and "Query.node" per service. I hope to do that the coming Weekend, but cannot make any guarantees. |
Hey, thank you for the quick feedback! Postgraphile with Federation support but without Relay support I'll give a look at your PR #3 and give you feedback as soon as I get the chance. Postgraphile with both Federation and Relay support Not sure renaming "Query.nodeId" and "Query.node" is a good idea. It may break the Relay support at the gateway level. It may actually be more the responsibility of the federation gateway to handle that use case. There is an attempt here at fixing apollo-federation to support relay: |
Apollo-Federation-Relay looks very interesting. The following is based on these two conversations if someone seeing this want to read them up:
As a result of the second discussion, I think you have two options. Let me explain: So, from that realization, you have two methods going forward:
export default (function NodePlugin(
builder
) {
builder.hook(
"build",
(build) => {
return build.extend(
build,
{
getNodeIdForTypeAndIdentifiers(Type, ...identifiers) {
return base64(
`${Type}:`+JSON.stringify([this.getNodeAlias(Type), ...identifiers])
);
},
getTypeAndIdentifiersFromNodeId(nodeId) {
const decoded = base64Decode(nodeId);
const [alias, ...identifiers] = JSON.parse(decoded.slice(decoded.indexOf(':')));
return {
Type: this.getNodeType(alias),
identifiers,
};
},
},
`Describe what you are doing`
);
},
["Your plugin name"],
[],
["Node"] // run this AFTER "Node"
);
}); As you are already experimenting with this, it would be really cool if you tried one (or both) of those ways and reported back! |
Thank you @phryneas for this very detailed step by step explanation! This is very helpful! I'll try to test this this week, I feel bad since your explanation is so detailed but I have design docs to write first. I will let you know! |
No worries, Open Source takes time :) |
i have just encountered this same problem, i think. tho i am not using the node plugin. @phryneas - i could put my schemas in a repo for you if that would help. not sure it's adding anything tho. i have not tried to dig into the issue deeper - maybe it's time for me to learn something! this occurs when i have the FederationPlugin included, whether i try to use the apollo gateway or whether i just try to hit graphiql from the server. if i remove the plugin, then graphiql finds my schema just fine. |
my stack trace is different, tho:
|
I'm on the road so I can take a look only in a few days, but then your schemas could be interesting. It sounds to me like you are not exposing any types. You need to expose at least one to avoid that error
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
|
i thought that might be the case so i've done some more investigating. my original db had two schemas - one with jwt_token and an id generator function, and another with one table. i've consolidated all into one schema (below). i now get a slightly different error (also below). the overall behaviour is the same - postgraphile works fine w/o the federation plugin. dbscript;
current error trace:
|
figured it out... not that i shouldn't have done so for other reasons... but you have to have a primary key on your table in order for the Node interface to implemented in order for it to be included in federation types... ... so, my bad... and now i am back to the first error:
|
apollographql/federation-jvm#20 (comment) this sounds like it might be a bug in the gateway itself |
You are getting these because multiple microservices are defining those and federation cannot decide which one to use. The By the way, @cedricvidal is there any progress from your side? :) |
@phryneas - thanks, and i'll try that out when i get back to this (hopefully this weekend), unless it moves forward by other paths. |
For people who don't depend on the import { Plugin } from "graphile-build";
import { omit } from "lodash";
export default (function RemoveNodeAndQueryFieldsPlugin(builder) {
builder.hook("GraphQLObjectType:fields", (fields, _, { Self }) => {
if (Self.name !== "Query") {
return fields;
}
return omit(fields, ["node", "nodeId", "query"]);
});
} as Plugin); We need to remove the Node interface as well: import { Plugin } from "graphile-build";
export default (function StripNodeInterfacePlugin(builder) {
builder.hook("GraphQLObjectType:interfaces", interfaces => {
return interfaces.filter(int => int.name !== "Node");
});
} as Plugin); These two plugins should allow you to federate your services. Obviously this doesn't really help you if you need that functionality |
Hello guys,
I'm trying to federate two postgraphile endpoints with the Apollo Federation gateway but can't seem to find a working combination.
Postgraphile with both Federation and Relay support
Given I started the postgraphile endpoints with Federation support (using FederationPlugin) and Relay support (default NodePlugin activated), when I start the Apollo Federation gateway, it complains with the following error:
I investigated a bit and looking at the Apollo Federation demo here https://github.com/apollographql/federation-demo, the federated services don't expose node and nodeId fields in the Query type.
Postgraphile with Federation support but without Relay support
I therefore tested starting the two postgraphile endpoints without Relay support (skipping the
NodePlugin
plugin) but theFederationPlugin
plugin fails with :Apparently, this is a known problem in Apollo Federation that Relay is not supported:
https://spectrum.chat/apollo/apollo-federation/federation-with-relays-node-interface~c0ae3cb1-d243-491a-ac58-17307629e31e
Conclusion
So, this problem may be spread between Postgraphile and Apollo Federation Gateway.
That being said, I can't find a working combination so far, with or without Relay support.
The text was updated successfully, but these errors were encountered: