Skip to content

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

@tot-ra

Description

@tot-ra

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions