We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
With the release of prisma 3.10.0, we now can use embedded documents via the type keyword.
type
currently the generated field resolver doesn't work, it gives Cannot read properties of undefined (reading 'fields')
Cannot read properties of undefined (reading 'fields')
example
model Account { id String @id @default(auto()) @map("_id") @db.ObjectId username String posts Post[] } type Post { title String content String }
objectType({ name: 'Post', // need to match Account.posts.type definition(t) { t.string('title') t.string('content') } }) objectType({ name: Account.$name, description: Account.$description, definition(t) { t.field(Account.username) t.field(Account.posts) } }) extendType({ type: 'Query', definition(t) { t.field('accounts', { type: list('Account'), resolve: (root, args, { prisma }) => { return prisma.account.findMany() } }) } })
this fails with
{ "errors": [ { "message": "Cannot read properties of undefined (reading 'fields')", "locations": [ { "line": 5, "column": 5 } ], "path": [ "accounts", 0, "posts" ], "extensions": { "code": "INTERNAL_SERVER_ERROR", "exception": { "stacktrace": [ "TypeError: Cannot read properties of undefined (reading 'fields')", " at applyFluent (node_modules\\@prisma\\client\\runtime\\index.js:37215:39)", " at Object.get (node_modules\\@prisma\\client\\runtime\\index.js:37229:16)", " at node_modules\\nexus-prisma\\src\\generator\\models\\javascript.ts:304:18", " at node_modules\\nexus-shield\\src\\plugin.ts:100:16" ] } } } ], "data": null }
and to fix the issue i have to override the Account.posts resolver
objectType({ name: Account.$name, description: Account.$description, definition(t) { t.field(Account.username) t.field({ ...Account.posts, resolve: (root) => { return (root as any).posts } }) } })
this works and produce the expected result
{ "data": { "accounts": [ { "username": "name", "posts": [ { "title": "t1", "content": "c1" }, { "title": "t2", "content": "c2" } ] } ] } }
The text was updated successfully, but these errors were encountered:
t.field({...Account.posts, resolve: undefined}) working too and more type safely.
Is it possible to remove the resolver for embedded documents, since it is not needed there?
Sorry, something went wrong.
No branches or pull requests
With the release of prisma 3.10.0, we now can use embedded documents via the
type
keyword.currently the generated field resolver doesn't work, it gives
Cannot read properties of undefined (reading 'fields')
example
this fails with
and to fix the issue i have to override the Account.posts resolver
this works and produce the expected result
The text was updated successfully, but these errors were encountered: