Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142239

Empty array is returned when attempting to access the fields in the relational Type

$
0
0

I currently have the Prisma datamodel as following:

type User {
  id: ID! @id
  username: String!
  email: String! @unique
  password: String
  friends: [Friend] @relation(name: "FriendToUser", onDelete: CASCADE) 
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}

And I also have a type that is linked to User through the friends field:

type Friend {
  id: ID! @id
  user: User! @relation(name: "FriendToUser", onDelete: SET_NULL) 
  friend: User! @relation(name: "FriendToUser2")
  areFriends: Boolean! @default(value: false)
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}

I'm trying to access the type Friend through User, but the query keeps telling me that the information doesn't exist when the information in fact exists.

My schema:

 user(id: ID!): User

My query:

query User($id: ID!){
  user(
    id: $id
  ){
    email
    friends {
      areFriends
    }
  }
}

When I checked the query resolver in the back end server:

const result = await prisma.query.user({
            where: {
                id,
            }
        }, info)

all the other fields from User shows properly, but the information from Friend show up empty.

More specifically, when I log the result in the back end, an empty array is returned for the friends field.

{ email: 'some@email.com',
  friends: [],
  __typename: 'User' }

Viewing all articles
Browse latest Browse all 142239

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>