DjangoObjectType attribute of type FileField should return its url
See original GitHub issueCurrent behavior is to return file name for FileField
and ImageField
type attributes of graphene_django.types.DjangoObjectType
.
It seems completely unusable as we always need an actual url of the file or image on a client.
Thus the one is forced to implement something like the following for every FileField
:
class CompanyNode(types.DjangoObjectType):
logo = graphene.String()
class Meta:
model = models.Company
interfaces = (relay.Node,)
def resolve_logo(self, args, context, info):
return self.logo and self.logo.url
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Queries & ObjectTypes - Graphene-Python
By default, DjangoObjectType will present all fields on a Model through GraphQL. If you only want a subset of fields to be present,...
Read more >how to add a custom field that is not present in database in ...
Graphene uses Types to resolve nodes, which are not at all tied to the model, you can even define a Graphene Type which...
Read more >Django model data types and fields list - GeeksforGeeks
Fields in Django are the data types to store a particular type of ... ImageField, It inherits all attributes and methods from FileField, ......
Read more >Create a Modern Application with Django and Vue – Part Three
First, we need to setup a URL pattern to serve the GraphQL APIs. ... from blog import models # Define type class SiteType(DjangoObjectType): ......
Read more >Create a Modern Application with Django and Vue #2
First, we need to setup a URL pattern to serve the GraphQL APIs. ... models # Define type class SiteType(DjangoObjectType): class Meta: model...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It looks like
FileField
is being registered to the grapheneString
type. That means the value coming out of it is whateversix.text_type(value)
will spit out when called with the file field instance. And that looks to be eventually coming from the django.core.files.base.File class.So all that being said… I think ideally, we’d get something where you could pull whichever attributes off the file that you would need. Something like:
I’m not too sure on the implementation details, but I’m thinking we would just need to implement a new
class FileType(graphene.ObjectType)
that would then be used to map theFileField
to agraphene.Field
of the new type instead ofgraphene.String
.How does that sound?
If someone would like to contribute a PR to add this feature I will happily review and merge it.