Example #1
0
            protected override UnionGraphType ToUnionType(GraphQLUnionTypeDefinition unionDef)
            {
                var type = base.ToUnionType(unionDef);

                type.ResolveType = _ => null;
                return(type);
            }
        protected virtual UnionGraphType ToUnionType(GraphQLUnionTypeDefinition unionDef)
        {
            var name       = (string)unionDef.Name.Value;
            var typeConfig = Types.For(name);

            AssertKnownType(typeConfig);

            var type = new UnionGraphType
            {
                Name        = name,
                Description = typeConfig.Description ?? unionDef.Description?.Value.ToString() ?? unionDef.Comment?.Text.ToString(),
                ResolveType = typeConfig.ResolveType,
            }.SetAstType(unionDef);

            OverrideDeprecationReason(type, typeConfig.DeprecationReason);

            typeConfig.CopyMetadataTo(type);

            if (unionDef.Types?.Count > 0) // just in case
            {
                foreach (var x in unionDef.Types)
                {
                    string n = (string)x.Name.Value;
                    type.AddPossibleType((GetType(n) ?? new GraphQLTypeReference(n)) as IObjectGraphType);
                }
            }

            return(type);
        }
        public virtual GraphQLUnionTypeDefinition BeginVisitUnionTypeDefinition(GraphQLUnionTypeDefinition node)
        {
            if (node.Directives != null)
            {
                this.BeginVisitNodeCollection(node.Directives);
            }

            return(node);
        }
Example #4
0
        private string PrintUnionTypeDefinition(GraphQLUnionTypeDefinition node)
        {
            var name       = PrintName(node.Name);
            var directives = node.Directives?.Select(PrintDirective);
            var types      = node.Types?.Select(PrintNamedType);

            return(Join(new[]
            {
                "union",
                name,
                Join(directives, " "),
                types?.Any() == true
                        ? "= " + Join(types, " | ")
                        : string.Empty
            },
                        " "));
        }
Example #5
0
        protected virtual UnionGraphType ToUnionType(GraphQLUnionTypeDefinition unionDef)
        {
            var typeConfig = Types.For(unionDef.Name.Value);

            var type = new UnionGraphType();

            type.Name        = unionDef.Name.Value;
            type.Description = typeConfig.Description;
            type.ResolveType = typeConfig.ResolveType;

            CopyMetadata(type, typeConfig);

            var possibleTypes = unionDef.Types.Select(x => GetType(x.Name.Value));

            possibleTypes.Apply(x => type.AddPossibleType(x as IObjectGraphType));
            return(type);
        }
        protected virtual UnionGraphType ToUnionType(GraphQLUnionTypeDefinition unionDef)
        {
            var typeConfig = Types.For(unionDef.Name.Value);

            var type = new UnionGraphType
            {
                Name        = unionDef.Name.Value,
                Description = typeConfig.Description ?? unionDef.Comment?.Text,
                ResolveType = typeConfig.ResolveType
            };

            CopyMetadata(type, typeConfig);

            var possibleTypes = unionDef.Types.Select(x => GetType(x.Name.Value) ?? new GraphQLTypeReference(x.Name.Value));

            possibleTypes.Apply(x => type.AddPossibleType(x as IObjectGraphType));
            return(type);
        }
        protected virtual UnionGraphType ToUnionType(GraphQLUnionTypeDefinition unionDef)
        {
            var typeConfig = Types.For(unionDef.Name.Value);

            var type = new UnionGraphType
            {
                Name        = unionDef.Name.Value,
                Description = typeConfig.Description,
                ResolveType = typeConfig.ResolveType
            };

            ApplyDeprecatedDirective(unionDef.Directives, reason =>
            {
                type.DeprecationReason = typeConfig.DeprecationReason ?? reason;
            });

            CopyMetadata(type, typeConfig);

            var possibleTypes = unionDef.Types.Select(x => GetType(x.Name.Value));

            possibleTypes.Apply(x => type.AddPossibleType(x as IObjectGraphType));
            return(type);
        }
Example #8
0
 public UnionType(GraphQLUnionTypeDefinition op)
 {
     this.op = op;
 }