VulcanJS / Vulcan-Starter

VulcanJS starter repo. Use as a base for your own VulcanJS projects.
MIT License
127 stars 88 forks source link

Step12: The loader.load() function must be called with a value,but got: undefined #12

Closed TylerL-uxai closed 4 years ago

TylerL-uxai commented 6 years ago

Following along with the tutorial and got this error on Resolvers

graphQLErrors: 
I20180201-20:30:38.883(-6)?    [ { message: 'The loader.load() function must be called with a value,but got: undefined.',
I20180201-20:30:38.883(-6)?        locations: [Array],
I20180201-20:30:38.883(-6)?        path: [Array] },

Modified (uncommented) code

  userId: {
    type: String,
    optional: true,
    viewableBy: ['guests'],
    /*

    Uncomment on #Step12:

    */
    resolveAs: {
      fieldName: 'user',
      type: 'User',
      resolver: async (movie, args, context) => {
        return await context.Users.loader.load(movie.userId);
      },
      addOriginalField: true,
    },
  },

import { registerFragment } from 'meteor/vulcan:core';

registerFragment(`
  fragment MoviesFragment on Movie {
    _id
    createdAt
    nam
    user{
      displayName
    }
  }
`);

Here's the query from meteor mongo:


meteor:PRIMARY> db.users.find()
{ "_id" : "XsFRxEe2sAw6Cw8We", "username" : "Bruce", "email" : "dummyuser1@telescopeapp.org", "isDummy" : true, "createdAt" : ISODate("2018-02-02T01:25:35.445Z"), "isAdmin" : false, "displayName" : "Bruce", "emailHash" : "088d8d939171c84420aaf7b6f1f86e6d", "slug" : "bruce" }
{ "_id" : "szrABDzdgpa4bgmAP", "username" : "Arnold", "email" : "dummyuser2@telescopeapp.org", "isDummy" : true, "createdAt" : ISODate("2018-02-02T01:25:35.445Z"), "isAdmin" : false, "displayName" : "Arnold", "emailHash" : "48812ccbe08c11454379039a622ec52c", "slug" : "arnold" }
{ "_id" : "oFxgZN7cTPXGxTTZ8", "username" : "Julia", "email" : "dummyuser3@telescopeapp.org", "isDummy" : true, "createdAt" : ISODate("2018-02-02T01:25:35.445Z"), "isAdmin" : false, "displayName" : "Julia", "emailHash" : "5879e4b77176de7563f5b8a5451728c8", "slug" : "julia" }

Update:

After debugging, I found the line that's causing the program to crash return await context.Users.loader.load(movie.userId);

TylerL-uxai commented 6 years ago

Seeding movies is called before the dummy users are created (async type error)


const createDummyUsers = function () {
  console.log('// seeding users…');
  createUser('Bruce', 'dummyuser1@telescopeapp.org');
  createUser('Arnold', 'dummyuser2@telescopeapp.org');
  createUser('Julia', 'dummyuser3@telescopeapp.org');
};

export const seedMovies = () => {

  const allUsers = Users.find().fetch();

  if (allUsers.length === 0) {
    createDummyUsers();
  }
  if (Movies.find().fetch().length === 0) {
    console.log('// seeding movies…');
SachaG commented 6 years ago

Oh right, see also https://github.com/VulcanJS/Vulcan/pull/1849

Let me know if it's fixed now.

TylerL-uxai commented 6 years ago

Trying to merge, but it's in a different repo (VulcanJs instead of Vulcan-Starter)

SachaG commented 6 years ago

Oh sorry, I meant I fixed it here: https://github.com/VulcanJS/Vulcan-Starter/commit/c0166f9fb29acefb293c9e2bada95d358b815885

TylerL-uxai commented 6 years ago

Check out step 12 with the dummy data. userId still isn't being added, but you did fix the async.

return await context.Users.loader.load(movie.userId); //movie.userId === undefined

SachaG commented 6 years ago

OK, got it. I was missing a return statement! Should work now :)

efficienthacks commented 6 years ago

I googled around and found this because I was getting the same error...

Already tried replacing the /getting-started/lib/server/seed.js file with the one at c0166f9

Then I went to the meteor shell to call seedMovies(), but I'm still getting the error..

How would I fix this (without reinstalling the whole thing). Any suggestions? Thanks

SachaG commented 6 years ago

@efficienthacks you would also need to add the code from here: https://github.com/VulcanJS/Vulcan-Starter/commit/8f944b33fbc437c807682d3bf587fc25b6d6df97

Or you could git pull the repo to get the latest version.

eric-burel commented 4 years ago

Closed as resolved