Closed davidalbers closed 1 year ago
pls check the lates snapshot version, I believe it was fixed recently
Hi @sav007,
I updated to apollo-gradle-plugin:1.0.1-SNAPSHOT
and still see the same compilation error
If I am right you have 2 type definitions in your GraphQL schema that have name collision? One for enum another for object:
type PropertyAmenityCategory {
...
}
I'm trying to find the GraphQL specs if name
in schema definition is unique or not, but that seems like not right, that schema has 2 types with the same name.
Each type definition has a unique name
. However the names share the amenityCategory
suffix which seems to cause a problem with apollo-android.
Example schema.json:
"types": [
{
"kind": "OBJECT",
"name": "PropertyAmenityCategory",
...
},
{
"kind": "ENUM",
"name": "AmenityCategory",
...
},
{
"kind": "OBJECT",
"name": "PropertyInfo",
"fields": [
{
"name": "amenityCategories",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PropertyAmenityCategory",
"ofType": null
}
}
}
}
},
{
"name": "category",
"type": {
"kind": "ENUM",
"name": "AmenityCategory",
"ofType": null
}
}
]
}
agh, I see, so its field name causes this issue, well you can always use aliases https://graphql.github.io/learn/queries/#aliases but for sure we need to reserve enum type name and resolve name collision accordingly
That's a good workaround. Doing something like:
propertyAmenityCategories: amenityCategories {
...
}
will avoid the type mismatching and fixes the generated code errors.
Yeah, the existing name conflict resolution in codegen is not straightforward, I thought it's easy fix but not really
I have a query which I've simplified for this post:
amenityCategories
is a list ofPropertyAmenityCategory
Objects
.category
is anAmenityCategory
which is anEnum
.Although named similarly,
PropertyAmenityCategory
is very different fromAmenityCategory
.When the code is generated for it looks like this:
This causes an exception while building. The generated code should be something like:
apollo-android is incorrectly using
List<AmenityCategory>
for the fieldamenityCategories
.