union types
See original GitHub issueI have a union type called TestUnion:
# Data type and array type for data values
interface UaDataValue {
dataType: String
arrayType : String
statusCode: StatusCode
}
type UaNull implements UaDataValue {
dataType: String
arrayType: String
value: String
statusCode: StatusCode
}
type UaLong implements UaDataValue {
dataType: String
arrayType: String
value: Int
statusCode: StatusCode
}
type UaInt implements UaDataValue {
dataType: String
arrayType: String
value: Int
statusCode: StatusCode
}
type UaIntArray implements UaDataValue {
dataType: String
arrayType: String
value: [Int]
statusCode: StatusCode
}
type UaFloat implements UaDataValue {
dataType: String
arrayType: String
value: Float
statusCode: StatusCode
}
union TestUnion = UaNull | UaLong | UaInt | UaFloat | UaIntArray
type UaNode {
id: String!
nodeClass: NodeClassEnum
browseName: QualifiedName
displayName: LocalizedText
writeMask: Int
userWriteMask: Int
isAbstract: Boolean
symmetric: Boolean
inverseName: LocalizedText
containsNoLoops: Boolean
eventNotifier: Int
nodeId: ExpandedNodeId
description: LocalizedText
dataValue: TestUnion
self: UaNode
}
I am querying this with:
const MyNodeQuery = gql`query Query($id: String!) {
uaNode(id: $id) {
id
dataValue {
... on UaIntArray {intArrayValue: value, arrayType}
... on UaLong {longValue: value arrayType}
... on UaNull {nullValue: value, arrayType}
... on UaFloat {doubleValue: value, arrayType}
... on UaInt {intValue: value, arrayType}
}
}
}`;
I’m getting a UaIntArray (say) from the api ie it returns only intArrayValue
{
"data":{
"uaNode":{
"id":"ns=2;i=10931",
"dataValue":{
"intArrayValue":[
-6234,
-28844
],
"arrayType":"Array",
"__typename":"UaIntArray"
},
"__typename":"UaNode"
}
}
}
- however in the data that gets passed to my component props (react) the other properties are filled in (longvalue, nullValue, doubleValue. intValue)
"dataValue":{
"intArrayValue":[
-6234,
-28844
],
"longValue":[
-6234,
-28844
],
"nullValue":[
-6234,
-28844
],
"doubleValue":[
-6234,
-28844
],
"intValue":[
-6234,
-28844
],
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Handbook - Unions and Intersection Types - TypeScript
A union type describes a value that can be one of several types. We use the vertical bar ( | ) to separate...
Read more >Union type - Wikipedia
Some programming languages support special data types, called union types, to describe such values and variables. In other words, a union type definition ......
Read more >TypeScript Union Types - W3Schools
Union types are used when a value can be more than a single type. Such as when a property would be string or...
Read more >Union Type in TypeScript - TutorialsTeacher
Learn about union type in TypeScript. TypeScript allows us to use more than one data type for a variable or a function parameter....
Read more >Union Types - Scala 3 - EPFL
Union types are duals of intersection types. | is commutative: A | B is the same type as B | A . The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is fixed now, see #1483.
ok it’s because of this
Is there a reason this cannot return false?
it also messes up :
the less complex items don’t come through.