TransWikia.com

GraphQL using Prisma client : Cannot return null for non-nullable field

Stack Overflow Asked by bgeun on December 10, 2020

schema:

type Query {
    seeFeed: [Post!]!
}

type Post{
  id: ID!
  files: [File!]!
  location: String
  caption: String!
  user: User!
  likes: [Like!]!
  comments: [Comment!]!
  isLiked: Boolean!
  likeCount: Int!
  createdAt: String
  updatedAt: String
}

resolver(seeFeed.js):

export default {
  Query: {
    seeFeed: async (_, __, { request, isAuthenticated }) => {
      isAuthenticated(request);
      const { user } = request;
      const following = await prisma.user({ id: user.id }).following();
      return prisma.posts({
        where: {
          user: {
            id_in: [...following.map(user => user.id), user.id]
          }
        },
        orderBy: "createdAt_DESC"
      });
    }
  }
};

resolver(Post.js):

export default {
    Post: {
        isLiked: (parent,_,{request})=> {
            const {user} = request;
            const {id} = parent;
            return prisma. $exists.like({
                AND:[{
                        user:{
                            id:user.id
                        }
                    },
                    {
                        post: {
                            id
                        }
                    }
                ]
            });
        },
        likeCount : parent =>  prisma.likesConnection({
            where:{post :{id: parent.id}}
        })
        .aggregate()
        .count(),
        files  : ({id}) => prisma.post({id}).files(),
        comments  : ({id}) => prisma.post({id}).comments(),
        user  : ({id}) => prisma.post({id}).user(),
        createdAt: ({id}) => prisma.post({id}).createdAt(),
        updatedAt: ({id}) => prisma.post({id}).updatedAt()
    }
}

I want to get comments of Post. So I tried query on Prisma Playground and it gives me valid response
Request:

{
  posts{
    comments{
      id
      text
      user{
        id
        username
      }
    }
  }
}

but I tried query on my graphql server Playground, It gives me
Cannot return null for non-nullable field Comment.user.

Request:

{
  seeFeed{
    id
    comments{
      text
      user{
        username
      }
    }
    }
}

Response:

{
  "data": null,
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Comment.user.",
      "locations": [
        {
          "line": 6,
          "column": 7
        }
      ],
      "path": [
        "seeFeed",
        0,
        "comments",
        0,
        "user"
      ]
    }
  ]
}

Please help me resolve the problem..

What is problem with my resolver??

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP