Concluding Union Types
Implement a union type query in a React application, and test what you have learned.
We'll cover the following...
We'll cover the following...
Summarizing union types
Here is a quick recap of union types:
Our GraphQL API returns a union type for a user field.
A union-typed field will return a selection of objects that matches one of the types from the union. For our React application, the API returns either a
Usertype or aSuspendedUsertype.To know what type we are getting back from our API, we use the special
__typenamemetafield that GraphQL provides.. If we request thebadboyuser, we will get a user back with a__typenameofSuspendedUser. And if we requestgoodie-goodie, we will get back a user with the__typenameofUser. We can then use that ...