How can I create a hook, so that during an insert,...
# prisma-whats-new
e
How can I create a hook, so that during an insert, for example, a bunch of other items are initialized. For example, a user is created, so after it s crested, create a new "Organization" a new "Profile", etc. Can that be done with the functions hooks?
c
That can definitely be done. Lemme find a good example...
This is a messy example, but it's straight from the graphcool templates: https://github.com/graphcool/templates/blob/master/auth/email-password/src/signup.ts#L70
basically, within a hook, you grab an API you can send queries and mutations to, like this:
Copy code
js
const graphcool = fromEvent(event)
const api = graphcool.api('simple/v1')
then you send a mutation to it with
api.request(graphQLString, variables)
so you could just write one huge mutation that adds an Organization and Profile and whatever else, and send that to the API under an
afterOperation
hook on
operation: User.create
e
So antthing done through the api.request bypasses the permissions and executed as Admin?
Also, in order to do this, I'd have to use the Graphcool framework and can't be done just in graphcool cloud?