Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support projecting enums #16

Closed
jasonkuhrt opened this issue Mar 16, 2021 · 3 comments · Fixed by #18
Closed

Support projecting enums #16

jasonkuhrt opened this issue Mar 16, 2021 · 3 comments · Fixed by #18
Assignees
Labels
enum Related to Prisma & Nexus enum type type/feat Add a new capability or enhance an existing one
Milestone

Comments

@jasonkuhrt
Copy link
Contributor

Perceived Problem

It is currently not possible to project enums from Prisma schema into the the GraphQL API.

Example:

enum ProjectRole {
  admin
  developer
  collaborator
  viewer
}
enumType({
  name: 'ProjectRole',
  members: ['admin', 'developer', 'collaborator', 'viewer'],
})

Ideas / Proposed Solution(s)

Generate representations of Prisma Schema enums.

import { ProjectRole } from 'nexus-prisma'

ProjectRole.name // 'ProjectRole'
ProjectRole.members // ['admin', 'developer', 'collaborator', 'viewer']

enumType(ProjectRole),

It might also be handy to have access to some of the individual pieces of data.

import { ProjectRole } from 'nexus-prisma/data'

ProjectRole.admin           // 'admin'
ProjectRole.developer       // 'developer'
ProjectRole.collaborator    // 'collaborator'
ProjectRole.viewer          // 'viewer'

Similarly it might be handy to have access to the types:

import type { ProjectRole } from 'nexus-prisma/types'

type a = ProjectRole.Admin           // 'admin'
type b = ProjectRole.Developer       // 'developer'
type c = ProjectRole.Collaborator    // 'collaborator'
type d = ProjectRole.Viewer          // 'viewer'

type z = ProjectRole.$Members        //  ProjectRole.Admin | ProjectRole.Developer | ProjectRole.Collaborator | ProjectRole.Viewer
@jasonkuhrt jasonkuhrt added type/feat Add a new capability or enhance an existing one enum Related to Prisma & Nexus enum type labels Mar 16, 2021
@jasonkuhrt jasonkuhrt self-assigned this Mar 17, 2021
jasonkuhrt added a commit that referenced this issue Mar 18, 2021
closes #16

- [ ] default JSDoc for an enum when non is defined in the prisma schema
- [ ] tests covering default JSDoc
- [ ] documentation
@jasonkuhrt
Copy link
Contributor Author

It might also be handy to have access to some of the individual pieces of data.
Similarly it might be handy to have access to the types:

Did not do this for now. Revisit once we have a concrete use-case.

@martzoukos martzoukos added this to the 2.20.0 milestone Mar 23, 2021
@kidqueb
Copy link

kidqueb commented Apr 19, 2021

This solution doesn't cover all use cases and lacks some features available in enumType but overall has been working out ok for me thus far. Figured I'd drop it here incase others come across this looking for a quick hacky fix.

import { Prisma } from ".prisma/client";
import { enumType } from "nexus";

export const enumTypes = Prisma.dmmf.datamodel.enums.map((e) => {
  return enumType({
    name: e.name,
    members: e.values,
  });
});

@jasonkuhrt
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enum Related to Prisma & Nexus enum type type/feat Add a new capability or enhance an existing one
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants