public void AddType <TType>(TypeCollectionContext context)
            where TType : GraphType
        {
            var instance = context.ResolveType(typeof(TType));

            AddType(instance, context);
        }
        public override string CollectTypes(TypeCollectionContext context)
        {
            if (!string.IsNullOrWhiteSpace(_remoteLocation) && !string.IsNullOrWhiteSpace(_name))
            {
                // get remote server information
                // if we haven't fetched the remote types for this remote:
                if (!RemoteServerSchemas.TryGetValue(_remoteLocation, out var schema))
                {
                    throw new Exception($"Schema not already loaded for remote {_remoteLocation}");
                }

                // get type
                if (!TryGetFieldTypeFromRemoteSchema(schema, _name, out var type))
                {
                    // if no type found: fail
                    // TODO: fail better
                    throw new Exception($"Failed to find type '{_name}' in remote '{_remoteLocation}' schema");
                }

                Name = $"{_remoteLocation}.{_name}";

                if (!_hasAddedFields)
                {
                    var fields = GetFieldsForFieldType(_remoteLocation, type).Where(f => f != null).ToList();
                    foreach (var field in fields)
                    {
                        AddField(field);
                    }

                    _hasAddedFields = true;
                }
            }

            return(base.CollectTypes(context));
        }
Exemplo n.º 3
0
        public override string CollectTypes(TypeCollectionContext context)
        {
            var innerType = context.ResolveType(Type);
            var name      = innerType.CollectTypes(context);

            context.AddType(name, innerType, context);
            return(Name);
        }
        private void AddTypeIfNotRegistered(Type type, TypeCollectionContext context)
        {
            var foundType = this[type];

            if (foundType == null)
            {
                AddType(context.ResolveType(type), context);
            }
        }
        public void AddType <TType>()
            where TType : GraphType, new()
        {
            var context = new TypeCollectionContext(
                type => (GraphType)Activator.CreateInstance(type),
                (name, type, _) =>
            {
                _types[name] = type;
                _?.AddType(name, type, null);
            });

            AddType <TType>(context);
        }
Exemplo n.º 6
0
        public override string CollectTypes(TypeCollectionContext context)
        {
            Name = Name ?? typeof(T).Name;

            if (!_hasAddedFields)
            {
                var fields = GetFields().Where(f => f != null).ToList();
                foreach (var field in fields)
                {
                    AddField(field);
                }

                _hasAddedFields = true;
            }

            return(base.CollectTypes(context));
        }
        public static GraphTypesLookup Create(IEnumerable <GraphType> types, Func <Type, GraphType> resolveType)
        {
            var lookup = new GraphTypesLookup();

            var ctx = new TypeCollectionContext(resolveType, (name, graphType, context) =>
            {
                if (lookup[name] == null)
                {
                    lookup.AddType(graphType, context);
                }
            });

            foreach (var type in types)
            {
                lookup.AddType(type, ctx);
            }
            ;

            return(lookup);
        }
Exemplo n.º 8
0
 public string CollectTypes(TypeCollectionContext context)
 {
     return(Name);
 }
        public void AddType(GraphType type, TypeCollectionContext context)
        {
            if (type == null)
            {
                return;
            }

            var name = type.CollectTypes(context);

            _types[name] = type;

            bool isInput = type is InputObjectGraphType;

            foreach (var field in type.Fields)
            {
                field.Type = updateInputFieldType(isInput, field.Type);
                AddTypeIfNotRegistered(field.Type, context);

                if (field.Arguments != null)
                {
                    foreach (var arg in field.Arguments)
                    {
                        AddTypeIfNotRegistered(arg.Type, context);
                    }
                }
            }

            if (type is ObjectGraphType)
            {
                var obj = (ObjectGraphType)type;
                foreach (var objectInterface in obj.Interfaces)
                {
                    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);
                });
            }
        }
 public override string CollectTypes(TypeCollectionContext context)
 {
     context.AddType(staticEntry.Name, staticEntry, context);
     context.AddType(processEntry.Name, processEntry, context);
     return(base.CollectTypes(context));
 }