コード例 #1
0
        public void AddType(GraphType type, TypeCollectionContext context)
        {
            if (type == null)
            {
                return;
            }

            var name = type.CollectTypes(context);

            _types[name] = type;

            type.Fields.Apply(field =>
            {
                AddTypeIfNotRegistered(field.Type, context);

                if (field.Arguments != null)
                {
                    field.Arguments.Apply(arg =>
                    {
                        AddTypeIfNotRegistered(arg.Type, context);
                    });
                }
            });

            if (type is ObjectGraphType)
            {
                var obj = (ObjectGraphType)type;
                obj.Interfaces.Apply(objectInterface =>
                {
                    AddTypeIfNotRegistered(objectInterface, context);
                });
            }
        }
コード例 #2
0
        public void AddType(GraphType type, TypeCollectionContext context)
        {
            if (type == null)
            {
                return;
            }

            var name = type.CollectTypes(context);

            _types[name] = type;

            type.Fields.Apply(field =>
            {
                var foundType = this[field.Type];
                if (foundType == null)
                {
                    AddType(context.ResolveType(field.Type), context);
                }
            });

            if (type is ObjectGraphType)
            {
                var obj = (ObjectGraphType)type;
                obj.Interfaces.Apply(objectInterface =>
                {
                    var foundType = this[objectInterface];
                    if (foundType == null)
                    {
                        AddType(context.ResolveType(objectInterface), context);
                    }
                });
            }
        }
コード例 #3
0
        public GraphType this[string typeName]
        {
            get
            {
                GraphType result = null;
                if (_types.ContainsKey(typeName))
                {
                    result = _types[typeName];
                }

                return(result);
            }
            set { _types[typeName] = value; }
        }
コード例 #4
0
ファイル: GraphType.cs プロジェクト: cmiagika/graphql-dotnet
 protected bool Equals(GraphType other)
 {
     return(string.Equals(Name, other.Name));
 }
コード例 #5
0
        public void AddType(GraphType type, TypeCollectionContext context)
        {
            if (type == null)
            {
                return;
            }

            var name = type.CollectTypes(context);

            _types[name] = type;

            type.Fields.Apply(field =>
            {
                AddTypeIfNotRegistered(field.Type, context);

                field.Arguments?.Apply(arg =>
                {
                    AddTypeIfNotRegistered(arg.Type, context);
                });
            });

            if (type is ObjectGraphType)
            {
                var obj = (ObjectGraphType)type;
                obj.Interfaces.Apply(objectInterface =>
                {
                    AddTypeIfNotRegistered(objectInterface, context);

                    var interfaceInstance = this[objectInterface] as InterfaceGraphType;
                    if (interfaceInstance != null)
                    {
                        interfaceInstance.AddPossibleType(obj);

                        if (interfaceInstance.ResolveType == null && obj.IsTypeOf == null)
                        {
                            throw new ExecutionError((
                                                         "Interface type {0} does not provide a \"resolveType\" function " +
                                                         "and possible Type \"{1}\" does not provide a \"isTypeOf\" function.  " +
                                                         "There is no way to resolve this possible type during execution.")
                                                     .ToFormat(interfaceInstance, obj));
                        }
                    }
                });
            }

            if (type is UnionGraphType)
            {
                var union = (UnionGraphType)type;

                if (!union.Types.Any())
                {
                    throw new ExecutionError("Must provide types for Union {0}.".ToFormat(union));
                }

                union.Types.Apply(unionedType =>
                {
                    AddTypeIfNotRegistered(unionedType, context);

                    var objType = this[unionedType] as ObjectGraphType;

                    if (union.ResolveType == null && objType != null && objType.IsTypeOf == null)
                    {
                        throw new ExecutionError((
                                                     "Union type {0} does not provide a \"resolveType\" function" +
                                                     "and possible Type \"{1}\" does not provide a \"isTypeOf\" function.  " +
                                                     "There is no way to resolve this possible type during execution.")
                                                 .ToFormat(union, objType));
                    }

                    union.AddPossibleType(objType);
                });
            }
        }
コード例 #6
0
 public virtual bool IsPossibleType(GraphType type)
 {
     return(PossibleTypes.Any(x => x.Equals(type)));
 }