Issue:
Apollo creates an invalid auto generated file from a graphql query when it contains a enum type. When the class with type enum is generated, it extends the Apollo.JSONEncodable and Apollo.JSONDecodable classes, which do not appear to actually exist.

'JSONEncodable' is not a member type of 'Apollo'
'JSONDecodable' is not a member type of 'Apollo'
Partial Solution:
To fix this temporarily I auto generated the invalid code for this query, copied the contents, and put them into a separate swift file. To fix the 'JSONEncodable' is not a member type of 'Apollo' warning I simply changed Apollo.JSONEncodable to JSONEncodable. It seems as though if you just remove the Apollo namespace from the class extensions, this fixes the issue.
GraphQL Query:
The graphql query works fine in postman / insomnia. I can't give out the exact query, but it would be similar to this, given the knowledge of the schema below:
query Icons {
icons {
icon
}
}
Schema:
...
{
"kind": "ENUM",
"name": "Icon",
"description": "An enum of icons used by the system",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "icon1",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "icon2",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
...
],
"possibleTypes": null
},
...
The partial solution is starting to be very tedious. I found it strange that no once else has ran into this issue.
I had this error because I have a class with the same name in an attempt to make a singleton.
class Apollo {
static let shared = Apollo()
let client: ApolloClient
init() {
client = ApolloClient(url: URL(string: ProcessInfo.processInfo.environment["GRAPHQL_BASE_URL"]!)!)
}
}
It was fine after I renamed it. It is probably interfering with the namespace.
I am doing the exact same thing. Thanks for the response. Ill change the class name later but I'm certain that is the issue that is happening.
I had this error because I have a class with the same name in an attempt to make a singleton.
class Apollo { static let shared = Apollo() let client: ApolloClient init() { client = ApolloClient(url: URL(string: ProcessInfo.processInfo.environment["GRAPHQL_BASE_URL"]!)!) } }It was fine after I renamed it. It is probably interfering with the namespace.
thanks reply
Oh weird! I should look into that, we've been recommending Apollo as a singleton name but maybe we shouldn't 馃檭
Most helpful comment
I had this error because I have a class with the same name in an attempt to make a singleton.
It was fine after I renamed it. It is probably interfering with the namespace.