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

multipart_uploads_enabled not propagated in AsyncGraphQLView, causing file uploads to fail #3713

Open
BranDavidSebastian opened this issue Nov 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@BranDavidSebastian
Copy link

BranDavidSebastian commented Nov 29, 2024

Describe the Bug

In strawberry-graphql==0.253.0 and strawberry-graphql-django==0.50.0, setting multipart_uploads_enabled=True in the AsyncGraphQLView does not enable multipart uploads as expected. The self.multipart_uploads_enabled attribute remains False, causing file uploads via multipart/form-data to fail with a 400 Bad Request error.

To Reproduce

  1. Configure the GraphQL view in Django:
path(
    'graphql/',
    AsyncGraphQLView.as_view(
        schema=schema,
        graphiql=settings.DEBUG,
        multipart_uploads_enabled=True,
    ),
    name='graphql',
),
  1. Attempt to perform a file upload mutation from the client.

Example cURL Command:

curl -X POST -H "Content-Type: multipart/form-data" \
  -F 'operations={"query":"mutation createImages($data: [ImageInput!]!) { createImages(data: $data) { id imageWebUrl }}","variables":{"data":[{"image":null,"imageType":"PACK"}]}}' \
  -F 'map={"0":["variables.data.0.image"]}' \
  -F '0=@/path/to/logo.png' \
  http://localhost:8080/graphql
  1. Observe that the server responds with a 400 Bad Request error stating "Unsupported content type".
  2. Inspect the self.multipart_uploads_enabled attribute inside the AsyncGraphQLView and find that it is False.

Expected Behavior

Setting multipart_uploads_enabled=True should set self.multipart_uploads_enabled to True in the AsyncGraphQLView, enabling multipart uploads and allowing file uploads to work correctly.

Actual Behavior

Despite setting multipart_uploads_enabled=True, self.multipart_uploads_enabled remains False, causing the server to reject multipart/form-data requests.

Additional Context

  • This issue did not occur in previous versions:
  • strawberry-graphql==0.219.1
  • strawberry-graphql-django==0.32.1
  • According to the documentation:
  • The issue seems to be that multipart_uploads_enabled is not properly propagated to the AsyncGraphQLView instance.

If I force it to True in this method everthing works fine:

    async def parse_http_body(
        self, request: AsyncHTTPRequestAdapter
    ) -> GraphQLRequestData:
        headers = {key.lower(): value for key, value in request.headers.items()}
        content_type, _ = parse_content_type(request.content_type or "")
        accept = headers.get("accept", "")

        protocol: Literal["http", "multipart-subscription"] = "http"
        if self._is_multipart_subscriptions(*parse_content_type(accept)):
            protocol = "multipart-subscription"

        if request.method == "GET":
            data = self.parse_query_params(request.query_params)
        elif "application/json" in content_type:
            data = self.parse_json(await request.get_body())
        elif self.multipart_uploads_enabled and content_type == "multipart/form-data":
            data = await self.parse_multipart(request)
        else:
            raise HTTPException(400, "Unsupported content type")

        return GraphQLRequestData(
            query=data.get("query"),
            variables=data.get("variables"),
            operation_name=data.get("operationName"),
            protocol=protocol,
        )

Question

Am I misconfiguring something, or is this a bug in strawberry-graphql? Any guidance on how to fix or work around this issue would be appreciated.

@BranDavidSebastian BranDavidSebastian added the bug Something isn't working label Nov 29, 2024
@patrick91 patrick91 transferred this issue from strawberry-graphql/strawberry-django Nov 30, 2024
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

No branches or pull requests

1 participant