Skip to content
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

Merged
merged 29 commits into from
Aug 8, 2024
Merged
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c3c2d82
Add media filenames on MediaFieldType
hyzx86 Jan 6, 2024
7fdfddd
add MediaFileItemType
hyzx86 Jan 7, 2024
78f1585
Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQu…
hyzx86 Jan 7, 2024
b3c1484
fix code style
hyzx86 Jan 7, 2024
e2402c8
Merge branch 'mediaFileNames' of https://github.com/hyzx86/OrchardCor…
hyzx86 Jan 7, 2024
778a472
Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQu…
hyzx86 Jan 10, 2024
4381d1a
Merge branch 'main' into mediaFileNames
hishamco Jan 10, 2024
1190a6f
merge main
hyzx86 Feb 18, 2024
f24484d
fix new graphql API
hyzx86 Feb 18, 2024
7ae8e52
merge main
hyzx86 Feb 19, 2024
eb41064
Merge branch 'main' into mediaFileNames
hyzx86 Mar 16, 2024
efcdb83
Merge branch 'main' into mediaFileNames
hyzx86 Mar 23, 2024
7b5c76d
Merge branch 'main' into mediaFileNames
hyzx86 Apr 2, 2024
e7d7e34
Merge branch 'main' into mediaFileNames
hyzx86 Jul 2, 2024
8c9c2b6
add MediaText
Jul 2, 2024
f14109a
remove empty line
Jul 2, 2024
f069176
Merge branch 'main' into mediaFileNames
hyzx86 Jul 24, 2024
4df8497
Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQu…
MikeAlhayek Jul 24, 2024
528c6d8
Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQu…
MikeAlhayek Jul 24, 2024
868c1f7
Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQu…
MikeAlhayek Jul 24, 2024
a01632b
Update MediaFieldQueryObjectType.cs
hyzx86 Jul 25, 2024
912616c
Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQu…
hyzx86 Jul 25, 2024
4f11c4f
Merge branch 'main' into mediaFileNames
hyzx86 Jul 29, 2024
de11ba8
Handle invalid recipe files from breaking the harvester (#16490)
MikeAlhayek Jul 26, 2024
9df8f05
Add RemovePart<TPart> extension (#16491)
MikeAlhayek Jul 26, 2024
8366a89
Move Media Permissions to Media.Core (#16493)
MikeAlhayek Jul 26, 2024
3c99705
Fix that you can't add a content part when it's already added as a Na…
lampersky Jul 26, 2024
6ea02df
Add CanHandleModelAsync (#16501)
MikeAlhayek Jul 28, 2024
e18beee
Merge branch 'mediaFileNames' of https://github.com/hyzx86/OrchardCor…
Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ public MediaFieldQueryObjectType()
{
return Array.Empty<string>();
}

return x.Page(x.Source.Paths);
});

Field<ListGraphType<StringGraphType>, IEnumerable<string>>("fileNames")
.Description("the media fileNames")
.Description("the media file names")
Copy link
Member

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

Copy link
Contributor

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

Copy link
Contributor Author

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?

.PagingArguments()
.Resolve(x =>
{
Expand All @@ -50,9 +51,40 @@ public MediaFieldQueryObjectType()
}
var paths = x.Page(x.Source.Paths);
var mediaFileStore = x.RequestServices.GetService<IMediaFileStore>();

return paths.Select(p => mediaFileStore.MapPathToPublicUrl(p));
});

Field<ListGraphType<MediaFileItemType>, IEnumerable<MediaFileItem>>("files")
.Description("the files of the media items")
.PagingArguments()
.Resolve(x =>
{
if (x.Source?.Paths is null)
{
return [];
}

var paths = x.Page(x.Source.Paths).ToArray();
var mediaFileStore = x.RequestServices.GetService<IMediaFileStore>();
var urls = paths.Select(p => mediaFileStore.MapPathToPublicUrl(p)).ToArray();
var fileNames = x.Page(x.Source?.GetAttachedFileNames()).ToArray();
var items = new List<MediaFileItem>();
var mediaTexts = x.Source?.MediaTexts ?? [];
for (int i = 0; i < paths.Length; i++)
{
items.Add(new MediaFileItem
{
Path = paths[i],
FileName = fileNames.Length > i ? fileNames[i] : string.Empty,
Url = urls.Length > i ? urls[i] : string.Empty,
MediaText = mediaTexts.Length > i ? mediaTexts[i] : string.Empty,
});
}

return items;
});

Field<ListGraphType<StringGraphType>, IEnumerable<string>>("mediatexts")
.Description("the media texts")
.PagingArguments()
Expand All @@ -66,4 +98,23 @@ public MediaFieldQueryObjectType()
});
}
}

public sealed class MediaFileItemType : ObjectGraphType<MediaFileItem>
{
public MediaFileItemType()
{
Field<StringGraphType>("fileName").Description("the file name of the media file item").Resolve(x => x.Source.FileName);
Field<StringGraphType>("path").Description("the path of the media file item").Resolve(x => x.Source.Path);
Field<StringGraphType>("url").Description("the url name of the media file item").Resolve(x => x.Source.Url);
hyzx86 marked this conversation as resolved.
Show resolved Hide resolved
Field<StringGraphType>("mediaText").Description("the media text of the file item").Resolve(x => x.Source.MediaText );
hyzx86 marked this conversation as resolved.
Show resolved Hide resolved
}
}

public sealed class MediaFileItem
{
public string FileName { get; set; }
public string Path { get; set; }
public string Url { get; set; }
public string MediaText { get; set; }
}
}