A quesion about nexusjs with the prisma plugin: S...
# orm-help
s
A quesion about nexusjs with the prisma plugin: Say I have the following schema:
Copy code
model User {
  id                    String   @id @default(cuid())
  username              String
  createdAt             DateTime @default(now())
  updatedAt             DateTime @updatedAt
  groups                Group[]
}

enum Group {
  ADMIN
  RADIUS
}
I am able to assign multiple enum values to a user using the api or studio, however I am unsure of how to handle this in nexus. Seems as though I need a definition for Group, but don't know what fields I need.
l
You can use the
set
field, e.g.
Copy code
prisma.user.create({
  data: {
    // Rest
    groups: { set: ['ADMIN', 'OTHER'] }
  }
})
Just be careful, if you use
set
in an update, all the previpous roles will be overridden
s
I get that I can do that with the prisma-client-js api, but this is with nexusjs i.e.
Copy code
import { schema } from 'nexus'

schema.objectType({
  name: 'Group',
  definition(t) {
    t.model...
  },
})
but nexus doesnt seem to like definitions for enums
l
That's the new nexus already, so I can't say for sure whether the api changed, but in the original version enums got picked up either by the prisma plugin, or you could define them with a
schema.enumType()
s
@luhagel Not really getting anywhere: tried:
Copy code
schema.enumType({
  name: 'Group',
  members: {
    ADMIN: String,
    RADIUS: String,
  },
})
but upon querying I get
Expected a value of type \"Group\" but received: \"ADMIN\"
l
Give me 5 min to look some stuff up 👍
s
thanks a lot
FIXED IT!
Copy code
schema.enumType({
  name: 'Group',
  members: ['ADMIN', 'RADIUS'],
})
docs are out of date
l
oh my
s
but a huge thanks for your help, you put me onto the enumtype property, which the docs just refers to as enum
l
No worries, happy coding!
s
thanks!