예제 #1
0
        // http://facebook.github.io/graphql/June2018/#AreTypesCompatible()
        private bool AreTypesCompatible(
            ITypeNode variableType,
            IType locationType)
        {
            if (locationType.IsNonNullType())
            {
                if (variableType.IsNonNullType())
                {
                    return(AreTypesCompatible(
                               variableType.InnerType(),
                               locationType.InnerType()));
                }
                return(false);
            }

            if (variableType.IsNonNullType())
            {
                return(AreTypesCompatible(
                           variableType.InnerType(),
                           locationType));
            }

            if (locationType.IsListType())
            {
                if (variableType.IsListType())
                {
                    return(AreTypesCompatible(
                               variableType.InnerType(),
                               locationType.InnerType()));
                }
                return(false);
            }

            if (variableType.IsListType())
            {
                return(false);
            }

            if (variableType is NamedTypeNode vn &&
                locationType is INamedType lt)
            {
                return(string.Equals(
                           vn.Name.Value,
                           lt.Name,
                           StringComparison.Ordinal));
            }

            return(false);
        }
예제 #2
0
        public static NamedTypeNode NamedType(this ITypeNode type)
        {
            if (type.InnerType().InnerType().InnerType().InnerType().InnerType() is NamedTypeNode n)
            {
                return(n);
            }

            throw new NotSupportedException();
        }
예제 #3
0
        // helpers
        protected TypeDefinitionField TransformTypeField(ITypeNode type, TypeDefinitionField context, bool nullable = false)
        {
            var ctx = context ?? new TypeDefinitionField();

            if (type.IsNonNullType())
            {
                ctx.NotNullable = true;
                return(TransformTypeField(type.InnerType(), ctx));
            }

            if (type.IsListType())
            {
                ctx.IsList    = true;
                ctx.InnerType = TransformTypeField(type.InnerType(), null);
                return(ctx);
            }

            ctx.Type = type.ToString();
            return(ctx);
        }