GithubHelp home page GithubHelp logo

how to upload file about gql HOT 22 CLOSED

graphql-python avatar graphql-python commented on June 3, 2024 5
how to upload file

from gql.

Comments (22)

leszekhanusz avatar leszekhanusz commented on June 3, 2024 3

@leahein did you make some progress on this ? I'll have some time in the following weeks so I will maybe start to implement this myself.

from gql.

leszekhanusz avatar leszekhanusz commented on June 3, 2024 1

@leahein

Happy to work on a PR for this as well.

I think this would be a great addition to this library. I will accept your pull request in my own PR #70 if it comes with 100% test code coverage (and documentation).

Note: to create temporary files in the tests, you can use this method

You can create a test which will create a temporary text file, send this file in a mutation to the local created aiohttp server, the server will return the first line from the file.

Then another test with a mutation with a list of files which return a list of first lines.

from gql.

leahein avatar leahein commented on June 3, 2024 1

I did start on the feature here, but it's not complete.
Right now there are utils to check whether a request contains files, and I started the transformation for sending them with the requests lib.

from gql.

KingDarBoja avatar KingDarBoja commented on June 3, 2024 1

@leahein The link should be https://github.com/leahein/gql/tree/file-support :)

At the end, the base implementation to implement should be https://github.com/jaydenseric/graphql-multipart-request-spec

from gql.

leszekhanusz avatar leszekhanusz commented on June 3, 2024 1

See also #179

And to be clear, it should be possible to support file uploads with the RequestsHTTPTransport. I'll accept a PR if it is well tested.

from gql.

leszekhanusz avatar leszekhanusz commented on June 3, 2024 1

@maaft Could you please check if the PR #244 works well for you?

from gql.

leahein avatar leahein commented on June 3, 2024

I would love to know whether gql supports this, as well.

from gql.

leahein avatar leahein commented on June 3, 2024

It doesn't look like this library currently supports files. Is there any plan to support the graphql multipart request spec in the future?

Happy to work on a PR for this as well.

from gql.

KingDarBoja avatar KingDarBoja commented on June 3, 2024

@leahein the library doesn't support file uploads but there is a repo which implements that for Django and Flask servers, would be worth checking it: graphene-file-upload.

from gql.

leahein avatar leahein commented on June 3, 2024

@leahein the library doesn't support file uploads but there is a repo which implements that for Django and Flask servers, would be worth checking it: graphene-file-upload.

I was looking for file upload support for a python client that uses graphene-file-upload server-side.
I found this one that seems to support file uploads well.

from gql.

KingDarBoja avatar KingDarBoja commented on June 3, 2024

@leahein best idea would be a separated repo to support this feature as this would be a third party integration with gql library, hence making easier to maintain the core features as there aren't many contributors around here 🤔

from gql.

leszekhanusz avatar leszekhanusz commented on June 3, 2024

Now that the aiohttp transport is implemented in #70 It should be relatively easy to incorporate the implementation from aiogqlc

from gql.

leszekhanusz avatar leszekhanusz commented on June 3, 2024

@leahein

Now that #70 has been merged, if you are still interested you should create your PR directly from the repo now.

from gql.

leahein avatar leahein commented on June 3, 2024

@leszekhanusz Thanks for the details! I will work on adding file support 👍

from gql.

sreerajkksd avatar sreerajkksd commented on June 3, 2024

@leszekhanusz would you be able to implement this feature in a month or two ? I'm really looking forward to have this feature in this library.

from gql.

leszekhanusz avatar leszekhanusz commented on June 3, 2024

This is now available in release v3.0.0a3. Tests and feedback is welcome.

from gql.

maaft avatar maaft commented on June 3, 2024

Is file-upload support planned for sync transport? I cannot use async io in my application.

from gql.

leszekhanusz avatar leszekhanusz commented on June 3, 2024

@maaft
No, it is not planned. But you can use AIOHTTPTransport in a sync manner if you want.

from gql.

maaft avatar maaft commented on June 3, 2024

The issue with AIOHTTPTransport is that it creates a new session everytime you execute a query/mutation. That sounds very inefficient and also I get random "Transport is already connected" Exceptions from time to time. Might be some race conditions maybe.

from gql.

leszekhanusz avatar leszekhanusz commented on June 3, 2024

The issue with AIOHTTPTransport is that it creates a new session every time you execute a query/mutation. That sounds very inefficient

Not necessarily, you can execute multiple queries and mutations on the same session (See async usage and async advanced usage). If you want to do it synchronously, it is still possible by running loop.run_until_complete yourself like in Client::execute

and also I get random "Transport is already connected" Exceptions from time to time. Might be some race conditions maybe.

I suspect you try to execute queries from different threads or task with the same transport. If that is not the case, and if you can reproduce a minimal example, please submit an issue.

from gql.

maaft avatar maaft commented on June 3, 2024

I suspect you try to execute queries from different threads or task with the same transport. If that is not the case, and if you can reproduce a minimal example, please submit an issue.

Yes, that is indeed the case. I'm also thinking about rewriting all my code to make use of asyncio (instead of threads & processes) but unfortunately I rely on external libraries (pytorch in this case) that make heavy use of threads and processes already. And there is no way around using pytorch sadly. It's the defacto standard in machine learning. But who knows, maybe it will work just fine with asyncio. I'll have to try.

Thanks!

from gql.

maaft avatar maaft commented on June 3, 2024

@leszekhanusz yes, it works. Thank you!

from gql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.