当前位置: 首页>>代码示例>>C#>>正文


C# ISchema.FindType方法代码示例

本文整理汇总了C#中ISchema.FindType方法的典型用法代码示例。如果您正苦于以下问题:C# ISchema.FindType方法的具体用法?C# ISchema.FindType怎么用?C# ISchema.FindType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISchema的用法示例。


在下文中一共展示了ISchema.FindType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GraphTypeFromType

        public static IGraphType GraphTypeFromType(this IType type, ISchema schema)
        {
            if (type is NonNullType)
            {
                var nonnull = (NonNullType)type;
                var ofType = GraphTypeFromType(nonnull.Type, schema);
                var nonnullGraphType = typeof(NonNullGraphType<>).MakeGenericType(ofType.GetType());
                var instance = (NonNullGraphType)Activator.CreateInstance(nonnullGraphType);
                instance.ResolvedType = ofType;
                return instance;
            }

            if (type is ListType)
            {
                var list = (ListType)type;
                var ofType = GraphTypeFromType(list.Type, schema);
                var listGraphType = typeof(ListGraphType<>).MakeGenericType(ofType.GetType());
                var instance = (ListGraphType)Activator.CreateInstance(listGraphType);
                instance.ResolvedType = ofType;
                return instance;
            }

            if (type is NamedType)
            {
                var named = (NamedType)type;
                return schema.FindType(named.Name);
            }

            return null;
        }
开发者ID:graphql-dotnet,项目名称:graphql-dotnet,代码行数:30,代码来源:TypeExtensions.cs

示例2: ContainsTypeNames

 public void ContainsTypeNames(ISchema schema, params string[] typeNames)
 {
     typeNames.Apply(typeName =>
     {
         var type = schema.FindType(typeName);
         type.ShouldNotBeNull("Did not find {0} in type lookup.".ToFormat(typeName));
     });
 }
开发者ID:modulexcite,项目名称:graphql-dotnet,代码行数:8,代码来源:SchemaTests.cs

示例3: CoerceValue

        public object CoerceValue(ISchema schema, GraphType type, object input, Variables variables = null)
        {
            if (type is NonNullGraphType)
            {
                var nonNull = type as NonNullGraphType;
                return CoerceValue(schema, schema.FindType(nonNull.Type), input, variables);
            }

            if (input == null)
            {
                return null;
            }

            var variable = input as Variable;
            if (variable != null)
            {
                return variables != null
                    ? variables.ValueFor(variable.Name)
                    : null;
            }

            if (type is ListGraphType)
            {
                var listType = type as ListGraphType;
                var listItemType = schema.FindType(listType.Type);
                var list = input as IEnumerable;
                return list != null && !(input is string)
                    ? list.Map(item => CoerceValue(schema, listItemType, item, variables)).ToArray()
                    : new[] { CoerceValue(schema, listItemType, input, variables) };
            }

            if (type is ObjectGraphType || type is InputObjectGraphType)
            {
                var obj = new Dictionary<string, object>();

                if (input is KeyValuePair<string, object>)
                {
                    var kvp = (KeyValuePair<string, object>)input;
                    input = new Dictionary<string, object> { { kvp.Key, kvp.Value } };
                }

                var kvps = input as IEnumerable<KeyValuePair<string, object>>;
                if (kvps != null)
                {
                    input = kvps.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                }

                var dict = input as Dictionary<string, object>;
                if (dict == null)
                {
                    return null;
                }

                type.Fields.Apply(field =>
                {
                    object inputValue;
                    if (dict.TryGetValue(field.Name, out inputValue))
                    {
                        var fieldValue = CoerceValue(schema, schema.FindType(field.Type), inputValue, variables);
                        obj[field.Name] = fieldValue ?? field.DefaultValue;
                    }
                });

                return obj;
            }

            if (type is ScalarGraphType)
            {
                var scalarType = type as ScalarGraphType;
                return scalarType.Coerce(input);
            }

            return input;
        }
开发者ID:poobah,项目名称:graphql-dotnet,代码行数:74,代码来源:DocumentExecuter.cs

示例4: IsValidValue

        public bool IsValidValue(ISchema schema, GraphType type, object input)
        {
            if (type is NonNullGraphType)
            {
                if (input == null)
                {
                    return false;
                }

                return IsValidValue(schema, schema.FindType(((NonNullGraphType)type).Type), input);
            }

            if (input == null)
            {
                return true;
            }

            if (type is ListGraphType)
            {
                var listType = (ListGraphType) type;
                var listItemType = schema.FindType(listType.Type);
                var list = input as IEnumerable;
                return list != null && !(input is string)
                    ? list.All(item => IsValidValue(schema, listItemType, item))
                    : IsValidValue(schema, listItemType, input);
            }

            if (type is ObjectGraphType || type is InputObjectGraphType)
            {
                var dict = input as Dictionary<string, object>;
                if (dict == null)
                {
                    return false;
                }

                // ensure every provided field is defined
                if (type is InputObjectGraphType
                    && dict.Keys.Any(key => type.Fields.FirstOrDefault(field => field.Name == key) == null))
                {
                    return false;
                }

                return type.Fields.All(field =>
                           IsValidValue(schema, schema.FindType(field.Type),
                               dict.ContainsKey(field.Name) ? dict[field.Name] : null));
            }

            if (type is ScalarGraphType)
            {
                var scalar = (ScalarGraphType) type;
                return scalar.Coerce(input) != null;
            }

            return false;
        }
开发者ID:poobah,项目名称:graphql-dotnet,代码行数:55,代码来源:DocumentExecuter.cs

示例5: GetVariableValue

        public object GetVariableValue(ISchema schema, Variable variable, object input)
        {
            var type = schema.FindType(variable.Type.FullName);
            var value = input ?? variable.DefaultValue;
            if (IsValidValue(schema, type, value))
            {
                return CoerceValue(schema, type, value);
            }

            if (value == null)
            {
                throw new Exception("Variable '${0}' of required type '{1}' was not provided.".ToFormat(variable.Name, variable.Type.FullName));
            }

            throw new Exception("Variable '${0}' expected value of type '{1}'.".ToFormat(variable.Name, type.Name));
        }
开发者ID:poobah,项目名称:graphql-dotnet,代码行数:16,代码来源:DocumentExecuter.cs

示例6: GetArgumentValues

        public Dictionary<string, object> GetArgumentValues(ISchema schema, QueryArguments definitionArguments, Arguments astArguments, Variables variables)
        {
            if (definitionArguments == null || !definitionArguments.Any())
            {
                return null;
            }

            return definitionArguments.Aggregate(new Dictionary<string, object>(), (acc, arg) =>
            {
                var value = astArguments != null ? astArguments.ValueFor(arg.Name) : null;
                var type = schema.FindType(arg.Type);

                if (value is Variable)
                {
                    var variable = (Variable) value;
                    value = variables.ValueFor(variable.Name);
                }

                object coercedValue = null;
                if (IsValidValue(schema, type, value))
                {
                    coercedValue = CoerceValue(schema, type, value, variables);
                }
                acc[arg.Name] = coercedValue ?? arg.DefaultValue;
                return acc;
            });
        }
开发者ID:poobah,项目名称:graphql-dotnet,代码行数:27,代码来源:DocumentExecuter.cs

示例7: getSuggestedTypeNames

        /// <summary>
        /// Go through all of the implementations of type, as well as the interfaces
        /// that they implement. If any of those types include the provided field,
        /// suggest them, sorted by how often the type is referenced,  starting
        /// with Interfaces.
        /// </summary>
        private IEnumerable<string> getSuggestedTypeNames(
          ISchema schema,
          GraphType type,
          string fieldName)
        {
            if (type is InterfaceGraphType || type is UnionGraphType)
            {
                var suggestedObjectTypes = new List<string>();
                var interfaceUsageCount = new LightweightCache<string, int>(key => 0);

                var absType = type as GraphQLAbstractType;
                absType.PossibleTypes.Apply(possibleType =>
                {
                    if (!possibleType.HasField(fieldName))
                    {
                        return;
                    }

                    // This object defines this field.
                    suggestedObjectTypes.Add(possibleType.Name);

                    possibleType.Interfaces.Apply(possibleInterfaceType =>
                    {
                        var possibleInterface = schema.FindType(possibleInterfaceType);

                        if (!possibleInterface.HasField(fieldName))
                        {
                            return;
                        }

                        // This interface type defines this field.
                        interfaceUsageCount[possibleInterface.Name] = interfaceUsageCount[possibleInterface.Name] + 1;
                    });
                });

                var suggestedInterfaceTypes = interfaceUsageCount.Keys.OrderBy(x => interfaceUsageCount[x]);
                return suggestedInterfaceTypes.Concat(suggestedObjectTypes);
            }

            return Enumerable.Empty<string>();
        }
开发者ID:mwatts,项目名称:graphql-dotnet,代码行数:47,代码来源:FieldsOnCorrectType.cs

示例8: CoerceValue

        private object CoerceValue( ISchema schema, GraphType type, object input, IEnumerable<Variable> variables = null )
        {
            NonNullGraphType typeAsNonNullGraphType = type as NonNullGraphType;
            if( typeAsNonNullGraphType != null )
            {
                NonNullGraphType nonNull = typeAsNonNullGraphType;
                return CoerceValue(schema, schema.FindType(nonNull.Type), input, variables);
            }

            if (input == null)
            {
                return null;
            }

            Variable variable = input as Variable;
            if (variable != null)
            {
                return variables != null
                    ? variables.ValueFor(variable.Name)
                    : null;
            }

            ListGraphType typeAsListGraphType = type as ListGraphType;
            if( typeAsListGraphType != null )
            {
                GraphType listItemType = schema.FindType( typeAsListGraphType.Type );
                IEnumerable list = input as IEnumerable;
                return list != null && !(input is string)
                    ? list.Map(item => CoerceValue(schema, listItemType, item, variables)).ToArray()
                    : new[] { CoerceValue(schema, listItemType, input, variables) };
            }

            if (type is ObjectGraphType || type is InputObjectGraphType)
            {
                bool inputTypeFound = false;

                Dictionary<string, object> obj = new Dictionary<string, object>();

                if (input is KeyValuePair<string, object>)
                {
                    KeyValuePair<string, object> kvp = (KeyValuePair<string, object>)input;
                    input = new Dictionary<string, object>
                    {
                        {kvp.Key, kvp.Value}
                    };
                    inputTypeFound = true;
                }
                
                IEnumerable<KeyValuePair<string, object>> kvps = input as IEnumerable<KeyValuePair<string, object>>;
                if (kvps != null)
                {
                    input = kvps.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                    inputTypeFound = true;
                }

                if (!inputTypeFound)
                {
                    try
                    {
                        input = JObject.FromObject(input).Children()
                            .Cast<JProperty>()
                            .Select(x => {
                                JToken value = JToken.FromObject(x.Value);
                                return new KeyValuePair<string, object>(x.Name, value);
                            })
                            .ToDictionary(x => x.Key, x => x.Value);
                    }
                    catch
                    {
                        input = new Dictionary<string, object>
                        {
                            {(string)input, null} 
                        };
                    }
                }

                Dictionary<string, object> dict = (Dictionary<string, object>)input;

                type.Fields.Apply(field =>
                {
                    object inputValue;
                    if (dict.TryGetValue(field.Name, out inputValue))
                    {
                        object fieldValue = CoerceValue(schema, schema.FindType(field.Type), inputValue, variables);
                        obj[field.Name] = fieldValue ?? field.DefaultValue;
                    }
                });

                return obj;
            }

            ScalarGraphType typeAsScalarGraphType = type as ScalarGraphType;
            if( typeAsScalarGraphType != null )
            {
                return typeAsScalarGraphType.Coerce( input );
            }

            return input;
        }
开发者ID:husterk,项目名称:graphql-dotnet,代码行数:99,代码来源:DocumentExecuter.cs

示例9: IsValidValue

        private bool IsValidValue(ISchema schema, GraphType type, object input)
        {
            NonNullGraphType typeAsNonNullGraphType = type as NonNullGraphType;
            if( typeAsNonNullGraphType != null )
            {
                if (input == null)
                {
                    return false;
                }

                return IsValidValue( schema, schema.FindType( typeAsNonNullGraphType.Type ), input );
            }

            if (input == null)
            {
                return true;
            }

            ListGraphType typeAsListGraphType = type as ListGraphType;
            if( typeAsListGraphType != null )
            {
                GraphType listItemType = schema.FindType( typeAsListGraphType.Type );
                IEnumerable list = input as IEnumerable;
                return list != null && !(input is string)
                    ? list.All(item => IsValidValue(schema, listItemType, item))
                    : IsValidValue(schema, listItemType, input);
            }

            if (type is ObjectGraphType || type is InputObjectGraphType)
            {
                IReadOnlyDictionary<string, object> dict = input as IReadOnlyDictionary<string, object> ??
                    JObject.FromObject(input).Children()
                        .Cast<JProperty>()
                        .Select(x => {
                            JToken value = JToken.FromObject(x.Value);
                            return new KeyValuePair<string, object>(x.Name, value);
                        })
                        .ToDictionary(x => x.Key, x => x.Value);
                
                // ensure every provided field is defined
                if (type is InputObjectGraphType
                    && dict.Keys.Any(key => type.Fields.FirstOrDefault(field => field.Name == key) == null))
                {
                    return false;
                }

                return type.Fields.All( field =>
                    IsValidValue(
                        schema,
                        schema.FindType(field.Type),
                        dict.ContainsKey(field.Name)
                            ? dict[field.Name]
                            : null ) );
            }

            ScalarGraphType typeAsScalarGraphType = type as ScalarGraphType;
            if( typeAsScalarGraphType != null )
            {
                ScalarGraphType scalar = typeAsScalarGraphType;
                return scalar.Coerce(input) != null;
            }

            return false;
        }
开发者ID:husterk,项目名称:graphql-dotnet,代码行数:64,代码来源:DocumentExecuter.cs

示例10: GetArgumentValues

        private IReadOnlyDictionary<string, object> GetArgumentValues(ISchema schema, IEnumerable<QueryArgument> definitionArguments, IEnumerable<Argument> astArguments, IEnumerable<Variable> variables)
        {
            List<QueryArgument> definitionArgumentsAsList = definitionArguments != null
                ? definitionArguments.ToList()
                : new List<QueryArgument>();

            if (definitionArgumentsAsList.Count == 0)
            {
                return null;
            }

            return definitionArgumentsAsList.Aggregate(new Dictionary<string, object>(), (acc, arg) =>
            {
                object value = astArguments != null ? astArguments.ValueFor(arg.Name) : null;
                GraphType type = schema.FindType(arg.Type);

                object coercedValue = CoerceValue(schema, type, value, variables);
                acc[arg.Name] = IsValidValue(schema, type, coercedValue)
                    ? coercedValue ?? arg.DefaultValue
                    : arg.DefaultValue;
                return acc;
            });
        }
开发者ID:husterk,项目名称:graphql-dotnet,代码行数:23,代码来源:DocumentExecuter.cs

示例11: CoerceValueAst

        // TODO: combine duplication with CoerceValue
        public object CoerceValueAst(ISchema schema, GraphType type, object input, Variables variables)
        {
            if (type is NonNullGraphType)
            {
                var nonNull = type as NonNullGraphType;
                return CoerceValueAst(schema, schema.FindType(nonNull.Type), input, variables);
            }

            if (input == null)
            {
                return null;
            }

            if (input is Variable)
            {
                return variables != null
                    ? variables.ValueFor(((Variable)input).Name)
                    : null;
            }

            if (type is ListGraphType)
            {
                var listType = type as ListGraphType;
                var list = input as IEnumerable;
                return list != null
                    ? list.Map(item => CoerceValueAst(schema, listType, item, variables))
                    : new[] { input };
            }

            if (type is ObjectGraphType)
            {
                var objType = type as ObjectGraphType;
                var obj = new Dictionary<string, object>();
                var dict = (Dictionary<string, object>)input;

                objType.Fields.Apply(field =>
                {
                    var fieldValue = CoerceValueAst(schema, schema.FindType(field.Type), dict[field.Name], variables);
                    obj[field.Name] = fieldValue ?? field.DefaultValue;
                });
            }

            if (type is ScalarGraphType)
            {
                var scalarType = type as ScalarGraphType;
                return scalarType.Coerce(input);
            }

            return input;
        }
开发者ID:josdeweger,项目名称:graphql-dotnet,代码行数:51,代码来源:DocumentExecuter.cs

示例12: IsValidValue

        public bool IsValidValue(ISchema schema, GraphType type, object input)
        {
            if (type is NonNullGraphType)
            {
                if (input == null)
                {
                    return false;
                }

                return IsValidValue(schema, schema.FindType(((NonNullGraphType)type).Type), input);
            }

            if (input == null)
            {
                return true;
            }

            if (type is ListGraphType)
            {
                var listType = (ListGraphType) type;
                var list = input as IEnumerable;
                return list != null
                    ? list.All(item => IsValidValue(schema, type, item))
                    : IsValidValue(schema, listType, input);
            }

            if (type is ObjectGraphType)
            {
                var dict = input as Dictionary<string, object>;
                return dict != null
                    && type.Fields.All(field => IsValidValue(schema, schema.FindType(field.Type), dict[field.Name]));
            }

            if (type is ScalarGraphType)
            {
                var scalar = (ScalarGraphType) type;
                return scalar.Coerce(input) != null;
            }

            return false;
        }
开发者ID:josdeweger,项目名称:graphql-dotnet,代码行数:41,代码来源:DocumentExecuter.cs

示例13: GetVariableValue

        public object GetVariableValue(ISchema schema, Variable variable, object input)
        {
            var type = schema.FindType(variable.Type.Name);
            if (IsValidValue(schema, type, input))
            {
                if (input == null && variable.DefaultValue != null)
                {
                    return CoerceValueAst(schema, type, variable.DefaultValue, null);
                }

                return CoerceValue(schema, type, input);
            }

            throw new Exception("Variable {0} expected type '{1}'.".ToFormat(variable.Name, type.Name));
        }
开发者ID:josdeweger,项目名称:graphql-dotnet,代码行数:15,代码来源:DocumentExecuter.cs

示例14: GetArgumentValues

        public Dictionary<string, object> GetArgumentValues(ISchema schema, QueryArguments definitionArguments, Arguments astArguments, Variables variables)
        {
            if (definitionArguments == null || !definitionArguments.Any())
            {
                return null;
            }

            return definitionArguments.Aggregate(new Dictionary<string, object>(), (acc, arg) =>
            {
                var value = astArguments != null ? astArguments.ValueFor(arg.Name) : null;
                var coercedValue = CoerceValueAst(schema, schema.FindType(arg.Type), value, variables);
                acc[arg.Name] = coercedValue ?? arg.DefaultValue;
                return acc;
            });
        }
开发者ID:josdeweger,项目名称:graphql-dotnet,代码行数:15,代码来源:DocumentExecuter.cs

示例15: CoerceValue

        public object CoerceValue(ISchema schema, GraphType type, IValue input, Variables variables = null)
        {
            if (type is NonNullGraphType)
            {
                var nonNull = type as NonNullGraphType;
                return CoerceValue(schema, schema.FindType(nonNull.Type), input, variables);
            }

            if (input == null)
            {
                return null;
            }

            var variable = input as VariableReference;
            if (variable != null)
            {
                return variables != null
                    ? variables.ValueFor(variable.Name)
                    : null;
            }

            if (type is ListGraphType)
            {
                var listType = type as ListGraphType;
                var listItemType = schema.FindType(listType.Type);
                var list = input as ListValue;
                return list != null
                    ? list.Values.Map(item => CoerceValue(schema, listItemType, item, variables)).ToArray()
                    : new[] { CoerceValue(schema, listItemType, input, variables) };
            }

            if (type is ObjectGraphType || type is InputObjectGraphType)
            {
                var obj = new Dictionary<string, object>();

                var objectValue = input as ObjectValue;
                if (objectValue == null)
                {
                    return null;
                }

                type.Fields.Apply(field =>
                {
                    var objectField = objectValue.Field(field.Name);
                    if (objectField != null)
                    {
                        var fieldValue = CoerceValue(schema, schema.FindType(field.Type), objectField.Value, variables);
                        fieldValue = fieldValue ?? field.DefaultValue;

                        obj[field.Name] = fieldValue;
                    }
                });

                return obj;
            }

            if (type is ScalarGraphType)
            {
                var scalarType = type as ScalarGraphType;
                return scalarType.ParseLiteral(input);
            }

            return null;
        }
开发者ID:mwatts,项目名称:graphql-dotnet,代码行数:64,代码来源:DocumentExecuter.cs


注:本文中的ISchema.FindType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。