-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Unable to add type "Service" in federation #1256
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
nope |
I just hit the same thing - glad it got reported. The One of them represents my actual model, the other looks like this: Service struct {
SDL func(childComplexity int) int
} gqlgen version |
I just found this one as well when trying to migrate an existing schema to use federation, so renaming my type is hardly an option without causing breaking changes. It seems to be caused by an internal model representing the service (as required by Apollo Federation) defined here: https://github.com/99designs/gqlgen/blob/master/plugin/federation/fedruntime/runtime.go#L6 This is currently a blocker for us, so I'll take a stab at solving it in a way that works for us. If anyone has any bright ideas as to how this can be fixed without renaming the internal struct, I'm open to suggestions. |
@zhevron I took a look at this too and believe it's a limitation in this function here: gqlgen/codegen/templates/templates.go Lines 285 to 306 in 997da42
The actual schema type is I started an attempt to fix it by doing something as simple as this - but soon got stuck five layers deep in templates and code generation with no way out :-/ if strings.HasPrefix(name, "_") {
return fmt.Sprintf("Underscore%s", string(runes))
} The real "blow up" seems to occur here: gqlgen/plugin/federation/fedruntime/runtime.go Lines 3 to 8 in 997da42
So a different approach I took was through renaming |
@moensch You are absolutely correct that this is what causes it. We had our own entities named This is how I fixed it for us, but YMMV: zhevron@cecd727 In short, I renamed the gqlgen |
I hear you. We are at a point where we could very easily still absorb upstream API changes. I would suggest you throw the PR out there and start gathering feedback - it looks eerily similar to what I've come up with so far. I also tried looking at the code surrounding "complexity" to see why this is smashing types from different packages into the same "namespace". This seemed wrong to me, and is one of probably two places a fix could help avoid the need to rename this Go type. |
I'll take one last pass at the solution to see if I can at least move the "logic" of the change out of the core |
Our team just hit this as well. We have a type named I'm confused why something like this doesn't work: in
This seems to be handled fine by gqlgen, but the error still happens, and the duplicate |
@zhevron sorry for double ping, I mostly copy-pasta'd your work into a PR. It's what we're attempting in our own fork for now, so either way thanks for the code. |
@AndrewRayCode No worries at all. I'm glad you could take the time to make this. I've been absolutely swamped since the last update and will be for the foreseeable future. Turns out it's hard to get the time to address this when your workaround fork is working just fine. |
Hi! I merged #1531 which I think resolves this in a more general way. If you encounter problems, please open a new issue and reference both this and that. Thanks! |
I'm declaring a GraphQL type called "Service" in a federated gqlgen. gqlgen fails to generate because of "redeclared service type".
Reproduction: https://github.com/josemarluedke/gqlgen-fed-service-type
GraphQL: https://github.com/josemarluedke/gqlgen-fed-service-type/blob/master/graph/schema.graphqls
What happened?
Here is the generated code: https://github.com/josemarluedke/gqlgen-fed-service-type/blob/master/graph/generated/generated.go#L58-L64
What did you expect?
Only one type Service declared. No conflict with the Federation.
Minimal graphql.schema and models to reproduce
Full repro: https://github.com/josemarluedke/gqlgen-fed-service-type
GraphQL: https://github.com/josemarluedke/gqlgen-fed-service-type/blob/master/graph/schema.graphqls
versions
gqlgen version
v0.11.3go version
1.13.6The text was updated successfully, but these errors were encountered: