-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Checho3388/allow-introspection
Allow introspection
- Loading branch information
Showing
13 changed files
with
315 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "graphql_complexity" | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
description = "A python library that provides complexity calculation helpers for GraphQL" | ||
authors = ["Checho3388 <[email protected]>"] | ||
packages = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
from .complexity import get_complexity | ||
from .complexity import ( | ||
get_ast_complexity, | ||
get_complexity, | ||
) | ||
|
||
__all__ = [ | ||
'get_complexity', | ||
'get_ast_complexity' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
from graphql import parse, visit | ||
from graphql import parse, visit, TypeInfo, TypeInfoVisitor, GraphQLSchema | ||
|
||
from ..estimators import ComplexityEstimator | ||
from .visitor import ComplexityVisitor | ||
from ..estimators import ComplexityEstimator | ||
|
||
|
||
def get_complexity(query: str, estimator: ComplexityEstimator) -> int: | ||
def get_complexity(query: str, schema: GraphQLSchema, estimator: ComplexityEstimator) -> int: | ||
"""Calculate the complexity of a query using the provided estimator.""" | ||
ast = parse(query) | ||
return get_ast_complexity(ast, estimator=estimator) | ||
return get_ast_complexity(ast, schema=schema, estimator=estimator) | ||
|
||
|
||
def get_ast_complexity(ast, estimator: ComplexityEstimator) -> int: | ||
def get_ast_complexity(ast, schema: GraphQLSchema, estimator: ComplexityEstimator) -> int: | ||
"""Calculate the complexity of a query using the provided estimator.""" | ||
visitor = ComplexityVisitor(estimator=estimator) | ||
visit(ast, visitor) | ||
type_info = TypeInfo(schema) | ||
|
||
visitor = ComplexityVisitor(estimator=estimator, type_info=type_info) | ||
visit(ast, TypeInfoVisitor(type_info, visitor)) | ||
|
||
return visitor.evaluate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.