Comments (2)
Graphene does support file uploads, but it's a matter of the underlying web view (for example graphene Django, starlette-graphene3, GraphQL-server) to support them. What's your stack? If you're able to provide a minimal example I might be able to help.
from graphene.
In reality if you google this topic extensively, you'll notice that there are a number of ways to tackle it.
In the example below, the path we've chosen is to stick to graphql only and used graphene-file-upload.
That graphene-file-upload package supports file transfers. By now, it seems that it hasn't received any updates in a couple of years. But if something would break, I can imagine it will be easy enough to fork and fix.
This very minimal example below is how I tackled the mutation a couple of years ago with that package. It's not intended to work out of the box, it's just a simplified snippet from a codebase in one of our projects at Tweave.tech
from graphene_file_upload.scalars import Upload
import graphene
from .validators import your_file_validator
class CreateFile(graphene.Mutation):
file = graphene.Field(FileType, required=False)
class Arguments:
filename = graphene.String(required=True)
filecontents = Upload(required=True)
@staticmethod
def mutate(root, info, filename, filecontents, *args, **kwargs):
user = info.context.user
file_instance = File()
file_instance.file.save(filename, ContentFile(filecontents.file.read()), save=False)
try:
your_file_validator(file_instance.file)
file_instance.save()
return CreateFile(file=file_instance)
except ValidationError:
return CreateFile(file=None)
from graphene.
Related Issues (20)
- Thanks for Thanks for GraphQL Python Roadmap HOT 1
- Leading white spaces in description casuing issues HOT 1
- `graphql_schema` introspection doesn't output docstrings descriptions
- InputObjectType causing encoding issues with JSONField HOT 1
- @include and @skip directives lead to irrelevant errors HOT 2
- Provide a way to configure default timezone of DateTimes HOT 3
- Turning Non-null to is_null HOT 3
- Enum conversion to Graphene Enum fails if Enum name is "type" HOT 1
- Enum equality comparison is inconsistent
- http://www.graphene-python.org Has EXPIRED HOT 3
- Unexpected argument in Pycharm 2023.2.1 HOT 1
- Default_value option in Arguments inside Mutation is not working as expected HOT 2
- Exception: NonNull could not have a mounted String() as inner type. Try with NonNull(String).
- Returning non fatal errors alongside data
- Conversion to snake_case fails on nested inputs
- Depth limit validator key error if fragment undefined
- Tests in `graphene/relay/tests/test_custom_global_id.py` fail due incompatibility with pytest 8.x HOT 1
- Enum.from_enum() fails with Django IntegerChoices
- Do you support GQL over websocket? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphene.