Skip to content
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

Fragment doesn't get code generated when embedded in inline fragment with same type information #54

Closed
fruitcoder opened this issue Feb 7, 2017 · 1 comment
Labels
bug Generally incorrect behavior

Comments

@fruitcoder
Copy link

In the following example:

query Details($id: ID!) {
  viewer {
    Model(id: $clipId) {
      id
      ...BasicInfo
      recommendations {
        edges {
          node {
            id
            ... on ModelInterface {
              ...BasicInfo
            }
          }
        }
      }
    }
  }
}

fragment BasicInfo on ModelInterface {
  title
}

we get the following code generation:

public struct Recommendation: GraphQLMappable {
  public let __typename = "XXXConnection"
  public let edges: [Edge?]?

  public init(reader: GraphQLResultReader) throws {
    edges = try reader.optionalList(for: Field(responseName: "edges"))
  }

  public struct Edge: GraphQLMappable {
    public let __typename = "XXXEdge"
    public let node: Node?

    public init(reader: GraphQLResultReader) throws {
      node = try reader.optionalValue(for: Field(responseName: "node"))
    }

    public struct Node: GraphQLMappable {
      public let __typename: String
      public let id: GraphQLID

      public init(reader: GraphQLResultReader) throws {
        __typename = try reader.value(for: Field(responseName: "__typename"))
        id = try reader.value(for: Field(responseName: "id"))
      }
    }
  }
}

The type constraint for the conditional fragment to be a ModelInterface is redundant but the fragment should still be included in the generated code.

@martijnwalraven martijnwalraven added the bug Generally incorrect behavior label Feb 7, 2017
@martijnwalraven
Copy link
Contributor

I believe this has been fixed in Apollo iOS 0.6.0-beta.1. Make sure to use npm install -g apollo-codegen@next until it is out of beta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior
Projects
None yet
Development

No branches or pull requests

2 participants