1
votes

I have a type defined as Device on my Prisma server

type Device {
  id: ID! @unique
  type: DeviceType
  settings: Json
}

On my Gateway however I'd like to resolve the field settings to an actual union type

# import Node from './generated/prisma.graphql'

type MobileSettings {
  firmware: String
}

type DesktopSettings {
  os: String
}

union Settings = MobileSettings | DesktopSettings

type Device implements Node {
  id: ID!
  type: DeviceType
  settings: Json
}

type Query {
  devices: [Device]
  node(id: ID!): Node
}

If I add a custom resolver on the Device.settings field, the initial query to get all devices still tries to retrieve the settings field.

How can I resolve the Json field into an actual union type?

1

1 Answers

0
votes

I think you forgot to use the Settings type in your schema:

# import Node from './generated/prisma.graphql'

type MobileSettings {
  firmware: String
}

type DesktopSettings {
  os: String
}

union Settings = MobileSettings | DesktopSettings

type Device implements Node {
  id: ID!
  type: DeviceType
  settings: Settings # <-- Here
}

type Query {
  devices: [Device]
  node(id: ID!): Node
}