Hello ! So I noticed that all resolvers created in...
# orm-help
p
Hello ! So I noticed that all resolvers created in the API schema with names identical to those in the Prisma schema are automatically forwarded to Prisma. Is this documented anywhere?
n
do you have a code example?
p
Sure, what would you like to see?
n
the resolver implementation
p
For example, here’s a part of `schema.graphql`:
Copy code
type Mutation {
  signUp(idToken: String!): User
  verifyEmail(idToken: String!): User @isAuthenticated(checkIfEmailIsVerified: false)
  deleteMe: User @isAuthenticated

  createEvent(data: EventCreateInput!): Event! @hasRole(roles: ["ADMIN, ORGANIZER"])
  attendEvent(id: ID!, code: String): Event! @isAuthenticated
}
In my resolver implementation, I skipped
createEvent
entirely
I can however call it successfully still
Which led me to believe it was automatically forwarded to Prisma
n
when starting the server, are you not getting an error about the missing resolver implementation?
p
Do you mean this:
Copy code
Type "Node" is missing a "resolveType" resolver. Pass false into "resolverValidationOptions.requireResolversForResolveType" to disable this warning.
That’s the only “warning” I’m getting. No errors.
n
no
p
Nope, no errors, even after restarting server
Actually, not the above warning anymore either!
n
I just started a test project, with a
posts: Post
resolver. I also receive no error. But when I send a
posts
query, I immediately get the result
null
. No additional query is sent anywhere.
I added a mutation
createPost(data: PostCreateInput!): Post!
. When I execute it, I get this
p
Ok I see… so when I removed the
@hasRole(roles: ["ADMIN, ORGANIZER"])
part (which throws an error at the directive resolver level, it still goes through, but gives the following error:
n
Copy code
{
  "data": null,
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Mutation.createPost.",
      "locations": [
        {
          "line": 14,
          "column": 3
        }
      ],
      "path": [
        "createPost"
      ]
    }
  ]
}
p
Precisely
n
so, nothing is send to Prisma 🙂 it just returns
null
p
I see, so I should use
forwardTo
in this case, right?
n
if that's what you need 🙂
personally, I prefer to implement the mutation right away, because I will eventually need to adjust it anyway
p
Do you think so? I really find myself needing some of those “auto-created” Prisma functions often, usually for ADMIN roles
n
Copy code
createPost(parent, { isPublished, title, text }, context: Context, info) {
      return context.db.mutation.createPost(
        { data: { isPublished, title, text } },
        info,
      )
    },
(TypeScript)
ah, you use directives for permission logic
yea, makes sense
p
I do. I know that you’re planning on a graphql-middleware solution, but I have no idea when that would be released
n
you can track #graphql-middleware 🙂
👍 2
there'll be an update soon
💚 1