Exemplo n.º 1
0
 private bool IsReferencingThis(SchemaInfo other)
 {
     return(other.Schema.SchemaDef.Fields.Any(IsReferencingThis));
 }
Exemplo n.º 2
0
        public DataGraphType(Builder builder, SchemaInfo schemaInfo)
        {
            Name = schemaInfo.DataType;

            foreach (var fieldInfo in schemaInfo.Fields)
            {
                if (fieldInfo.Field.RawProperties is ComponentFieldProperties ||
                    fieldInfo.Field.RawProperties is ComponentsFieldProperties)
                {
                    var fieldGraphType = new ObjectGraphType
                    {
                        Name = fieldInfo.LocalizedType
                    };

                    var partitioning = builder.ResolvePartition(((RootField)fieldInfo.Field).Partitioning);

                    foreach (var partitionKey in partitioning.AllKeys)
                    {
                        fieldGraphType.AddField(new FieldType
                        {
                            Name         = partitionKey.EscapePartition(),
                            Arguments    = ContentActions.Json.Arguments,
                            ResolvedType = AllTypes.Json,
                            Resolver     = FieldVisitor.JsonPath,
                            Description  = fieldInfo.Field.RawProperties.Hints
                        }).WithSourceName(partitionKey);
                    }

                    fieldGraphType.Description = $"The dynamic structure of the {fieldInfo.DisplayName} field of the {schemaInfo.DisplayName} content type.";

                    AddField(new FieldType
                    {
                        Name         = fieldInfo.FieldNameDynamic,
                        ResolvedType = fieldGraphType,
                        Resolver     = ContentResolvers.Field
                    }).WithSourceName(fieldInfo);
                }
                else
                {
                    var(resolvedType, resolver, args) = builder.GetGraphType(fieldInfo);

                    if (resolver != null)
                    {
                        var fieldGraphType = new ObjectGraphType
                        {
                            Name = fieldInfo.LocalizedType
                        };

                        var partitioning = builder.ResolvePartition(((RootField)fieldInfo.Field).Partitioning);

                        foreach (var partitionKey in partitioning.AllKeys)
                        {
                            fieldGraphType.AddField(new FieldType
                            {
                                Name         = partitionKey.EscapePartition(),
                                Arguments    = args,
                                ResolvedType = resolvedType,
                                Resolver     = resolver,
                                Description  = fieldInfo.Field.RawProperties.Hints
                            }).WithSourceName(partitionKey);
                        }

                        fieldGraphType.Description = $"The structure of the {fieldInfo.DisplayName} field of the {schemaInfo.DisplayName} content type.";

                        AddField(new FieldType
                        {
                            Name         = fieldInfo.FieldName,
                            ResolvedType = fieldGraphType,
                            Resolver     = ContentResolvers.Field
                        }).WithSourceName(fieldInfo);
                    }
                }
            }

            Description = $"The structure of the {schemaInfo.DisplayName} data type.";
        }
Exemplo n.º 3
0
 public ContentGraphType(SchemaInfo schemaInfo)
 {
     // The name is used for equal comparison. Therefore it is important to treat it as readonly.
     Name = schemaInfo.ContentType;
 }
Exemplo n.º 4
0
        public void Initialize(Builder builder, SchemaInfo schemaInfo, IEnumerable <SchemaInfo> allSchemas)
        {
            var schemaId = schemaInfo.Schema.Id;

            IsTypeOf = value =>
            {
                return(value is IContentEntity content && content.SchemaId?.Id == schemaId);
            };

            AddField(ContentFields.Id);
            AddField(ContentFields.Version);
            AddField(ContentFields.Created);
            AddField(ContentFields.CreatedBy);
            AddField(ContentFields.CreatedByUser);
            AddField(ContentFields.EditToken);
            AddField(ContentFields.LastModified);
            AddField(ContentFields.LastModifiedBy);
            AddField(ContentFields.LastModifiedByUser);
            AddField(ContentFields.Status);
            AddField(ContentFields.StatusColor);
            AddField(ContentFields.NewStatus);
            AddField(ContentFields.NewStatusColor);
            AddField(ContentFields.Url);

            var contentDataType = new DataGraphType(builder, schemaInfo);

            if (contentDataType.Fields.Any())
            {
                AddField(new FieldType
                {
                    Name         = "data",
                    ResolvedType = new NonNullGraphType(contentDataType),
                    Resolver     = ContentResolvers.Data,
                    Description  = FieldDescriptions.ContentData
                });
            }

            var contentDataTypeFlat = new DataFlatGraphType(builder, schemaInfo);

            if (contentDataTypeFlat.Fields.Any())
            {
                AddField(new FieldType
                {
                    Name         = "flatData",
                    ResolvedType = new NonNullGraphType(contentDataTypeFlat),
                    Resolver     = ContentResolvers.FlatData,
                    Description  = FieldDescriptions.ContentFlatData
                });
            }

            foreach (var other in allSchemas.Where(x => IsReference(x, schemaInfo)))
            {
                AddReferencingQueries(builder, other);
            }

            foreach (var other in allSchemas.Where(x => IsReference(schemaInfo, x)))
            {
                AddReferencesQueries(builder, other);
            }

            AddResolvedInterface(SharedTypes.ContentInterface);

            Description = $"The structure of a {schemaInfo.DisplayName} content type.";
        }
Exemplo n.º 5
0
 private static bool IsReference(SchemaInfo from, SchemaInfo to)
 {
     return(from.Schema.SchemaDef.Fields.Any(x => IsReferencing(x, to.Schema.Id)));
 }