what is the recommended way to programmatically up...
# orm-help
v
what is the recommended way to programmatically update the database from the server? Can you call mutations from javascript / Node? Or somehow use code similar to what is in the resolver functions?
l
Resolvers are just functions, so if you export the function, any part of the server can call it. You could also use the Prisma binding directly in any part of the server.
v
@lawjolla Thanks. I get that resolvers are just functions. So is accepted practice to call the resolvers and pass in the parent / args / context / info args args as needed? That is the part I was wondering about
Does the prisma binding mean something like "context.db.mutation.createUser"? If so those are the two options I had thought about. Was wondering about best practices for code organization, and how other people manage this
l
I don't know that I've seen an accepted use case. I think it depends on your use case. What I've done is if my resolver's core function is also needed by the server, I'll make a function out of the resolver's logic and call that from the resolver and my server
That will avoid the context/info/etc issues you mentioned
Yes, that's the Prisma binding. I define the binding outside of the server context (and pass it into the server) but also export it so I can import it into server functions
v
Gotcha. Factoring out common functionality and calling it from the resolver and server is also what I was thinking about. That seems like the right approach I think
l
It's worked well for me. You'll end up passing the prisma binding (
db
) into the abstracted function
v
that makes sense. So you define "let db = new Prisma..." and then pass that db into "new GraphQLServer" and then also hang on to the db object for calling in your server otherwise
l
Exactly right
v
cool. Also are you using typescript by any chance? I'm trying to figure out how to get auto-complete happening for the bindings
l
I'm not, sorry. Dynamic types 4 life. 🙂 Someday I need to learn it!
v
haha
sounds good, thank you! I like it 🙂
💯 1
l
I know it's a dirty word, but Webstorm/IntelliJ does a nice job with binding autocomplete and vanilla js
v
@lawjolla that's cool