I’m looking for a little help on implementing reso...
# orm-help
b
I’m looking for a little help on implementing resolvers. Can anyone walk me through it. Context: I’ve done the howtographql.com node.js tutorial and would like to add fetch, update, and delete.
n
can you describe your situation in more detail? 🙂 what exactly are you trying to do?
b
I’m simply trying to add the ability to find a link by the ID, update a Link, or delete a Link from the hackernews tutorial
I’m assuming it’s trivial and if someone can walk me through adding 1 more I’ll be able to deduce the rest.
n
you need to follow these steps
1) add the query to
schema.graphql
2) create a new, empty resolver somewhere and import it into the GraphQL server (probably in
index.js
. You can compare this to how other resolvers end up being there. 3) In the still empty resolver, use
prisma-binding
to implement your logic.
Example -
feed
query
b
this advanced server repo should help me get there 🙂 thanks nilan
👌 1
@nilan quick question: If I have a type user that has a key posts:
Copy code
type User {
  id: ID!
  name: String!
  email: String!
  posts: [Link!]!
}
and a resolver that looks like this:
Copy code
async function user(parent, { id }, ctx, info) {
  return ctx.db.query.user({ where: { id } }, info)
}
should the
Posts
be populated “magically” or do I need to write a query in the resolver to grab the posts where the user ID matches?
a
Yes. The posts will be there (assuming the query actually asks for the users posts). That's the magic of passing the "info" argument as the second argument to all those prisma-binding methods.
💡 1
b
ah okay I figured. so something must be wrong
a
Got some code you could share such as a GitHub repo? I'll be back in ten and I'd be happy to look.
b
sure I’ve forked off of the how2graphql tutorials and am just adding features. I’ll push to github and send you an invite. can i get your username?
a
andrewjmead
b
sweet 🙂 thanks!
user
I think the issue may be that my types are different between
schema.graphql
and
datamodel.graphql
a
We chatted in a PM. For future reference, there was an inconsistency between the schema for the Node server and the Prisma schema. The Prisma server didn't have "posts" in the schema while the Node server did. That's why no data was coming back when calling the prisma-binding method and passing in info.
b
yep! if you are having an issue where the graph ql magic isn’t happening make sure your schema and datamodel line up
👍 1