public IntrospectedType Introspect(GraphQLScalarType type)
        {
            if (type is GraphQLList)
            {
                return(this.IntrospectListType((GraphQLList)type, () => this.Introspect(((GraphQLList)type).MemberType)));
            }

            if (type is GraphQLNonNullType)
            {
                return(this.IntrospectNonNullType((GraphQLNonNullType)type, () => this.Introspect(((GraphQLNonNullType)type).UnderlyingNullableType)));
            }

            if (type is GraphQLEnumType)
            {
                return(this.IntrospectEnumType((GraphQLEnumType)type));
            }

            if (type is GraphQLObjectType)
            {
                return(this.IntrospectObjectType((GraphQLObjectType)type));
            }

            if (type is GraphQLInterfaceType)
            {
                return(this.IntrospectInterfaceType((GraphQLInterfaceType)type));
            }

            if (type is GraphQLInputObjectType)
            {
                return(this.IntrospectInputObjectType((GraphQLInputObjectType)type));
            }

            return(this.IntrospectScalarType(type));
        }
Example #2
0
        public Type GetType(GraphQLScalarType type)
        {
            if (type is GraphQLList)
            {
                return(ReflectionUtilities.CreateListTypeOf(this.GetType(((GraphQLList)type).MemberType)));
            }

            var reflectedType = this.bindings
                                .Where(e => IsMatchingValueType(type, e.Value))
                                .Select(e => e.Key)
                                .SingleOrDefault();

            if (reflectedType == null)
            {
                if (type is GraphQLNonNullType)
                {
                    reflectedType = this.schemaObserver.GetTypeFor(((GraphQLNonNullType)type).UnderlyingNullableType);
                }
                else
                {
                    reflectedType = this.schemaObserver.GetTypeFor(type);
                }
            }

            return(reflectedType);
        }
        public override GraphQLArgument BeginVisitArgument(GraphQLArgument argument)
        {
            var fieldName = this.fieldStack.Peek();

            this.argumentType = this.translator.GetObjectTypeTranslatorFor(this.typeStack.Peek()).GetField(fieldName).Arguments
                                .SingleOrDefault(e => e.Key == argument.Name.Value).Value;
            this.argumentTypes.Remove(argument.Name.Value);

            return(base.BeginVisitArgument(argument));
        }
Example #4
0
        public static IntrospectedType CreateForScalar(GraphQLScalarType type)
        {
            var introspectedType = new IntrospectedType();

            introspectedType.Name        = type.Name;
            introspectedType.Description = type.Description;
            introspectedType.Kind        = TypeKind.SCALAR;

            return(introspectedType);
        }
Example #5
0
        public object TranslatePerDefinition(object inputObject, GraphQLScalarType typeDefinition)
        {
            if (inputObject is ExpandoObject && typeDefinition is GraphQLObjectType)
            {
                return(this.CreateObjectFromDynamic((GraphQLObjectType)typeDefinition, (ExpandoObject)inputObject));
            }

            var systemType = this.GetType(typeDefinition);

            return(ReflectionUtilities.ChangeValueType(inputObject, systemType));
        }
Example #6
0
        private static bool IsMatchingValueType(GraphQLScalarType type, GraphQLScalarType bindingType)
        {
            if (type is GraphQLNonNullType && bindingType is GraphQLNonNullType)
            {
                return(IsMatchingValueType(GetUnderlyingNullableType(type), GetUnderlyingNullableType(bindingType)));
            }

            if (type.GetType() != bindingType.GetType())
            {
                return(false);
            }

            return(type.Name == bindingType.Name);
        }
Example #7
0
        public GraphQLException[] IsValidLiteralValue(GraphQLScalarType inputType, Language.AST.GraphQLValue astValue)
        {
            if (inputType is GraphQLNonNullType)
            {
                if (astValue == null)
                {
                    return(new GraphQLException[]
                    {
                        new GraphQLException($"Expected {inputType.Name ?? "non-null"} found null")
                    });
                }

                return(this.IsValidLiteralValue(((GraphQLNonNullType)inputType).UnderlyingNullableType, astValue));
            }

            if (astValue == null)
            {
                return new GraphQLException[] { }
            }
            ;

            if (astValue.Kind == Language.AST.ASTNodeKind.Variable) // this method is checking only literals
            {
                return new GraphQLException[] { }
            }
            ;

            object value = this.GetLiteralValue(astValue);

            try
            {
                ReflectionUtilities.ChangeValueType(value, this.GetType(inputType));
            }
            catch (Exception ex)
            {
                return(new GraphQLException[] { new GraphQLException($"Expected {inputType.Name ?? "non-null"} found null", ex) });
            }

            return(new GraphQLException[] { });
        }
Example #8
0
 private static string PrintScalar(GraphQLScalarType type)
 {
     return($"{PrintDescription(type)}scalar {type.Name}");
 }
Example #9
0
 public GraphQLList(GraphQLScalarType memberType) : base(null, null)
 {
     this.MemberType = memberType;
 }
Example #10
0
 public Type GetTypeFor(GraphQLScalarType type)
 {
     return(ReflectionUtilities.GetGenericArgumentsEagerly(type.GetType()));
 }
Example #11
0
 private IntrospectedType IntrospectScalarType(GraphQLScalarType scalarType)
 {
     return(IntrospectedType.CreateForScalar(scalarType));
 }
Example #12
0
 private static GraphQLNullableType GetUnderlyingNullableType(GraphQLScalarType type)
 {
     return(((GraphQLNonNullType)type).UnderlyingNullableType);
 }