does creating new schema affect performance in every functional call?

Why I am have to do this? because the docs returns based on data I am passing to db.

No, that’s not a reason to create a new schema on every call.

You should create a static schema that uses a resolver which takes the docs from the rootvalue that can be passed with every graphql query execute()ion.


In your case, you actually don’t even need that. Instead of running doOperations for the whole endpoint, you should run it inside the resolver that produces the users and make data an argument:

const RootQueryType = GraphQLObjectType({
    name: "RootQuery",
    fields: {   
        users: {
            type: GraphQLList(UserType),
            args: {
                filter: {
                    type: GraphQLList(ConditionType),
                },
            },
            resolve(_, {filter}) {
                return doOperations(filter, 'multiValueSearch');
            }
        }
    }

});

const schema = new GraphQLSchema({
    query: RootQueryType
});


app.post('/',  (req, res)=> {
    const {query, variables} = req.body;
    graphql(schema, query, null, {}, variables).then(result => {
        res.json(result);
    }, err => {
        console.error(err);
        res.status(500).json({error: 'A problem occurred.'});
    });
});

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top