`convertDefinition` failing when `name` == concatenated `namePrefix`
- Dominant language
- Go
- Stars
- 1.3k
- Forks
- 143
- Avg merge
- 4h 50m
- Merged PRs (30d)
- 1
Description
**Describe the bug**
I am encountering "conflicting definition" errors when using specific GraphQL field and type names with genqlient. The error message is as follows:
> ...../schema.graphql:13: conflicting definition for FooBarA; this can indicate either a genqlient internal error, a conflict between user-specified type-names, or some very tricksy GraphQL field/type names: expected 2 fields, got 1
exit status 1
> main.go:9: running "go": exit status 1
**To Reproduce**
The issue occurs under specific conditions:
1. The schema includes a union whose name is the concatenation of a parent type's name and its field names in camel case.
2. The query includes fragments named identically to the types:
For a clearer understanding and a practical demonstration, I prepared a minimal reproducible example here: https://github.com/Ynng/genqlient-bug
**Expected behavior**
I expect the code generation process to successfully handle these scenarios without encountering conflicting definition errors.
**genqlient version**
`v0.6.0`
**Additional Information**
My guess is that the issue arises when `convertDefinition()` encounters a `name` that is the same as `namePrefix` list concatenated and formatted.
This causes problems down the road for Unions, leading to duplicate "UnionNameImplName" definitions.
I think the issue can be traced back to these two lines:
https://github.com/Khan/genqlient/blob/28aafc79a9f9065f7cb7e8bb2df49e5795896aeb/generate/convert.go#L465
https://github.com/Khan/genqlient/blob/28aafc79a9f9065f7cb7e8bb2df49e5795896aeb/generate/convert.go#L496
These lines inadvertently create two conflicting definitions: one from "UnionName + ImplName" and another from "Union + Name + ImplName."
Contributor guide
Research direction
Start in generate/convert.go at the convertDefinition logic referenced around lines 465 and 496, then reproduce the conflict with the linked minimal example. Trace how the matching name and namePrefix produce the duplicate union definitions. Done means the example generates successfully without conflicting-definition errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100