Apollo iOS Client: Good way to detect the type from interface implementation

Imagine I have a query like this

query {
  findEventsAtVenue(venueId: "ABC") {
    id
    name
    ... on Festival {
      performers
    }

    ... on Concert {
      performingBand
    }

    ... on Conference {
      speakers
      workshops
    }
  }
}

Now in the client code I will be receiving array of events which could be a Concert, Conference or Festival, whats the best way to identify the objects… do we write something like below or can we do some kind of type and do a switch case?

for event in Events {

if event.asFestival {
....do something
} else if event.asConcert {
....do something
} else if event.Conference {
....do something
}

}

I believe you should be able to use type casting to do this since you’re explicitly casting to those types, and they should get generated as subtypes of Event for that query:

if let festival = event as? Event.Festival {
   // do something with `festival`
} else if let concert = event as? Event.Concert {
   // do something with `concert`
} else if let conference = event as? Event.Conference {
   // do something with `conference`
} // .. etc

Some how it gives me error, to exactly tell, we use fragments a lot and this is how it looks, sorry for the formatting issues and syntaxes, due to client confidentiality I cannot provide the exact code, so I am making up with test data.

query {
  findEventsAtVenue(venueId: "ABC") {
	…VenueEventsInfo
  }
}

Fragment VenueEventsInfo on Venue {

    venueId
    name
	events {
	id 
	name

    ... on Festival {
      performers
    }

    ... on Concert {
      performingBand
    }

    ... on Conference {
      speakers
      workshops
    }
	}

}

For me this will end up like VenueEventsInfo.Event . There will be

        public struct VenueEventsInfo: GraphQLFragment {
            public struct Event: GraphQLSelectionSet {
                public struct AsFestival: GraphQLSelectionSet {}

                public struct AsConcert: GraphQLSelectionSet {}
            }
        }

So below fails…

if let festival = event as? VenueEventsInfo.Event.AsFestival

:slight_smile: not sure if I am making sense. Let me know your thoughts.