저는 graphql을 처음 사용하고 express가있는 GraphQL 서버가 있습니다. 컨텍스트 값에서 createdBy 필드를 설정하려고합니다. 아래와 같이 userId를 전달하고 있습니다.
app.use('/graphql', auth, userAuthCheck, graphlHTTP(req => ({
schema: schema,
graphiql: true,
context: {
userId: req.user._Id,
},
})));
인증을 확인하기 위해 이와 같은 해결 프로그램이 있습니다.
const checkAuth = (resolve, source, args, context, info) => {
if (context.userId) {
return resolve(source, args, context, info);
}
throw new Error('You must be authorized');
};
graphql-compose-mongoose를 사용하여 돌연변이 함수를 만듭니다.
리졸버는 인증을 올바르게 검증합니다. eventCreateOne : EventTC.getResolver ( 'createOne', [checkAuth]),
이벤트를 만들 때 컨텍스트의 값으로 createdBy 필드를 설정하고 싶습니다. 어떻게해야합니까? 이 시나리오를 처리하는 모범 사례를 알고 싶습니다.
미리 감사드립니다.
이것이 제가 문제를 해결 한 방법입니다.
const checkAuth = (resolve, source, args, context, info) => {
if (context.userId) {
args.record.createdBy = context.user._id;
return resolve(source, args, context, info);
}
throw new Error('You must be authorized');
};
값을 올바르게 삽입 한 다음 해석기에 전달하기 전에 단순히 args를 업데이트했습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다