apollographql / apollo-tooling

✏️ Apollo CLI for client tooling (Mostly replaced by Rover)
https://apollographql.com
MIT License
3.04k stars 469 forks source link

client:codegen --no-addTypename for SWIFT target #1357

Open xunshuairu opened 5 years ago

xunshuairu commented 5 years ago

Code generate --no-addTypename is not working for swift target. Any version <=2.13.1 has this issue. Apollo-iOS example can reproduce.

martijnwalraven commented 5 years ago

Apollo iOS requires the __typename to be available for every object, so I think this is working as intended.

ivopintodasilva commented 5 years ago

Tested on v2.17.4 and it does not seem to be working either

theladyjaye commented 4 years ago

Version: apollo/2.24.0 darwin-x64 node-v10.16.3

I see the same issue. When __typename is present the GraphQL deserialization fails from my Apollo server with:

Failure! Error: GraphQLResultError(path:myMutation.__typename, underlying: Apollo.JSONDecodingError.missingValue)
apollo codegen:generate --target=swift --includes="./GraphQL/**/*.graphql" --localSchemaFile="schema.json" --no-addTypename Services/GraphQL

If I manually remove the

GraphQLField("__typename", type: .nonNull(.scalar(String.self))),

from the generated code things under public static let selections: [GraphQLSelection] = [

things start working again.

aventurella-honey commented 4 years ago

Here is where this error originates:

https://github.com/apollographql/apollo-ios/blob/master/Sources/Apollo/Decoding.swift#L149-L151

 guard let runtimeType = object["__typename"] as? String else {
      throw GraphQLResultError(path: path + "__typename", underlying: JSONDecodingError.missingValue)
    }
abashyam commented 4 years ago

The issue still exists. It doesn't appear to be a tooling issue but more with the apollo-ios. Should it be logged somewhere else for visibility? I am happy to work with someone to resolve this issue.