This might be an accidental duplicate of #3125. It may also be me rather than the lib at fault as the documentation on Operation directives is very limited (already left feedback for that in the proper place).
It seems that the inclusion of a directive in...well, anything is enough to throw an error when exporting the schema.
MRE:
import strawberry
from strawberry.directive import DirectiveLocation
@strawberry.directive(locations=[DirectiveLocation.FIELD_DEFINITION])
def turn_uppercase(value: str):
return value.upper()
@strawberry.type
class Message:
body: str
@strawberry.type
class Query:
@strawberry.field(directives=[turn_uppercase])
def send_message(self) -> Message:
return Message(body="Hello world!")
schema = strawberry.federation.Schema(
query=Query,
types=[Message],
enable_federation_2=True,
)
Passing the directive to strawberry.type
for Message
also triggers it. There's a directives
argument to Schema
, but it's undocumented. It expects Sequence[Type]
, notably not Sequence[StrawberryDirective]
-- is that in some way related to this problem?
I'm guessing by the traceback below I'm not supposed be passing a StrawberryDirective
though to directives
, but if not, what?
Traceback:
Traceback (most recent call last):
File "/app/serverless-clone/node_modules/serverless-wsgi/wsgi_handler.py", line 43, in import_app
wsgi_module = importlib.import_module(wsgi_fqn_parts[-1])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/app/serverless-clone/server.py", line 4, in <module>
from app import create_app
File "/app/serverless-clone/app.py", line 6, in <module>
from urls import auth_blueprint
File "/app/serverless-clone/urls.py", line 2, in <module>
from sgql import schema
File "/app/serverless-clone/sgql.py", line 42, in <module>
schema = strawberry.federation.Schema(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/strawberry/federation/schema.py", line 91, in __init__
composed_directives = self._add_compose_directives()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/strawberry/federation/schema.py", line 319, in _add_compose_directives
definition = directive.__strawberry_directive__ # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'StrawberryDirective' object has no attribute '__strawberry_directive__'
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too