question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I 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:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
helfercommented, May 3, 2017

This is fixed now, see #1483.

0reactions
gilesbradshawcommented, Jan 6, 2017

ok it’s because of this

// XXX here we reach an issue - we don't know if this fragment should match or not. It's either:
  // 1. A fragment on a non-matching concrete type or interface or union
  // 2. A fragment on a matching interface or union
  // If it's 1, we don't want to return anything, if it's 2 we want to match. We can't tell the
  // difference, so for now, we just do our best to resolve the fragment but turn on partial data
  context.returnPartialData = true;
  return true;

Is there a reason this cannot return false?

it also messes up :

value {
          __typename
          ... on UaNull {nullValue: value}
          ... on UaLong {longValue: value}
          ... on UaLocalizedText  { localizedTextValue: value { text }}
          ... on UaLocalizedTextArray  { localizedTextValueArray: value { text }}
          
        }


the less complex items don’t come through.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found