Example #1
0
    private ValueTask <object?> ResolveRef(ISchema schema, ObjectType type)
    {
        var inClassResolverContextObject =
            type.ContextData[WellKnownContextData.EntityResolver];

        Assert.NotNull(inClassResolverContextObject);
        FieldResolverDelegate inClassResolverDelegate =
            Assert.IsType <FieldResolverDelegate>(inClassResolverContextObject);
        IResolverContext context = CreateResolverContext(schema);

        context.SetLocalValue("data", new ObjectValueNode());
        return(inClassResolverDelegate.Invoke(context));
    }
Example #2
0
 private static FieldDelegate CreateResolverMiddleware(
     FieldResolverDelegate fieldResolver)
 {
     return(async ctx =>
     {
         if (!ctx.IsResultModified && fieldResolver != null)
         {
             Task <object> task = fieldResolver.Invoke(ctx);
             ctx.Result = task == null
                 ? null
                 : await task.ConfigureAwait(false);
         }
     });
 }
        public async Task Resolver_IResolverContextObject_ResolverIsSet()
        {
            // arrange
            FieldResolverDelegate resolver = null;
            var resolverFunc = new Func <IResolverContext, object>(_ => "foo");
            var descriptor   = new Mock <IObjectFieldDescriptor>(MockBehavior.Strict);

            descriptor.Setup(t => t.Resolve(It.IsAny <FieldResolverDelegate>()))
            .Returns(
                new Func <FieldResolverDelegate, IObjectFieldDescriptor>(
                    r =>
            {
                resolver = r;
                return(descriptor.Object);
            }));

            // act
            ResolverObjectFieldDescriptorExtensions.Resolver(descriptor.Object, resolverFunc);

            // assert
            Assert.Equal("foo", await resolver.Invoke(
                             new Mock <IResolverContext>().Object));
        }