コード例 #1
0
        public ReferenceUnionGraphType(Builder builder, FieldInfo fieldInfo, ReadonlyList <DomainId>?schemaIds)
        {
            // The name is used for equal comparison. Therefore it is important to treat it as readonly.
            Name = fieldInfo.ReferenceType;

            if (schemaIds?.Any() == true)
            {
                foreach (var schemaId in schemaIds)
                {
                    var contentType = builder.GetContentType(schemaId);

                    if (contentType != null)
                    {
                        types[schemaId] = contentType;
                    }
                }
            }
            else
            {
                foreach (var(key, value) in builder.GetAllContentTypes())
                {
                    types[key.Schema.Id] = value;
                }
            }

            if (HasType)
            {
                foreach (var type in types)
                {
                    AddPossibleType(type.Value);
                }

                ResolveType = value =>
                {
                    if (value is IContentEntity content)
                    {
                        return(types.GetOrDefault(content.SchemaId.Id));
                    }

                    return(null);
                };
            }
        }
コード例 #2
0
        public ComponentUnionGraphType(Builder builder, FieldInfo fieldInfo, ReadonlyList <DomainId>?schemaIds)
        {
            // The name is used for equal comparison. Therefore it is important to treat it as readonly.
            Name = fieldInfo.ReferenceType;

            if (schemaIds?.Any() == true)
            {
                foreach (var schemaId in schemaIds)
                {
                    var contentType = builder.GetComponentType(schemaId);

                    if (contentType != null)
                    {
                        types[schemaId.ToString()] = contentType;
                    }
                }
            }

            if (HasType)
            {
                foreach (var type in types)
                {
                    AddPossibleType(type.Value);
                }

                ResolveType = value =>
                {
                    if (value is JsonObject component && component.TryGetValue <JsonString>(Component.Discriminator, out var schemaId))
                    {
                        return(types.GetOrDefault(schemaId.Value));
                    }

                    return(null);
                };
            }
        }