0
votes

I am typing out my typedDefs and for one property it can return either String or Boolean.

const typeDefs = `
    type Analysis {
    id: String
    analysisName: String
    creator: String
    description: String
    datesValid: String 
}
`

I want datesValid to be either String or Boolean. I tried:

const typeDefs = `
    ...
    datesValid: boolString 
}

union boolString = String | Boolean
`

But this resulted in a 500 internal server error when trying to query via GraphiQL.

My end goal here is to type it as either String | Boolean

1

1 Answers

0
votes

According to the GraphQL specification type unions can only be created from object types. This means what you want to do is not possible.

I am sure there is a different way of solving you issue. Maybe a nullable date type is solving you problem? Or an enum that could have multiple values (e.g. VALID, INVALID, PENDING)? In extreme cases you own scalar type could serve the purpose.

Usually these limitations in the specifications are also meant to help people build consistent and simple to use APIs.