how to define two types for one graphql field code example
Example 1: how to return multiple types in graphql schema
type Artist {
id: Int,
name: String,
}
type Venue {
id: Int,
name: String,
}
union Owner = Artist | Venue
type Event {
id: Int!,
owner: Owner,
}
type RootQuery {
event(id: Int): Event,
venue(id: Int): Venue,
}
Example 2: graphql nested schema
const StaffType = new GraphQLObjectType({
name: 'Staff',
fields: {
id: {type: GraphQLInt},
name: {type: GraphQLString},
role: {type: GraphQLString},
address: {type: AddressType}
}
})
const AddressType = new GraphQLObjectType({
name: 'Address',
fields: {
street: {type: GraphQLString},
town: {type: GraphQLString}
}
})