graphene-django icon indicating copy to clipboard operation
graphene-django copied to clipboard

DjangoObjectType attribute of type FileField should return its url

Open lig opened this issue 8 years ago • 13 comments

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

lig avatar Aug 17 '17 17:08 lig

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 avatar Sep 09 '17 04:09 spockNinja

@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.

lig avatar Sep 09 '17 22:09 lig

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.

stale[bot] avatar Jun 11 '19 11:06 stale[bot]

Still a good idea!

nikolaik avatar Jun 11 '19 12:06 nikolaik

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.

stale[bot] avatar Aug 10 '19 12:08 stale[bot]

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.

stale[bot] avatar Oct 11 '19 18:10 stale[bot]

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.

stale[bot] avatar Jan 12 '20 08:01 stale[bot]

Still useful feature!

javiercornejo avatar Mar 27 '20 18:03 javiercornejo

If someone would like to contribute a PR to add this feature I will happily review and merge it.

jkimbo avatar Apr 01 '20 14:04 jkimbo

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.

stale[bot] avatar Aug 27 '20 00:08 stale[bot]

@ulgens any update on this?

hashlash avatar Sep 04 '20 15:09 hashlash

If this issue is still relevant I would be happy to work on it

ghost avatar Apr 29 '23 10:04 ghost

If this issue is still relevant I would be happy to work on it

Yes that would be great!

firaskafri avatar Apr 29 '23 12:04 firaskafri