cdelacruzzin / ClotheStation

Welcome to the Clothestation! This is an e-commerce platform, which can be used in many ways. Here it is used as a Skating Clothes Apparel. We built this project to help any business to sell and display their project in a great and polished UI. This project is our first MERN Full Stack Application built from scratch.
https://urban-sk8-ef054e6c42c1.herokuapp.com/
MIT License
1 stars 1 forks source link

fixi the "me" query #39

Open cdelacruzzin opened 1 year ago

cdelacruzzin commented 1 year ago

the type definitions and resolvers seem to be flawed

  Query: {
    me: async (parent, args, context) => {
      console.log(context.user)
      if (context.user) {
        // return User.findOne({ _id: context.user._id }).populate("products");
        return User.findOne({ _id: context.user._id });
      }

first, the ".populate('products') is trying to populate a "product field of the User schema.

const typeDefs = gql`
 user that takes id, username, email, password and products in an array
  type User {
    _id: ID!
    username: String!
    email: String!
    cartCount: Int! #items in cart at the time
    cart: [CartItem]!
  }

how we have our user schema does not have a "products" field.

there's two changes that need to be done:

  1. change return User.findOne({ _id: context.user._id }).populate("products")to fit our user schema/model.
  2. change the QUERY_ME query to correspond to how you want the user schema to return

    export const QUERY_ME = gql`
    
    query me {
    me {
      _id
      username
      email
    }
    }
    `;