Types

Specification

Following types are supported:

  • ScalarType
  • ObjectType
  • InterfaceType
  • UnionType
  • EnumType
  • InputObjectType

These all exists in Tanka.GraphQL.type namespace and implement INamedType interface

    public interface INamedType: IType
    {
        string Name { get; }
    }

Wrapping types

Wrapping types implement the IWrappingType

    public interface IWrappingType: IType
    {
        IType OfType { get; }
    }

Two built-in implementations are provided

  • List
  • NonNull

Input and output types

Is input type?

        [Theory]
        [MemberData(nameof(ValidInputTypes))]
        public void IsInputType(INamedType type)
        {
            /* Given */
            /* When */
            var isInput = TypeIs.IsInputType(type);
            var isInputAsNonNull = TypeIs.IsInputType(
                new NonNull(type));
            var isInputAsList = TypeIs.IsInputType(
                new List(type));

            /* Then */
            Assert.True(isInput);
            Assert.True(isInputAsNonNull);
            Assert.True(isInputAsList);
        }


        public static IEnumerable<object[]> ValidInputTypes
        {
            get
            {
                foreach (var scalarType in ScalarType.Standard)
                {
                    yield return new object[] {scalarType};
                }

                yield return new object[]
                {
                    new EnumType("Enum",
                        new EnumValues())
                };

                yield return new object[]
                {
                    new InputObjectType("Input")
                };
            }
        }

Is output type?


        [Theory]      
        [MemberData(nameof(ValidOutputTypes))]
        public void IsOutputType(INamedType type)
        {
            /* Given */
            /* When */
            var isOutput = TypeIs.IsOutputType(type);
            var isOutputAsNonNull = TypeIs.IsOutputType(
                new NonNull(type));
            var isOutputAsList = TypeIs.IsOutputType(
                new List(type));

            /* Then */
            Assert.True(isOutput);
            Assert.True(isOutputAsNonNull);
            Assert.True(isOutputAsList);
        }


        public static IEnumerable<object[]> ValidOutputTypes
        {
            get
            {
                foreach (var scalarType in ScalarType.Standard)
                {
                    yield return new object[] {scalarType};
                }

                yield return new object[]
                {
                    new ObjectType("Object"), 
                };

                yield return new object[]
                {
                    new InterfaceType("Interface"), 
                };

                yield return new object[]
                {
                    new UnionType("Union",
                        Enumerable.Empty<ObjectType>()), 
                };

                yield return new object[]
                {
                    new EnumType("Enum",
                        new EnumValues())
                };
            }
        }