मैं रिले और ग्राफक्यूएल का प्रयास कर रहा हूं। जब मैं स्कीमा कर रहा हूँ मैं यह कर रहा हूं:रिले/ग्राफक्यूएल 'संकल्प' कैसे काम करता है?
let articleQLO = new GraphQLObjectType({
name: 'Article',
description: 'An article',
fields:() => ({
_id: globalIdField('Article'),
title: {
type: GraphQLString,
description: 'The title of the article',
resolve: (article) => article.getTitle(),
},
author: {
type: userConnection,
description: 'The author of the article',
resolve: (article) => article.getAuthor(),
},
}),
interfaces: [nodeInterface],
})
तो, जब मैं इस तरह एक लेख के लिए पूछना:
{
article(id: 1) {
id,
title,
author
}
}
यह 3 प्रश्नों डेटाबेस के लिए क्या करेंगे? मेरा मतलब है, प्रत्येक फ़ील्ड में एक हल करने की विधि है (getTitle, getAuthor ...) जो डेटाबेस के लिए अनुरोध करता है। क्या मैं यह गलत कर रहा हूँ?
articleSchema.methods.getAuthor = function(id){
let article = this.model('Article').findOne({_id: id})
return article.author
}