Beispiel #1
0
    public async void TestResolveViaForeignServiceType_MixedTypes()
    {
        // arrange
        ISchema schema = SchemaBuilder.New()
                         .AddApolloFederation()
                         .AddQueryType <Query>()
                         .Create();

        IResolverContext context = CreateResolverContext(schema);

        // act
        var representations = new List <Representation>
        {
            new()
            {
                TypeName = "MixedFieldTypes",
                Data     = new ObjectValueNode(
                    new ObjectFieldNode("Id", "1"),
                    new ObjectFieldNode("IntField", 25))
            }
        };

        // assert
        List <object?> result = await EntitiesResolver._Entities(schema, representations, context);

        MixedFieldTypes obj = Assert.IsType <MixedFieldTypes>(result[0]);

        Assert.Equal("1", obj.Id);
        Assert.Equal(25, obj.IntField);
        Assert.Equal("InternalValue", obj.InternalField);
    }
Beispiel #2
0
    public async void TestResolveViaEntityResolver()
    {
        ISchema schema = SchemaBuilder.New()
                         .AddApolloFederation()
                         .AddQueryType <Query>()
                         .Create();

        IResolverContext context = CreateResolverContext(schema);

        // act
        var representations = new List <Representation>
        {
            new()
            {
                TypeName = "TypeWithReferenceResolver",
                Data     = new ObjectValueNode(new ObjectFieldNode("Id", "1"))
            }
        };

        // assert
        List <object?> result = await EntitiesResolver._Entities(schema, representations, context);

        TypeWithReferenceResolver obj = Assert.IsType <TypeWithReferenceResolver>(result[0]);

        Assert.Equal("1", obj.Id);
        Assert.Equal("SomeField", obj.SomeField);
    }
Beispiel #3
0
    public async void TestResolveViaEntityResolver_NoResolverFound()
    {
        ISchema schema = SchemaBuilder.New()
                         .AddApolloFederation()
                         .AddQueryType <Query>()
                         .Create();

        IResolverContext context = CreateResolverContext(schema);

        // act
        var representations = new List <Representation>
        {
            new()
            {
                TypeName = "TypeWithoutRefResolver",
                Data     = new ObjectValueNode()
            }
        };

        // assert
        Task ShouldThrow() => EntitiesResolver._Entities(schema, representations, context);

        await Assert.ThrowsAsync <SchemaException>(ShouldThrow);
    }