public override void OnConfigure(
            IDescriptorContext context,
            IObjectFieldDescriptor descriptor,
            MemberInfo member)
        {
            descriptor.Resolve(async ctx =>
            {
                ICharacter character            = ctx.Parent <ICharacter>();
                ICharacterRepository repository = ctx.Service <ICharacterRepository>();
                //This is injected by the PreProcessing middleware wen enabled...
                var graphQLParams = new GraphQLParamsContext(ctx);

                //********************************************************************************
                //Perform some pre-processed retrieval of data from the Repository...
                //Notice Pagination processing is pushed down to the Repository layer also!

                //Get RepoDb specific mapper for the GraphQL parameter context...
                //Note: It's important that we map to the DB Model (not the GraphQL model).
                var repoDbParams = new GraphQLRepoDbMapper <CharacterDbModel>(graphQLParams);

                //Now we can retrieve the related and paginated data from the Repo...
                var pagedFriends = await repository.GetCharacterFriendsAsync(character.Id, repoDbParams.GetCursorPagingParameters());
                return(new PreProcessedCursorSlice <ICharacter>(pagedFriends));
                //********************************************************************************
            });
        }
Ejemplo n.º 2
0
    public static IObjectFieldDescriptor Resolver(
        this IObjectFieldDescriptor descriptor,
        object constantResult)
    {
        if (descriptor is null)
        {
            throw new ArgumentNullException(nameof(descriptor));
        }

        return(descriptor.Resolve(
                   _ => new ValueTask <object?>(constantResult)));
    }
 public override void OnConfigure(
     IDescriptorContext context,
     IObjectFieldDescriptor descriptor,
     MemberInfo member)
 {
     descriptor.Resolve(ctx =>
     {
         ICharacter character            = ctx.Parent <ICharacter>();
         ICharacterRepository repository = ctx.Service <ICharacterRepository>();
         return(repository.GetCharacters(character.Friends.ToArray()));
     });
 }
Ejemplo n.º 4
0
        public static IObjectFieldDescriptor Resolve <TResult>(
            this IObjectFieldDescriptor descriptor,
            TResult constantResult)
        {
            if (descriptor is null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            return(descriptor.Resolve(
                       ctx => new ValueTask <object?>(constantResult),
                       typeof(NativeType <TResult>)));
        }
Ejemplo n.º 5
0
    public static IObjectFieldDescriptor Resolver(
        this IObjectFieldDescriptor descriptor,
        Func <IResolverContext, object?> resolver)
    {
        if (descriptor is null)
        {
            throw new ArgumentNullException(nameof(descriptor));
        }

        if (resolver is null)
        {
            throw new ArgumentNullException(nameof(resolver));
        }

        return(descriptor.Resolve(ctx => new ValueTask <object?>(resolver(ctx))));
    }
Ejemplo n.º 6
0
    public static IObjectFieldDescriptor Resolver(
        this IObjectFieldDescriptor descriptor,
        Func <Task <object?> > resolver)
    {
        if (descriptor is null)
        {
            throw new ArgumentNullException(nameof(descriptor));
        }

        if (resolver is null)
        {
            throw new ArgumentNullException(nameof(resolver));
        }

        return(descriptor.Resolve(async _ => await resolver().ConfigureAwait(false)));
    }
Ejemplo n.º 7
0
 public override void OnConfigure(
     IDescriptorContext context,
     IObjectFieldDescriptor descriptor,
     MemberInfo member)
 {
     descriptor.Resolve(
         new List <Bar>
     {
         new Bar {
             BarBaz = "a_a", BarQux = "a_c"
         },
         new Bar {
             BarBaz = "a_b", BarQux = "a_d"
         }
     });
 }
        public static IObjectFieldDescriptor Resolve(
            this IObjectFieldDescriptor descriptor,
            Func <IResolverContext, CancellationToken, object?> resolver)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (resolver == null)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            return(descriptor.Resolve(
                       ctx => new ValueTask <object?>(resolver(ctx, ctx.RequestAborted))));
        }
Ejemplo n.º 9
0
    public static IObjectFieldDescriptor Resolver <TResult>(
        this IObjectFieldDescriptor descriptor,
        Func <TResult> resolver)
    {
        if (descriptor is null)
        {
            throw new ArgumentNullException(nameof(descriptor));
        }

        if (resolver is null)
        {
            throw new ArgumentNullException(nameof(resolver));
        }

        return(descriptor.Resolve(_ =>
                                  new ValueTask <object?>(resolver()),
                                  typeof(NativeType <TResult>)));
    }