Prisma 1 Forum

Query returns null when query to the Prisma server works

My query returns as they should except for the posts field, which returns null. If I were to run the query from the playground local:4466, which is directly to the Prisma server, the posts field works perfectly fine, but not from local:4000, which is from the local server.

My schema.graphql:

type Query {
    me: User
}

type User {
    posts: [Post!]
}

type Post {
    author: User!
}

My generated prisma.graphl

type User implements Node {
  posts(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Post!]
}

type Post implements Node {
  author: User!
}

type Query {
  user(where: UserWhereUniqueInput!): User
}

My datamodel.graphql:

type User {
  posts: [Post!] @relation(name: "PostToUser", onDelete: CASCADE)
}

type Post {
  author: User! @relation(name: "PostToUser", onDelete: SET_NULL)
}

And my resolver:

me(parent, args, { prisma, request }, info) {
    const userId = getUserId(request)
    return prisma.query.user({
        where: {
            id: userId
        }
    })
}

Since you’re using Prisma bindings, try to return ‘info’ like this:

me(parent, args, { prisma, request }, info) {
const userId = getUserId(request)
return prisma.query.user({
      where: {
        id: userId
      },
      info
    });
}
1 Like

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.