-
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.
- Loading branch information
0 parents
commit bb0152a
Showing
5 changed files
with
122 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
.venv/ | ||
**/__pycache__ | ||
|
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,22 @@ | ||
|
||
|
||
from fastapi import FastAPI | ||
import strawberry | ||
from strawberry.schema_directive import Location | ||
from strawberry.fastapi import GraphQLRouter | ||
|
||
@strawberry.schema_directive(locations=[Location.FIELD_DEFINITION]) | ||
class TestDirective: pass | ||
|
||
@strawberry.type | ||
class Query: | ||
@strawberry.field(directives=[TestDirective()]) | ||
def test() -> str: | ||
return "Test" | ||
|
||
schema = strawberry.Schema(Query) | ||
|
||
router = GraphQLRouter(schema, prefix='/graphql', graphql_ide="apollo-sandbox") | ||
app = FastAPI() | ||
app.include_router(router) | ||
|
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,48 @@ | ||
|
||
import traceback | ||
from typing import Callable | ||
from strawberry.cli.utils import load_schema | ||
from strawberry.printer import print_schema | ||
|
||
DIRECTIVE_NAMES_QUERY = 'query { __schema { directives { name } } }' | ||
|
||
def test_field_directive_schema_export(): | ||
schema_symbol = load_schema("field_directive:schema", ".") | ||
output = print_schema(schema_symbol) | ||
assert "testDirective" in output | ||
|
||
def test_one_of_schema_export(): | ||
schema_symbol = load_schema("one_of_directive:schema", ".") | ||
output = print_schema(schema_symbol) | ||
assert "oneOf" in output | ||
|
||
def test_field_directive_introspection(): | ||
from field_directive import schema | ||
result = schema.execute_sync(DIRECTIVE_NAMES_QUERY) | ||
directives = { directive['name'] for directive in result.data['__schema']['directives'] } | ||
assert "testDirective" in directives | ||
|
||
def test_one_of_introspection(): | ||
from one_of_directive import schema | ||
result = schema.execute_sync(DIRECTIVE_NAMES_QUERY) | ||
directives = { directive['name'] for directive in result.data['__schema']['directives'] } | ||
assert "oneOf" in directives | ||
|
||
|
||
def run_test(test: Callable): | ||
print("\n" + test.__name__.replace('_', ' ') + ": ", end="") | ||
try: | ||
test() | ||
print("PASS") | ||
except: | ||
print("FAIL") | ||
traceback.print_exc() | ||
|
||
def run_tests(): | ||
run_test(test_field_directive_schema_export) | ||
run_test(test_one_of_schema_export) | ||
run_test(test_field_directive_introspection) | ||
run_test(test_one_of_introspection) | ||
|
||
if __name__ == '__main__': | ||
run_tests() |
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,23 @@ | ||
|
||
|
||
from fastapi import FastAPI | ||
import strawberry | ||
from strawberry.fastapi import GraphQLRouter | ||
|
||
@strawberry.input(one_of=True) | ||
class TestInput: | ||
a: str | None = strawberry.UNSET | ||
b: str | None = strawberry.UNSET | ||
|
||
@strawberry.type | ||
class Query: | ||
@strawberry.field | ||
def test(x: TestInput) -> str: | ||
return "Test" | ||
|
||
schema = strawberry.Schema(Query) | ||
|
||
router = GraphQLRouter(schema, prefix='/graphql', graphql_ide="apollo-sandbox") | ||
app = FastAPI() | ||
app.include_router(router) | ||
|
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,25 @@ | ||
annotated-types==0.7.0 | ||
anyio==4.6.0 | ||
click==8.1.7 | ||
fastapi==0.115.0 | ||
graphql-core==3.2.4 | ||
h11==0.14.0 | ||
idna==3.10 | ||
libcst==1.4.0 | ||
markdown-it-py==3.0.0 | ||
mdurl==0.1.2 | ||
pydantic==2.9.2 | ||
pydantic_core==2.23.4 | ||
Pygments==2.18.0 | ||
python-dateutil==2.9.0.post0 | ||
python-multipart==0.0.10 | ||
PyYAML==6.0.2 | ||
rich==13.8.1 | ||
shellingham==1.5.4 | ||
six==1.16.0 | ||
sniffio==1.3.1 | ||
starlette==0.38.6 | ||
strawberry-graphql==0.243.1 | ||
typer==0.12.5 | ||
typing_extensions==4.12.2 | ||
uvicorn==0.30.6 |