Union Types
Union Types in GraphQL is used to return union of multiple object types i.e. It allows the schema to return one of the multiple object. Union Types can not define shared fields among various Types. It is represented by using Union Sign ” | “.
Syntax:
union Object_name = object_1 | Object_2 | Object_3
Example:
union Entertainment = Song | WebSeries
type Query {
allEntertainment: [Entertainment] # This list can include both Song and WebSeries objects
}
Types in GraphQL
GraphQL is a strongly typed query language used as a manipulative language for various APIs. It is also called a query language for APIs. GraphQL also helps to describe our data. GraphQL services can run in any language In this, Types are the fundamental concepts that define various data types present in GraphQL and It is also used to define the schema using different data types. There are multiple types in GraphQL.