-
Notifications
You must be signed in to change notification settings - Fork 45
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
Create multiple objectTypes from same prisma model #160
Comments
Maybe we need a new helper method. import { User } from 'nexus-prisma'
export const UserObjectType = objectType({
name: 'User',
definition(t) {
t.field(User.id);
t.field(User.name);
},
});
export const SecretUserObjectType = objectType({
name: 'SecretUser',
definition(t) {
t.field(User.$as('SecretUser').id);
t.field(User.$as('SecretUser').name);
t.field(User.$as('SecretUser').secretValue);
},
}) Or maybe a top level function: import { User } from 'nexus-prisma'
export const UserObjectType = User.$objectType({
definition(t) {
t.model.id()
t.model.name()
},
});
export const SecretUserObjectType = User.$objectType({
name: 'SecretUser',
definition(t) {
t.model.id()
t.model.name()
t.model.secretValue()
},
}) Or maybe generator config: import { settings } from 'nexus-prisma/generator'
settings({
modelAliases: {
SecretUser: 'User',
}
}) import { User, SecretUser } from 'nexus-prisma';
export const UserObjectType = objectType({
name: 'User',
definition(t) {
t.field(User.id);
t.field(User.name);
},
});
export const SecretUserObjectType = objectType({
name: 'SecretUser',
definition(t) {
t.field(SecretUser.id);
t.field(SecretUser.name);
t.field(SecretUser.secretValue);
},
}); |
@0xsven Did you manage to implement this with a workaround? |
@alainfonhof we are still using the old plugin ( |
I was able to make this work by using export const ProjectModel = objectType({
name: "Project",
definition(_t) {
const t = _t as unknown as ObjectDefinitionBlock<"Task">
t.field(Task.id)
t.field(Task.title)
|
@jasonkuhrt the ideas looks good, does one of them are being developed? |
Perceived Problem
I feel the need to create multiple
objectType
s from the same prisma model.Example:
This would give me the following type error:
Type 'FieldResolver<"User", "id">' is not assignable to type 'FieldResolver<"SecretUser", "id">'.
Ideas / Proposed Solution(s)
It would be great if the types would allow this.
The text was updated successfully, but these errors were encountered: