Apollo error: "Connector must be a function or an class"? - FIXED


#1

I have a function that makes a one-off GraphQL query:

getUserInfoForCurrentUser() {
    const userIsLoggedIn = Meteor.userId() ? true : false;
    if ((userIsLoggedIn) && (this.originatingUser == null)) {
        const localThis = this;
        const userID = Meteor.userId();
        this.client.query({
            query: GET_USERINFOFORIMS_QUERY,
            variables: {userID: userID},
        }).then((result) => {
            localThis.originatingUser = result.data.getUserData[0];
        });
    }
}

I’m getting a console error:

Uncaught (in promise) Error: GraphQL error: Connector must be a function or an class

How can I correct this?

Thanks in advance to all for any info.

UPDATE
I just tried it like this in GraphIQL:

query ($userID: String!) {
  getUserData(id: $userID) {
    name_first
    name_last
    picture_thumbnail
    id
}
}

//query variables:
{
  "userID": "DsmkoaYPeAumREsqC"
}

…and got this via GraphIQL:

{
  "data": {
    "getUserData": null
  },
  "errors": [
    {
      "message": "Connector must be a function or an class",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "getUserData"
      ]
    }
  ]
}

Here’s my resolver:

getUserData(_, args) {
	debugger; <== NEVER ACTIVATES
	return Promise.resolve()
		.then(() => {
			console.log('In getUserData');
			var Users = connectors.UserData.findAll({where: args}).then((Users) => Users.map((item) => item.dataValues));
			return Users;
		})
		.then(Users => {
			return Users;
		})
		.catch((err)=> {
			console.log(err);
		});
},

The debugger breakpoint in the resolver never activates.

I don’t yet know what GraphIQL means by a “connector”. What needs to be changed?


#2

Fixed! I had to remove the reference to connectors from my call to makeExecutableSchema, and add it in to:

server.use('/graphql', bodyParser.json(), graphqlExpress({
    schema,
    context: {
        connectors: connectors
    }
}));

Then I could retrieve it in the resolver like so:

getUserData: (root, args, context) => {
    return Promise.resolve()
        .then(() => {
            var Users = context.connectors.UserData.findAll({where: args}).then((Users) => Users.map((item) => item.dataValues));
            return Users;
        })
        .then(Users => {
            return Users;
        })
        .catch((err)=> {
            console.log(err);
        });
},

Thanks to @marcusnielsen on Apollo Slack for the tip that helped me find this!