-
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 strollby/feat-schema-directive
feat: add support for schema directive
- Loading branch information
Showing
13 changed files
with
173 additions
and
25 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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .custom_directive_meta import CustomDirectiveMeta | ||
from .schema_directive import SchemaDirective | ||
|
||
__all__ = ["SchemaDirective", "CustomDirectiveMeta"] |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from dataclasses import dataclass | ||
from typing import Any, Callable, Union | ||
|
||
from graphql import DirectiveLocation as GrapheneDirectiveLocation, GraphQLDirective | ||
|
||
|
||
@dataclass | ||
class CustomDirectiveMeta: | ||
allow_all_directive_locations: bool | ||
add_definition_to_schema: bool | ||
has_no_argument: bool | ||
valid_types: set[GrapheneDirectiveLocation] | ||
non_field_types: set[GrapheneDirectiveLocation] | ||
supports_field_types: bool | ||
supports_non_field_types: bool | ||
validator: Union[Callable[[GraphQLDirective, Any], bool], None] |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from dataclasses import dataclass | ||
from typing import Any | ||
|
||
from graphql import DirectiveLocation as GrapheneDirectiveLocation | ||
from graphql import GraphQLDirective | ||
|
||
from ..exceptions import DirectiveValidationError | ||
|
||
|
||
@dataclass | ||
class SchemaDirective: | ||
target_directive: GraphQLDirective | ||
arguments: dict[str, Any] | ||
|
||
def __post_init__(self): | ||
if GrapheneDirectiveLocation.SCHEMA not in self.target_directive.locations: | ||
raise DirectiveValidationError( | ||
". ".join( | ||
[ | ||
f"{self.target_directive} cannot be used as schema directive", | ||
"Missing DirectiveLocation.SCHEMA in locations", | ||
] | ||
) | ||
) |
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
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
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 = "graphene-directives" | ||
version = "0.3.1" | ||
version = "0.3.2" | ||
packages = [{include = "graphene_directives"}] | ||
description = "Schema Directives implementation for graphene" | ||
authors = ["Strollby <[email protected]>"] | ||
|
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