question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apollo upload client support

See original GitHub issue

Hi!

I’m trying to use default example from apollo-upload-client. But it doesn’t work with graphene.

The problem is - the rquest headers contains content-type: multiform-data, so parse_body from views.py returns request.POST, BUT get_graphql_params parse query only from GET request

And request contains query, but in POST…

latest-screenshot

So, my solution for apollo-upload-client is:

    @staticmethod
    def get_graphql_params(request, data):
        query = request.GET.get('query') or data.get('query')
        variables = request.GET.get('variables') or data.get('variables')
        id = request.GET.get('id') or data.get('id')

        # try to get params from POST
        if not query:
            if request.POST.get("operations"):
                parsed_post = json.loads(request.POST.get("operations"))

                if 'query' in parsed_post:
                    query = parsed_post['query']

                if 'variables' in parsed_post:
                    variables = parsed_post['variables']


        if variables and isinstance(variables, six.text_type):
            try:
                variables = json.loads(variables)
            except Exception:
                raise HttpError(HttpResponseBadRequest(
                    'Variables are invalid JSON.'))

        operation_name = request.GET.get(
            'operationName') or data.get('operationName')
        if operation_name == "null":
            operation_name = None

        return query, variables, operation_name, id

After that, all appear to be ok:

latest-screenshot

latest-screenshot

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:5

github_iconTop GitHub Comments

1reaction
Eraldocommented, Apr 2, 2018

I am also trying to get apollo-upload-client to play together with graphene-django. This issue seems related: https://stackoverflow.com/questions/48713911/apollo-upload-client-and-graphene-django

A complete example would be awesome! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

File uploads - Apollo GraphQL Docs
Apollo Client doesn't support a file upload feature out of the box. If you'd like to enable file upload capabilities, you will have...
Read more >
jaydenseric/apollo-upload-client - GitHub
GitHub - jaydenseric/apollo-upload-client: A terminating Apollo Link for Apollo Client that fetches a GraphQL multipart request if the GraphQL variables ...
Read more >
Top 5 apollo-upload-client Code Examples - Snyk
To help you get started, we've selected a few apollo-upload-client examples, based on popular ways it is used in public projects. Secure your...
Read more >
apollo-upload-client examples - CodeSandbox
Learn how to use apollo-upload-client by viewing and forking example apps that make use of apollo-upload-client on CodeSandbox.
Read more >
apollo-fetch-upload/readme.md - UNPKG
For server instructions see [`apollo-upload-server`](https://github.com/jaydenseric/apollo-upload-server). Checkout the [example API and client](https://github.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found