-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved MediaField Graphql support #15003
Conversation
src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs
Outdated
Show resolved
Hide resolved
…eryObjectType.cs Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
…into mediaFileNames
Hi @hishamco , I adjusted the type structure of the media file fields and increased the collection of file list objects |
src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs
Outdated
Show resolved
Hide resolved
…eryObjectType.cs Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
This pull request has merge conflicts. Please resolve those before requesting a review. |
Fix the conflict |
I'm not sure if we should add the full url as it is relative to the current tenant context. Normally, the html or javascript asset you are using should define if you need a relative or absolute path to these files. The GraphQL query becomes opiniated on the URL by generating it while the path could be different from 2 different contexts. Here, what I suggest is that you create a small javascript function that returns the tenantPath instead if you are using this inside a Vue.js app for example. The JSON structure though that you used is better than what we did. I think it should have been simply: "attachments": [ And in Razor there is a helper method AssetUrl. |
@Skrypt , Sorry, I don't quite understand what you mean, you mean that I should use But the sad thing is that, as you said, it takes the absolute path relative to the current site, not the absolute path of the tenant, |
What I mean is that adding the absolute URL to the GraphQL query doesn't make sense because it is redundant as it will always return the same protocol//domain/basepath for each of these medias. What you want is to get these from other services and use it in your javascript application instead. Also, adding this redundant path to the Query also makes the data size to be bigger for nothing. |
No, no, because the media files may be stored on Azure or some other server that is not consistent with the current server path, I think it is necessary to return the full path here. The current url format is strange: There is no problem using this path in mvc scenarios, but if you need to specify the server address in separate clients, At this point we also need to save another media file root path? It is currently used in my client application // Note that path is used here, not url
var imgUrl = serviceRoot+'/media'+path; |
You then need 2 things. Inject the ShellSettings like this in your Layout.cshtml file to always have the tenantId available for your javascript applications. @using OrchardCore.Environment.Shell
@inject ShellSettings ShellSettings
@{
var tenantId = ShellSettings.TenantId;
}
<body data-tenant-id="@tenantId"> Inject your fileProvider service and with the same technique add for example a "data-media-base-host" attribute that you will be able to use. |
Hi @Skrypt , I'm talking about the SPA /mobile application usage scenario where we're calling the oc api remotely, not just pages in the oc site's domain |
Then you/we can write an ApiController that will return these. That would really make more sense as also this tenant id will be required if you use something like NSwag studio to generate your proxy client for consuming these API's. It always needs a tenant id context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR adds support to retrieve the public URL of a Media file. I argued above that this is good and also necessary. I don't think that aspect needs to change.
src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs
Outdated
Show resolved
Hide resolved
return x.Page(x.Source.Paths); | ||
}); | ||
|
||
Field<ListGraphType<StringGraphType>, IEnumerable<string>>("fileNames") | ||
.Description("the media fileNames") | ||
.Description("the media file names") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this now redundant and can be deprecated? (But kept for now for backward compatibility.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second that. It would be great if we can remove the old redundant fields. It's a breaking change, but we already have lot's of them, so why not take this as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think it's a good time to remove them in 2.0.
@Skrypt what do you think? Or remove them in a new PR?
src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs
Outdated
Show resolved
Hide resolved
…eryObjectType.cs Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs
Show resolved
Hide resolved
src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs
Outdated
Show resolved
Hide resolved
When you're done addressing all feedback of a review, click "Re-request review" in the top-right corner for each reviewer when you're ready for another round of review, so they know that you're done. |
…6490) --------- Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
…into mediaFileNames
To simplify data binding for front-end single-page applications, add file objects