Esempio n. 1
0
        private static IFieldResolver ResolveAsync <T>(NamedId <DomainId> appId, NamedId <DomainId> schemaId, Func <IResolveFieldContext, ContentCommand> action)
        {
            return(Resolvers.Async <object, T>(async(source, fieldContext, context) =>
            {
                try
                {
                    var command = action(fieldContext);

                    command.AppId = appId;
                    command.SchemaId = schemaId;
                    command.ExpectedVersion = fieldContext.GetArgument("expectedVersion", EtagVersion.Any);

                    var commandContext = await context.CommandBus.PublishAsync(command);

                    return commandContext.Result <T>();
                }
                catch (ValidationException ex)
                {
                    fieldContext.Errors.Add(new ExecutionError(ex.Message));

                    throw;
                }
                catch (DomainException ex)
                {
                    fieldContext.Errors.Add(new ExecutionError(ex.Message));

                    throw;
                }
            }));
        }
Esempio n. 2
0
            public static IFieldResolver Query(DomainId schemaId)
            {
                var schemaIdValue = schemaId.ToString();

                return(Resolvers.Async <object, object>(async(_, fieldContext, context) =>
                {
                    var query = fieldContext.BuildODataQuery();

                    return await context.QueryContentsAsync(schemaIdValue, query);
                }));
            }
Esempio n. 3
0
            public static IFieldResolver Referencing(DomainId schemaId)
            {
                var schemaIdValue = schemaId.ToString();

                return(Resolvers.Async <IContentEntity, object?>(async(source, fieldContext, context) =>
                {
                    var query = fieldContext.BuildODataQuery();

                    var contentId = source.Id;

                    return await context.QueryReferencingContentsAsync(schemaIdValue, query, source.Id);
                }));
            }
Esempio n. 4
0
            public static IFieldResolver Resolver(DomainId schemaId)
            {
                var schemaIdValue = schemaId.ToString();

                return(Resolvers.Async <object, object?>(async(_, fieldContext, context) =>
                {
                    var contentId = fieldContext.GetArgument <DomainId>("id");

                    var version = fieldContext.GetArgument <int?>("version");

                    if (version >= 0)
                    {
                        return await context.FindContentAsync(schemaIdValue, contentId, version.Value);
                    }
                    else
                    {
                        return await context.FindContentAsync(contentId);
                    }
                }));
            }
Esempio n. 5
0
 private static IFieldResolver ResolveUser <TSource>(Func <TSource, RefToken> resolver)
 {
     return(Resolvers.Async <TSource, IUser?>((source, fieldContext, context) => context.FindUserAsync(resolver(source), fieldContext.CancellationToken)));
 }
Esempio n. 6
0
 private static IFieldResolver ResolveUser <TSource>(Func <TSource, RefToken> resolver)
 {
     return(Resolvers.Async <TSource, IUser>((source, _, context) => context.FindUserAsync(resolver(source))));
 }