DjangoObjectType attribute of type FileField should return its url
Current 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
It looks like FileField is being registered to the graphene String type. That means the value coming out of it is whatever six.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:
{
model {
fileField {
url
name
}
}
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 the FileField to a graphene.Field of the new type instead of graphene.String.
How does that sound?
@spockNinja sounds like a great idea. Moreover, it opens a way for some other things regarding images like dimensions or mime-type for any file.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Still a good idea!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Still useful feature!
If someone would like to contribute a PR to add this feature I will happily review and merge it.
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
@ulgens any update on this?
If this issue is still relevant I would be happy to work on it
If this issue is still relevant I would be happy to work on it
Yes that would be great!