torchbox / wagtail-grapple

A Wagtail app that makes building GraphQL endpoints a breeze!
https://wagtail-grapple.readthedocs.io/en/latest/
Other
152 stars 57 forks source link

Add `url` field to `DocumentObjectType` #94

Closed tbrlpld closed 4 years ago

tbrlpld commented 4 years ago

I know you guys probably pretty busy, but I just wanted to drop this feature request for future updates 😉

Currently the DocumentObjectType provides the following fields:

id: ID
title: String
file: String
createdAt: DateTime
fileSize: Int
fileHash: String

The file field resolves to some path like string like "documents/example.pdf". Now to actually generate a link where I can access the document I need to pull the Wagtail GraphQL enpoint from the plugin options, trim it to the base URL (domain) and then add the correct media URL and then add the value from the file field.

While this certainly works, it seems fragile and introduces some coupling between the frontend and backend. Anytime the backend might have a different media URL I would need to update that in the frontend (code or configuration).

The ImageObjectType provides similar fields as the DocumentObjectType and many other fileds. One of them is the src field. This is a valid URL under which the respective image can be accessed. It would be great to add the same filed to the DocumentObjectType 😊

Since the document model already provides a url proptery just like the image model, I guess the same approach as for the ImageObjectType.src could be used for the DocumentObjectType.src.

IAmNatch commented 4 years ago

@zerolab I put through a PR for this. Let me know if there's anything that you'd like me to adjust.

tbrlpld commented 4 years ago

Me too ^^ #95

zerolab commented 4 years ago

Let's go with url for the full URL, and leave file to maintain the relative path (as per https://github.com/GrappleGQL/wagtail-grapple/pull/96#issuecomment-674950403)

tbrlpld commented 4 years ago

PR #95 has been updated accordingly.