Skip to content

Commit

Permalink
chore: update rustberry to v0.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
erikwrede committed May 18, 2024
1 parent a5beaf1 commit 384d281
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
22 changes: 11 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ libcst = {version = ">=0.4.7", optional = true}
rich = {version = ">=12.0.0", optional = true}
pyinstrument = {version = ">=4.0.0", optional = true}
graphlib_backport = {version = "*", python = "<3.9", optional = true}
rustberry = {version = "^0.0.9", python= ">=3.11"}
rustberry = {version = "^0.0.10", python= ">=3.11"}

[tool.poetry.group.dev.dependencies]
asgiref = "^3.2"
Expand Down
22 changes: 10 additions & 12 deletions strawberry/schema/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,29 @@
from strawberry.types.execution import ExecutionContext, Executor

if TYPE_CHECKING:
from rustberry._rustberry import FileId
from rustberry._rustberry import Document


RUSTBERRY_FILE_ID_FIELD = "__rustberry_file_id"
RUSTBERRY_DOCUMENT_FIELD = "__rustberry_document"


class RustberryExecutor(Executor):
def __init__(self, schema: Schema):
def __init__(self, schema: Schema) -> None:
super().__init__(schema)
self.compiler = QueryCompiler()
self.compiler.set_schema(schema.as_str())
self.compiler = QueryCompiler(schema.as_str())

def parse(self, execution_context: ExecutionContext) -> None:
file_id = self.compiler.add_executable(execution_context.query)
setattr(execution_context, RUSTBERRY_FILE_ID_FIELD, file_id)
execution_context.graphql_document = self.compiler.gql_core_ast_mirror(file_id)
document = self.compiler.parse(execution_context.query)
setattr(execution_context, RUSTBERRY_DOCUMENT_FIELD, document)
execution_context.graphql_document = self.compiler.gql_core_ast_mirror(document)

def validate(
self,
execution_context: ExecutionContext,
) -> None:
assert execution_context.graphql_document
file_id: FileId = getattr(execution_context, RUSTBERRY_FILE_ID_FIELD, None)
assert file_id, "File ID not set - Required for Rustberry use"
validation_successful = self.compiler.validate_file(file_id)
document: Document = getattr(execution_context, RUSTBERRY_DOCUMENT_FIELD, None)
assert document, "Document not set - Required for Rustberry use"
validation_successful = self.compiler.validate(document)
if not validation_successful:
execution_context.errors = execution_context.errors or []
execution_context.errors.append(GraphQLError("Validation failed"))

Check warning on line 35 in strawberry/schema/executors.py

View check run for this annotation

Codecov / codecov/patch

strawberry/schema/executors.py#L34-L35

Added lines #L34 - L35 were not covered by tests

0 comments on commit 384d281

Please sign in to comment.