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

Map model ID fields to GraphQL ID types #807

Open
jasonkuhrt opened this issue Aug 27, 2020 · 1 comment
Open

Map model ID fields to GraphQL ID types #807

jasonkuhrt opened this issue Aug 27, 2020 · 1 comment
Labels
type/feat Add a new capability or enhance an existing one

Comments

@jasonkuhrt
Copy link
Contributor

Currently the following id fields map to String types in GraphQL Schema. But they should instead map to ID types instead.

model A {
  id String @id @default(uuid())
}

model B {
  id String @id @default(cuid())
}
@Albert-Gao
Copy link

Good to hear, I am currently using an interfaceType for these basic fields:

import { schema } from 'nexus'

schema.interfaceType({
  name: 'IdAndDates',
  definition(t) {
    t.id('id', {
      nullable: false,
      resolve: (root) => root.id,
    })
    t.date('createdAt', {
      nullable: false,
      resolve: (root) => root.createdAt,
    })
    t.date('updatedAt', {
      nullable: false,
      resolve: (root) => root.updatedAt,
    })

    t.resolveType(() => null)
  },
})

@jasonkuhrt jasonkuhrt added the type/feat Add a new capability or enhance an existing one label Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feat Add a new capability or enhance an existing one
Projects
None yet
Development

No branches or pull requests

2 participants