Hey :wave: I'm trying to query relational data, if...
# orm-help
b
Hey 👋 I'm trying to query relational data, if I query either I get "Cannot return null for non-nullable field Query.post/user"
Copy code
User: {
        posts(parent) {
          return prisma.user({ id: parent.id }).posts();
        },
      },
      Post: {
        user(parent) {
          return <http://prisma.post|prisma.post>({ id: parent.id }).user();
        },
      },
Any help would be highly appreciated
n
Did you implement the resolvers for the
post
and
user
on the
Query
type? Can you maybe share your full resolver implementation?
b
These are my Query resolvers:
Copy code
me(parent, args, ctx, info) {
    console.log(ctx.request.userId);

    if (!ctx.request.userId) return null;

    const user = ctx.db.query.user({ where: { id: ctx.request.userId }, info });
    console.log(user);
    return user;
  },

  async users(parent, args, ctx, info) {
    if (!ctx.request.userId) throw new Error('You must be logged in');

    await hasPermission(ctx.request.user, ['ADMIN']);

    return ctx.db.query.users({}, info);
  },

  debates(parent, args, ctx, info) {
    return ctx.db.query.debates({}, info);
  },
@nikolasburk
Has anyone queried relation data before? Help needed.
h
Are you using prisma-client or prisma-binding?
n
Hey @Benjamin Sampson, from the code you posted it seems like you're using a mix of Prisma client and Prisma bindings. In the code you posted, the
User
and
Post
resolvers are using the client, in the
me
,
users
and
debates
resolvers you're using Prisma bindings. Is this intentional? 🙂 If no, I'd recommend using only the client in your resolvers.
This will likely also solve your problem your then.
b
Any way to do this using only Prisma bindings?
Sorry I'm very new to Prisma and CMS in general
Fixed! I was forgetting to put
info
in my mutations
👍 1