How am I supposed to (re)query the object when id
is different on every load? What am I missing?
const {nodeInterface, nodeField} = nodeDefinitions(
(globalId) => {
const {type, id} = fromGlobalId(globalId);
// This id is different every time (if page is reloaded/refreshed)
// How am I suppose to use this id for database query (e.g by id)?
// How do I get "the right ID"? (ID actually used in database)
console.log('id:', id);
// This is correct: "User"
console.log('type:', type);
if (type === 'User') {
// Function that is suppose to get the user but id is useless ..
return getUserById(id);
}
return null;
},
(obj) => {
if (obj instanceof User) {
return userType;
}
return null;
}
);
const userType = new GraphQLObjectType({
name: 'User',
fields: () => ({
id: globalIdField('User'), // Relay ID
_id: { type: GraphQLString }, // MongoDB ID
email: { type: GraphQLString },
name: { type: GraphQLString }
}),
interfaces: [nodeInterface]
});