Пример #1
0
        // Constant

        public static IObjectFieldDescriptor Resolver(
            this IObjectFieldDescriptor descriptor,
            object constantResult)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            return(descriptor.Resolver(
                       ctx => Task.FromResult <object>(constantResult)));
        }
Пример #2
0
        public static IObjectFieldDescriptor Resolver <TResult>(
            this IObjectFieldDescriptor descriptor,
            TResult constantResult)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            return(descriptor.Resolver(
                       ctx => new ValueTask <object?>(constantResult),
                       typeof(NativeType <TResult>)));
        }
Пример #3
0
        public static IObjectFieldDescriptor Resolver(
            this IObjectFieldDescriptor descriptor,
            Func <IResolverContext, object?> resolver)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

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

            return(descriptor.Resolver(ctx => new ValueTask <object?>(resolver(ctx))));
        }
Пример #4
0
        public static IObjectFieldDescriptor Resolver(
            this IObjectFieldDescriptor descriptor,
            Func <Task <object?> > resolver)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

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

            return(descriptor.Resolver(async ctx => await resolver().ConfigureAwait(false)));
        }
Пример #5
0
        public static IObjectFieldDescriptor Resolver(
            this IObjectFieldDescriptor descriptor,
            Func <Task <object> > resolver)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

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

            return(descriptor.Resolver(ctx => resolver()));
        }
 public override void OnConfigure(
     IDescriptorContext context,
     IObjectFieldDescriptor descriptor,
     MemberInfo member)
 {
     descriptor.Resolver(
         new List <Bar>
     {
         new Bar {
             BarBaz = "a_a", BarQux = "a_c"
         },
         new Bar {
             BarBaz = "a_b", BarQux = "a_d"
         }
     });
 }
Пример #7
0
        // Resolver(IResolverContext, CancellationToken)

        public static IObjectFieldDescriptor Resolver(
            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.Resolver(
                       ctx => resolver(ctx, ctx.RequestAborted)));
        }
Пример #8
0
        public static IObjectFieldDescriptor Resolver <TResult>(
            this IObjectFieldDescriptor descriptor,
            Func <IResolverContext, CancellationToken, TResult> resolver)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

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

            return(descriptor.Resolver(
                       ctx => new ValueTask <object?>(resolver(ctx, ctx.RequestAborted)),
                       typeof(NativeType <TResult>)));
        }
Пример #9
0
        public static IObjectFieldDescriptor Resolver <TResult>(
            this IObjectFieldDescriptor descriptor,
            Func <TResult> resolver)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

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

            return(descriptor.Resolver(ctx =>
                                       Task.FromResult <object>(resolver()),
                                       typeof(NativeType <TResult>)));
        }
Пример #10
0
        public static IObjectFieldDescriptor Resolver <TResult>(
            this IObjectFieldDescriptor descriptor,
            Func <IResolverContext, Task <TResult> > resolver)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

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

            return(descriptor.Resolver(
                       async ctx => await resolver(ctx).ConfigureAwait(false),
                       typeof(NativeType <TResult>)));
        }
        public override void OnConfigure(
            IDescriptorContext context,
            IObjectFieldDescriptor descriptor,
            MemberInfo member)
        {
            descriptor.Resolver(ctx =>
            {
                ICharacter character            = ctx.Parent <ICharacter>();
                ICharacterRepository repository = ctx.Service <ICharacterRepository>();

                //********************************************************************************
                //Perform some pre-processed Paging (FYI, without sorting this may be unprdeicatble
                //  but works here due to the in-memory store used by Star Wars example!
                var graphQLParams = new GraphQLParamsContext(ctx);
                var friends       = repository.GetCharacters(character.Friends.ToArray());

                var pagedFriends = friends.SliceAsCursorPage(graphQLParams.PagingArgs);
                return(new PreProcessedCursorSlice <ICharacter>(pagedFriends));
                //********************************************************************************
            });
        }
Пример #12
0
 public static IObjectFieldDescriptor Resolver(
     this IObjectFieldDescriptor descriptor,
     AsyncFieldResolverDelegate fieldResolver)
 {
     return(descriptor.Resolver(fieldResolver));
 }
 public static IObjectFieldDescriptor Resolver(
     this IObjectFieldDescriptor descriptor,
     Func <Task <object> > fieldResolver)
 {
     return(descriptor.Resolver(ctx => fieldResolver()));
 }