DEV Community

Discussion on: Understanding GraphQL Mutations

 
eveporcello profile image
Eve Porcello • Edited

Oh gotcha! Look into union types. Unions allow you to return this or that and are often used with Error types.

Your example would probably look like this in the schema:

union LoginResult = User | CustomError

login(...): LoginResult
Enter fullscreen mode Exit fullscreen mode

The docs describe unions in more detail: graphql.org/learn/schema/#union-types
And Sasha Solomon has written about how she's used this pattern at Medium and Twitter: medium.com/@sachee/200-ok-error-ha...

Thread Thread
 
alexr89 profile image
Alex

Hey Eve, sorry for not replying. I got this working using your initial idea - returning a custom type :)