Example #1
0
        internal static IntrospectedInputObject CreateForInputObject(GraphQLInputObjectType type, Introspector introspector, IObjectTypeTranslator typeObserver)
        {
            var introspectedType = new IntrospectedInputObject(introspector, typeObserver);

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

            return(introspectedType);
        }
Example #2
0
        private string PrintInputObject(GraphQLInputObjectType type)
        {
            var fields        = type.GetFieldsInfo();
            var printedFields = string.Join("\n", fields.Select((field, i) =>
                                                                $"{PrintDescription(field, "  ", i == 0)}  {this.PrintInputValue(field)}{PrintDeprecated(field)}"));

            return
                (PrintDescription(type) +
                 $"input {type.Name} {{\n" +
                 $"{printedFields}\n}}");
        }
        private IEnumerable <GraphQLException> ValidateObjectFields(GraphQLInputObjectType objectType, GraphQLObjectValue objectValue)
        {
            foreach (var fieldInfo in objectType.GetFieldsInfo())
            {
                var field      = objectValue.Fields.SingleOrDefault(e => e.Name.Value == fieldInfo.Name);
                var fieldType  = fieldInfo.GetGraphQLType(this.schemaRepository);
                var fieldValue = field?.Value;

                var fieldErrors = this.IsValid(fieldType, fieldValue);

                foreach (var fieldError in fieldErrors)
                {
                    yield return(new GraphQLException($"In field \"{fieldInfo.Name}\": {fieldError.Message}"));
                }
            }
        }
Example #4
0
        public object CreateObjectFromDynamic(GraphQLInputObjectType inputObjectType, ExpandoObject inputObject)
        {
            var systemType            = this.schemaRepository.GetInputSystemTypeFor(inputObjectType);
            var fields                = inputObjectType.GetFieldsInfo();
            var inputObjectDictionary = (IDictionary <string, object>)inputObject;

            var resultObject = Activator.CreateInstance(systemType);

            foreach (var field in fields)
            {
                if (!inputObjectDictionary.ContainsKey(field.Name))
                {
                    continue;
                }

                this.AssignValueToField(inputObjectDictionary[field.Name], resultObject, field.Lambda);
            }

            return(resultObject);
        }
Example #5
0
 public void SetUp()
 {
     this.type = new GraphQLTestInputModelType();
 }
 private IntrospectedType IntrospectInputObjectType(GraphQLInputObjectType type)
 {
     return(IntrospectedType.CreateForInputObject(type, this, this.typeTranslator.GetObjectTypeTranslatorFor(type)));
 }