0

for example:

"""
A user device
"""
type device @model { 
  id: ID!
  statusID: Int!
  devFunctionIDs: [Int]!
  functions: [devFunction] @connection(fields: ["devFunctionIDs"])  
}

"""
A function or feature of a device
"""
type devFunction @model {
  id: Int!
  functionName: String!
}

In this situation I have an array of Int which correlate to functions. The array of Int's are compiled by user. A device can have many features/functions on it. I want to get all the associated function objects.

Please excuse my inexperience on this topic as I am very new to Graphql. The error I get tells me that I need to use a non-null scalar. (an array of scalars I guess doesn't count) The error message doesn't offer alternative solutions, or give me much to go on for searching up a proper way to do this.

Can anyone point me in the right direction?

ChrisW
  • 1
  • 2

1 Answers1

0

Try using “[Int!]!” instead of “[Int]!” for the “devFunctionIDs” field return type. As it stands (i.e., without the ! inside the brackets), you’re expressing that the list itself cannot be null, but could contain null values. Thus, the following would still satisfy the constraint: [1, 2, null, 4]. With the revised implementation, neither the list itself, nor any of its values, can be null. This should do the trick.

That said, there are some more idiomatic approaches to connecting data with Amplify that, depending on your use case, might prove advantageous. Right now, I can’t tell whether you envision a “one-to-many” or “many-to-many” relationship between the two types above. To me, assuming that a device can have multiple functions and each function might be associated with multiple devices, a “many-to-many” relationship seems in order. If you want to edit your question to expound on the above, I’ll gladly sketch out a suggestion for you. In the meantime, you should check out the docs here: https://docs.amplify.aws/cli/graphql-transformer/connection

Michael Edelman
  • 306
  • 1
  • 6