asynchronous nodeDefinitions?
tanekim88 opened this issue · 3 comments
tanekim88 commented
I am trying to get nodeDefinitions work asynchronously. Does this work? According to the definition of nodeDefinitions function, it does not seem it is designed to return a promise. But would await nodeDefinitions work?
How do people resolve this issue, when database is fetched asynchronously, like await db.findOne({ id });?
const { nodeInterface, nodeField } = await nodeDefinitions(
async (globalId) => {
const { type, id } = fromGlobalId(globalId);
const foundEntity = await db.findOne({ id });
// return {id}
return foundEntity;
},
(obj) => {
return GraphQLUser;
},
);
sibelius commented
this is async
async (globalId) => {
const { type, id } = fromGlobalId(globalId);
const foundEntity = await db.findOne({ id });
// return {id}
return foundEntity;
},
the nodeDefinition does not need to be
tanekim88 commented
Thanks! Also, is there a way to change the default id key to _id? I am using mongodb, and it uses _id as key.
what I am trying to do is: const { type, _id } = fromGlobalId(globalId);
sibelius commented
Use idFetcher, check code