Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload type not being correctly converted into Sanic File type at runtime #3750

Open
Maypher opened this issue Jan 9, 2025 · 0 comments · May be fixed by #3751
Open

Upload type not being correctly converted into Sanic File type at runtime #3750

Maypher opened this issue Jan 9, 2025 · 0 comments · May be fixed by #3751
Labels
bug Something isn't working

Comments

@Maypher
Copy link

Maypher commented Jan 9, 2025

Describe the Bug

According to the docs "Uploads can be used in mutations via the Upload scalar. The type passed at runtime depends on the integration"

  • AIOHTTP | io.BytesIO
  • Sanic | sanic.request.File

Using the Sanic framework I register the view provided by strawberry

from strawberry.sanic.views import GraphQLView

class AuthGraphQLView(GraphQLView):
    decorators = [login_required] if environ.get("BUILD_TARGET") != "dev" else None

    async def get_context(
        self, request: AdminRequest, response: TemporalResponse
    ) -> GraphQLContext:
        return {
            "request": request,
            "response": response,
            "resource_manager": request.app.ctx.resource_manager,
        }


graphql_blueprint = Blueprint("graphql", url_prefix="/graphql")


graphql_blueprint.add_route(
    AuthGraphQLView.as_view(
        schema=Schema(query=Query, mutation=Mutation),
        graphql_ide="graphiql",
        multipart_uploads_enabled=True,
    ),
    "/",
)

And then I have the mutation endpoint

@strawberry.mutation()
    def createImage(
        self,
        info: strawberry.Info[GraphQLContext],
        image: typing.Annotated[
            strawberry.file_uploads.Upload,
            strawberry.argument(description="The image file to upload."),
        ],
    ) -> schemas.Image:
        logger.debug(type(image)) # DEBUG: <class '_io.BytesIO'>
        return info.context["resource_manager"].create_image(image)

By this point the file should be of type sanic.request.File but it's io.BytesIO so it seems it's getting treated as if the server is AIOHTTP.

System Information

  • Operating system: Debian (Python official Docker image)
  • Strawberry version (if applicable): ^0.254.0
@Maypher Maypher added the bug Something isn't working label Jan 9, 2025
@bellini666 bellini666 linked a pull request Jan 12, 2025 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant