Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request - simple interface to ask for cost, independent of graphql server #36

Open
tot-ra opened this issue Jan 7, 2020 · 0 comments

Comments

@tot-ra
Copy link

tot-ra commented Jan 7, 2020

What is the best way to ask from costAnalysis API what is the cost, without any graphql server instance?

We're resorting currently to this, but would be nice to have easy API to get the cost..

const { validate, parse, ValidationContext, TypeInfo } = require('graphql');
const costAnalysis = require('graphql-cost-analysis').default;

function getCurrentCost(query, schema, variables) {
	const queryAST = parse(query);
	const validationContext = new ValidationContext(schema, queryAST, new TypeInfo(schema));
	const costAnalyser = costAnalysis({ variables, ...costLimits })(validationContext);

	validate(schema, queryAST, [() => costAnalyser]);

	return costAnalyser.cost;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant