Can a Cell return a GQL Union?

I would like to return and use a GraphQL Union from a Cell

something like this, but I can’t get it to work

I make a call and most times I get an answer and sometimes the answer is going to take a looooooong time to come back and I get a message to that effect and an authorized url to poll against

export const QUERY = gql`

  type AnswerRecord {
    answer
    question
    business
    reduction
    access
  }

  type AnswerPoller {
    message
    authorization
  }

  union AnswerResult = AnswerRecord | AnswerPoller

  query AnswerQuery {
    answer AnswerResult
  }
`

export const Loading = () => <div>Loading...</div>

export const Empty = () => <div>Empty</div>

export const Failure = ({ error }) => <div>Error: {error.message}</div>

export const Success = ({ answer }) => {
  return JSON.stringify(answer)
}

I just ended up making everything optional in the .sdl. file

and I’ll deal with whatever part comes back

export const QUERY = gql`
    answer {
    answer
    question
    business
    reduction
    access
    message
    authorization
   }
  }
`

export const Loading = () => <div>Loading...</div>

export const Empty = () => <div>Empty</div>

export const Failure = ({ error }) => <div>Error: {error.message}</div>

export const Success = ({ answer }) => {
  return JSON.stringify(answer)
}

Have you tried Graphql fragments?

1 Like

Thanks! The last big GraphQL project I did could have benefited from those!!

I had found some code back then to help with storing your GraphQL across multiple files to help with organization that made it easier, can’t find the project and don’t remember the link but it was along these lines - Modularizing your GraphQL schema code - Apollo Blog

There’s just too much to learn and remember - thanks for your efforts on Redwood, you’re making this old dogs life easier

1 Like

I won’t take credit ! Core team + community effort :), we’re always expanding, take the red pill :sunglasses:

You’re in odd luck actually: I found out about unions and fragments 2 days ago. That must have been the shortest time I ever relayed some freshly acquired knowledge.

May I ask what you are building with RW?

I’m building a demo for a product we are trying to sell, can’t say more right now - sorry

I know the feeling x)
Best of luck then!

1 Like