0

I wrote simple GraphQL schemas and resolvers in studying purpose, and I could not get reason why my codes work as expected. I used Prisma for ORM, and express-graphql and graphql-import to compose the API.

type User {
  id: ID!
  name: String!
}

type Link {
  id: ID!
  url: String!
  user: User!
}

type Query {
  links(id: ID!): [Link!]!
}
// resolvers
const links = async (root, args, ctx) => {
  const links = await ctx.prisma.links({
    where: {
      user {
        id: args.id
      }
    }
  }
}
// resolver for `Link` type
const user = async (root, args, ctx) => {
  const user = await ctx.prisma.link({ id: parent.id }).user()
  return user
}

// omitted field resolver for `url` and `id`
module.exports = {
  user
}

With these codes, I expected to get id, url, user fields when I query links, but when I send the query, it returns null with user field. Which means, if I check in the server-side, the resolver for user field does not invoked at all. What is wrong with this?

cadenzah
  • 928
  • 3
  • 10
  • 23

0 Answers0