apollo-ios
apollo-ios copied to clipboard
Apollo 1.0 Beta: Fragment name collisions are easy
Bug report
In the new Apollo codegen, it seems that although graphql allows fragment names to match typenames, Apollo codegen doesn't with the new generated types that match the schema.
If I'm missing an config option to allow this, maybe it's just missing documentation?
Reduced case that does not compile.
schema.graphqls
type Query {
pet: Dog
}
type Dog {
name: String
}
DogQuery.graphql
query DogQuery {
pet {
...Dog
}
}
fragment Dog on Dog {
name
}
Fragments/Dog.swift
// @generated
// This file was automatically generated and should not be edited.
import ApolloAPI
@_exported import enum ApolloAPI.GraphQLEnum
@_exported import enum ApolloAPI.GraphQLNullable
public struct Dog: ArgoApolloCodeGen.SelectionSet, Fragment {
public static var fragmentDefinition: StaticString { """
fragment Dog on Dog {
__typename
name
}
""" }
public let __data: DataDict
public init(data: DataDict) { __data = data }
public static var __parentType: ParentType { .Object(ArgoApolloCodeGen.Dog.self) }
public static var selections: [Selection] { [
.field("name", String?.self),
] }
public var name: String? { __data["name"] }
}
Operations/Queries/DogQuery.swift
// @generated
// This file was automatically generated and should not be edited.
import ApolloAPI
@_exported import enum ApolloAPI.GraphQLEnum
@_exported import enum ApolloAPI.GraphQLNullable
public class DogQuery: GraphQLQuery {
public static let operationName: String = "DogQuery"
public static let document: DocumentType = .notPersisted(
definition: .init(
"""
query DogQuery {
pet {
__typename
...Dog
}
}
""",
fragments: [Dog.self]
))
public init() {}
public struct Data: ArgoApolloCodeGen.SelectionSet {
public let __data: DataDict
public init(data: DataDict) { __data = data }
public static var __parentType: ParentType { .Object(ArgoApolloCodeGen.Query.self) }
public static var selections: [Selection] { [
.field("pet", Pet?.self),
] }
public var pet: Pet? { __data["pet"] }
/// Pet
///
/// Parent Type: `Dog`
public struct Pet: ArgoApolloCodeGen.SelectionSet {
public let __data: DataDict
public init(data: DataDict) { __data = data }
public static var __parentType: ParentType { .Object(ArgoApolloCodeGen.Dog.self) }
public static var selections: [Selection] { [
.fragment(Dog.self),
] }
public var name: String? { __data["name"] }
public struct Fragments: FragmentContainer {
public let __data: DataDict
public init(data: DataDict) { __data = data }
public var dog: Dog { _toFragment() }
}
}
}
}
Schema/Objects/Dog.swift
// @generated
// This file was automatically generated and should not be edited.
import ApolloAPI
public final class Dog: Object {
override public class var __typename: StaticString { "Dog" }
}
Error

This should actually already be fixed in the release/1.0
branch. Object
, Interface
, and Union
are now namespaced inside of the schema as MySchema.Objects.Dog
, etc.
@jimisaacs Can you confirm if this is still an issue?
This was completed and is available in beta 2. Thanks!