-
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 #10 from Checho3388/9-consider-__typename-as-metaf…
…ield-with-0-complexity 9 consider typename as metafield with 0 complexity
- Loading branch information
Showing
4 changed files
with
32 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "graphql_complexity" | ||
version = "0.3.1" | ||
version = "0.3.2" | ||
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,18 +1,32 @@ | ||
from typing import Any | ||
|
||
from graphql import DirectiveNode, FieldNode, VariableNode | ||
from graphql import ( | ||
DirectiveNode, | ||
FieldNode, | ||
VariableNode, | ||
get_named_type, | ||
is_introspection_type, | ||
) | ||
|
||
|
||
def get_node_argument_value(node: FieldNode | DirectiveNode, arg_name: str, variables: dict[str, Any]) -> Any: | ||
"""Returns the value of the argument given by parameter.""" | ||
arg = next( | ||
(arg for arg in node.arguments if arg.name.value == arg_name), | ||
None | ||
) | ||
arg = next((arg for arg in node.arguments if arg.name.value == arg_name), None) | ||
if not arg: | ||
raise ValueError(f"Value for {arg_name!r} not found in {node.name.value!r} arguments") | ||
|
||
if isinstance(arg.value, VariableNode): | ||
return variables.get(arg.value.name.value) | ||
|
||
return arg.value.value | ||
|
||
|
||
def is_meta_type(type_, node) -> bool: | ||
"""Check if the field is a meta field.""" | ||
unwrapped_type = get_named_type(type_) | ||
return any( | ||
( | ||
unwrapped_type is not None and is_introspection_type(unwrapped_type), | ||
unwrapped_type is not None and node.name.value == "__typename", | ||
) | ||
) |
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