I have a very simple setup. Express-GraphQL API with MongoDB database. MongoDB responses are in general quite fast but when I would like to return from GrapQL API, TTFB is taking too long especially for multi-user queries.
For example, when I request a user, TTFB is 25.65 ms and content download is around 0.6 ms. But when I request all users with same fields TTFB is 4.32s and content download is around 1.28s.
Content download is no problem but I feel like TTFB is longer than it should be. You can check part of my Schema with RootQuery below.
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
user: {
type: UserType,
args: {mail: {type: GraphQLString}},
resolve(parent, args){
return User.findOne({mail: args.mail});
}
},
users: {
type: new GraphQLList(UserType),
resolve(parent,args){
return User.find({}).collation({ locale: "en" }).sort({name: 1, surname: 1});
}
}
}
});
What would be the best way to decrease TTFB?