Created
February 23, 2021 12:51
-
-
Save molebox/be0b5255e09fea675e8b207b8d8f8a21 to your computer and use it in GitHub Desktop.
Nexus objectType error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// schema | |
model Company { | |
id Int @id @default(autoincrement()) | |
name String | |
trades Trade[] | |
} | |
model Trade { | |
id Int @id @default(autoincrement()) | |
name String | |
company Company @relation(fields: [companyId], references: [id]) | |
companyId Int | |
} | |
// nexus | |
export const Company = objectType({ | |
name: 'Company', | |
definition(t) { | |
t.nonNull.int('id') | |
t.nonNull.string('name') | |
t.nonNull.list.nonNull.field('trades', { | |
type: 'Trade', | |
resolve: (parent, _, ctx) => { | |
return ctx.db.company.findUnique({ | |
where: {id: parent.id} | |
}).trades() | |
} | |
}); | |
} | |
}) | |
export const Trade = objectType({ | |
name: 'Trade', | |
definition(t) { | |
t.nonNull.int('id') | |
t.nonNull.string('name') | |
t.nonNull.field('company', { | |
type: 'Company', | |
resolve: (parent, _, ctx) => { // <----------------error on resolve | |
return ctx.db.trade.findUnique({ | |
where: {id: parent.id} | |
}).company() | |
} | |
}) | |
} | |
}) | |
// Error: Type 'Company | null' is not assignable to type ..... | |
// So this must have something to do with me stating its nonNull right? but according to the nexus docs it should be nonNull |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment