I’m working on a GraphQL schema where I need to allow users to upload files or provide direct URLs as input for an image field in a mutation. However, I’m facing difficulty defining an input type that can handle both file uploads and direct URLs, as well as checking the input type in the resolver mutation.
What Did I Try:
- I attempted to define a union type in my GraphQL schema that includes both the Upload scalar type (for file uploads) and the String scalar type (for direct URLs)
union ImageInput = Upload | String
. - I explored various approaches to check the input type in the resolver mutation, such as using conditional statements or type introspection, but haven’t found a satisfactory solution yet.
What Were I Expecting:
I expected to define an input union type that accepts either file uploads or direct URLs, and then be able to determine the type of input (file upload or direct URL) in the resolver mutation, allowing me to process the input accordingly.