-
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
Add GraphQL support to UserPickerField #15389
Merged
Merged
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f35d133
Add UserPickerField
cb7bdae
Merge branch 'main' into UserPickerField
d85bc64
fix query
hyzx86 0974367
Merge branch 'UserPickerField' of https://github.com/hyzx86/OrchardCo…
1418b06
update dependency
52cc64b
Merge branch 'main' into UserPickerField
hyzx86 cd0d788
Merge branch 'main' into UserPickerField
hyzx86 c2645ae
Merge branch 'main' into UserPickerField
hyzx86 da29f40
Merge branch 'main' into UserPickerField
hyzx86 6f3a722
Merge branch 'main' into UserPickerField
hyzx86 74a2ae2
Merge branch 'main' into UserPickerField
hyzx86 e18892e
Makes the GraphQL user type reusable.
gvkries e3cc0af
Merge branch 'main' into UserPickerField
hyzx86 6c7a4cd
merge pr 15691
hyzx86 a210ba0
update with pr 15691
hyzx86 ab50f42
Merge branch 'UserPickerField' of https://github.com/hyzx86/OrchardCo…
hyzx86 dbbeb8e
Merge branch 'main' into UserPickerField
hyzx86 92cddfe
Merge branch 'main' into UserPickerField
hyzx86 0ce1bae
Merge branch 'main' into UserPickerField
Piedone c949c59
Merge branch 'main' into UserPickerField
hyzx86 7b22445
Merge branch 'main' into UserPickerField
hishamco 6adcd22
Update src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Type…
hyzx86 2d57d5d
Update src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Type…
hyzx86 7cb2e44
Merge branch 'main' into UserPickerField
hyzx86 10d3d04
fix code
3d6a459
Update src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Type…
hyzx86 5e360be
remove firstUser field
hyzx86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...ardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/UserPickerFieldQueryObjectType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using GraphQL; | ||
using GraphQL.DataLoader; | ||
using GraphQL.Types; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using OrchardCore.Apis.GraphQL; | ||
using OrchardCore.ContentFields.Fields; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.Users.GraphQL; | ||
using OrchardCore.Users.Indexes; | ||
using OrchardCore.Users.Models; | ||
using YesSql; | ||
using YesSql.Services; | ||
|
||
namespace OrchardCore.ContentFields.GraphQL | ||
{ | ||
public class UserPickerFieldQueryObjectType : ObjectGraphType<UserPickerField> | ||
{ | ||
public UserPickerFieldQueryObjectType() | ||
{ | ||
Name = nameof(UserPickerField); | ||
|
||
Field<ListGraphType<StringGraphType>, IEnumerable<string>>("userIds") | ||
.Description("user ids") | ||
.PagingArguments() | ||
.Resolve(x => | ||
Piedone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
return x.Page(x.Source.UserIds); | ||
}); | ||
|
||
Field<ListGraphType<UserType>, IEnumerable<User>>("users") | ||
.Description("the user items") | ||
.PagingArguments() | ||
.ResolveAsync(x => | ||
{ | ||
var userLoader = GetOrAddUserProfileByIdDataLoader(x); | ||
return userLoader.LoadAsync(x.Page(x.Source.UserIds)).Then(itemResultSet => | ||
{ | ||
return itemResultSet.SelectMany(x => x); | ||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); | ||
|
||
Field<UserType, User>("user") | ||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.Description("the first user") | ||
.ResolveAsync(x => | ||
{ | ||
var userLoader = GetOrAddUserProfileByIdDataLoader(x); | ||
return userLoader.LoadAsync(x.Source.UserIds.FirstOrDefault()).Then(itemResultSet => | ||
{ | ||
return itemResultSet.FirstOrDefault(); | ||
}); | ||
}); | ||
Piedone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
public static IDataLoader<string, IEnumerable<User>> GetOrAddUserProfileByIdDataLoader<T>(IResolveFieldContext<T> context) | ||
Piedone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
IDataLoaderContextAccessor requiredService = context.RequestServices.GetRequiredService<IDataLoaderContextAccessor>(); | ||
var session = context.RequestServices.GetService<ISession>(); | ||
return requiredService.Context.GetOrAddCollectionBatchLoader("GetOrAddUserByIds", async (IEnumerable<string> userIds) => | ||
{ | ||
if (userIds == null || !userIds.Any()) | ||
{ | ||
return null; | ||
Piedone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
var users = await session.Query<User, UserIndex>(y => y.UserId.IsIn(userIds)).ListAsync(); | ||
|
||
return users.ToLookup((User k) => k.UserId, (User user) => user); | ||
}); | ||
} | ||
} | ||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think all descriptions should be localizable.
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.
Done