public NestedInputGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field) { var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); var fieldType = field.TypeName(); var fieldName = field.DisplayName(); Name = $"{schemaType}{fieldName}ChildDto"; foreach (var nestedField in field.Fields.Where(x => !x.IsHidden)) { var fieldInfo = model.GetGraphType(schema, nestedField); if (fieldInfo.ResolveType != null) { AddField(new FieldType { Name = nestedField.Name.ToCamelCase(), Resolver = null, ResolvedType = fieldInfo.ResolveType, Description = $"The {fieldName}/{nestedField.DisplayName()} nested field." }); } } Description = $"The structure of a {schemaName}.{fieldName} nested schema."; }
public NestedGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field, string fieldName) { var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); var fieldDisplayName = field.DisplayName(); Name = $"{schemaType}{fieldName}ChildDto"; foreach (var(nestedField, nestedName, typeName) in field.Fields.SafeFields().Where(x => x.Field.IsForApi())) { var(resolvedType, valueResolver, args) = model.GetGraphType(schema, nestedField, typeName); if (resolvedType != null && valueResolver != null) { AddField(new FieldType { Name = nestedName, Arguments = args, ResolvedType = resolvedType, Resolver = ContentResolvers.NestedValue(valueResolver, nestedField.Name), Description = $"The {fieldDisplayName}/{nestedField.DisplayName()} nested field." }); } } Description = $"The structure of the {schemaName}.{fieldDisplayName} nested schema."; }
public NestedInputGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field, string fieldName) { var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); var fieldDisplayName = field.DisplayName(); Name = $"{schemaType}{fieldName}InputChildDto"; foreach (var(nestedField, nestedName, typeName) in field.Fields.SafeFields().Where(x => x.Field.IsForApi(true))) { var resolvedType = model.GetInputGraphType(schema, nestedField, typeName); if (resolvedType != null) { AddField(new FieldType { Name = nestedName, ResolvedType = resolvedType, Resolver = null, Description = $"The {fieldDisplayName}/{nestedField.DisplayName()} nested field." }).WithSourceName(nestedField.Name); } } Description = $"The structure of the {schemaName}.{fieldDisplayName} nested schema."; }
public NestedGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field, string fieldName) { var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); var fieldDisplayName = field.DisplayName(); Name = $"{schemaType}{fieldName}ChildDto"; foreach (var(nestedField, nestedName, _) in field.Fields.SafeFields()) { var fieldInfo = model.GetGraphType(schema, nestedField, nestedName); if (fieldInfo.ResolveType != null) { var resolver = ValueResolver(nestedField, fieldInfo); AddField(new FieldType { Name = nestedName, Resolver = resolver, ResolvedType = fieldInfo.ResolveType, Description = $"The {fieldDisplayName}/{nestedField.DisplayName()} nested field." }); } } Description = $"The structure of the {schemaName}.{fieldDisplayName} nested schema."; }
public ContentDataGraphInputType(IGraphModel model, ISchemaEntity schema) { var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); Name = $"{schemaType}InputDto"; foreach (var field in schema.SchemaDef.Fields.Where(x => !x.IsHidden)) { var inputType = model.GetInputGraphType(field); if (inputType != null) { if (field.RawProperties.IsRequired) { inputType = new NonNullGraphType(inputType); } var fieldName = field.RawProperties.Label.WithFallback(field.Name); var fieldGraphType = new InputObjectGraphType { Name = $"{schemaType}Data{field.Name.ToPascalCase()}InputDto" }; var partition = model.ResolvePartition(field.Partitioning); foreach (var partitionItem in partition) { fieldGraphType.AddField(new FieldType { Name = partitionItem.Key, ResolvedType = inputType, Resolver = null, Description = field.RawProperties.Hints }); } fieldGraphType.Description = $"The input structure of the {fieldName} of a {schemaName} content type."; var fieldResolver = new FuncFieldResolver <NamedContentData, ContentFieldData>(c => c.Source.GetOrDefault(field.Name)); AddField(new FieldType { Name = field.Name.ToCamelCase(), Resolver = fieldResolver, ResolvedType = fieldGraphType, Description = $"The {fieldName} field." }); } } Description = $"The structure of a {schemaName} content type."; }
public void Initialize(IGraphModel model, ISchemaEntity schema, IEnumerable <ISchemaEntity> all, int pageSize) { var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); AddField(new FieldType { Name = "url", ResolvedType = AllTypes.NonNullString, Resolver = ContentResolvers.Url, Description = $"The url to the the {schemaName} content." }); var contentDataType = new ContentDataGraphType(schema, schemaName, schemaType, model); if (contentDataType.Fields.Any()) { AddField(new FieldType { Name = "data", ResolvedType = new NonNullGraphType(contentDataType), Resolver = ContentResolvers.Data, Description = $"The data of the {schemaName} content." }); } var contentDataTypeFlat = new ContentDataFlatGraphType(schema, schemaName, schemaType, model); if (contentDataTypeFlat.Fields.Any()) { AddField(new FieldType { Name = "flatData", ResolvedType = new NonNullGraphType(contentDataTypeFlat), Resolver = ContentResolvers.FlatData, Description = $"The flat data of the {schemaName} content." }); } foreach (var other in all.Where(x => References(x, schema))) { var referencingId = other.Id; var referencingType = other.TypeName(); var referencingName = other.DisplayName(); var contentType = model.GetContentType(referencingId); AddReferencingQueries(referencingId, referencingType, referencingName, contentType, pageSize); } }
public void Initialize(IGraphModel model, ISchemaEntity schema) { var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); Name = $"{schemaType}DataDto"; foreach (var(field, fieldName, typeName) in schema.SchemaDef.Fields.SafeFields()) { var(resolvedType, valueResolver) = model.GetGraphType(schema, field); if (valueResolver != null) { var displayName = field.DisplayName(); var fieldGraphType = new ObjectGraphType { Name = $"{schemaType}Data{typeName}Dto" }; var partition = model.ResolvePartition(field.Partitioning); foreach (var partitionItem in partition) { var key = partitionItem.Key; fieldGraphType.AddField(new FieldType { Name = key.EscapePartition(), Resolver = PartitionResolver(valueResolver, key), ResolvedType = resolvedType, Description = field.RawProperties.Hints }); } fieldGraphType.Description = $"The structure of the {displayName} field of the {schemaName} content type."; AddField(new FieldType { Name = fieldName, Resolver = FieldResolver(field), ResolvedType = fieldGraphType, Description = $"The {displayName} field." }); } } Description = $"The structure of the {schemaName} content type."; }
public NestedGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field) { var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); var fieldType = field.TypeName(); var fieldName = field.DisplayName(); Name = $"{schemaType}{fieldName}ChildDto"; foreach (var nestedField in field.Fields.Where(x => !x.IsHidden)) { var fieldInfo = model.GetGraphType(schema, nestedField); if (fieldInfo.ResolveType != null) { var resolver = new FuncFieldResolver <object>(c => { if (((JObject)c.Source).TryGetValue(nestedField.Name, out var value)) { return(fieldInfo.Resolver(value, c)); } else { return(fieldInfo); } }); AddField(new FieldType { Name = nestedField.Name.ToCamelCase(), Resolver = resolver, ResolvedType = fieldInfo.ResolveType, Description = $"The {fieldName}/{nestedField.DisplayName()} nested field." }); } } Description = $"The structure of the {schemaName}.{fieldName} nested schema."; }
public ContentGraphType(ISchemaEntity schema) { schemaId = schema.Id; var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); Name = schemaType.SafeTypeName(); AddField(ContentFields.Id); AddField(ContentFields.Version); AddField(ContentFields.Created); AddField(ContentFields.CreatedBy); AddField(ContentFields.LastModified); AddField(ContentFields.LastModifiedBy); AddField(ContentFields.Status); AddField(ContentFields.StatusColor); AddResolvedInterface(ContentInterfaceGraphType.Instance); Description = $"The structure of a {schemaName} content type."; IsTypeOf = CheckType; }
public ContentGraphType(ISchemaEntity schema) { this.schema = schema; schemaType = schema.TypeName(); schemaName = schema.DisplayName(); Name = $"{schemaType}"; AddField(new FieldType { Name = "id", ResolvedType = AllTypes.NonNullGuid, Resolver = Resolve(x => x.Id), Description = $"The id of the {schemaName} content." }); AddField(new FieldType { Name = "version", ResolvedType = AllTypes.NonNullInt, Resolver = Resolve(x => x.Version), Description = $"The version of the {schemaName} content." }); AddField(new FieldType { Name = "created", ResolvedType = AllTypes.NonNullDate, Resolver = Resolve(x => x.Created), Description = $"The date and time when the {schemaName} content has been created." }); AddField(new FieldType { Name = "createdBy", ResolvedType = AllTypes.NonNullString, Resolver = Resolve(x => x.CreatedBy.ToString()), Description = $"The user that has created the {schemaName} content." }); AddField(new FieldType { Name = "lastModified", ResolvedType = AllTypes.NonNullDate, Resolver = Resolve(x => x.LastModified), Description = $"The date and time when the {schemaName} content has been modified last." }); AddField(new FieldType { Name = "lastModifiedBy", ResolvedType = AllTypes.NonNullString, Resolver = Resolve(x => x.LastModifiedBy.ToString()), Description = $"The user that has updated the {schemaName} content last." }); AddField(new FieldType { Name = "status", ResolvedType = AllTypes.NonNullString, Resolver = Resolve(x => x.Status.Name.ToUpperInvariant()), Description = $"The the status of the {schemaName} content." }); AddField(new FieldType { Name = "statusColor", ResolvedType = AllTypes.NonNullString, Resolver = Resolve(x => x.StatusColor), Description = $"The color status of the {schemaName} content." }); Interface <ContentInterfaceGraphType>(); Description = $"The structure of a {schemaName} content type."; IsTypeOf = CheckType; }
public static string DisplayName(this ISchemaEntity schema) { return(schema.SchemaDef.Properties.Label.WithFallback(schema.TypeName())); }
public void Initialize(IGraphModel model, ISchemaEntity schema) { var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); Name = $"{schemaType}DataDto"; foreach (var field in schema.SchemaDef.Fields.ForApi()) { var(resolvedType, valueResolver) = model.GetGraphType(schema, field); if (valueResolver != null) { var fieldType = field.TypeName(); var fieldName = field.DisplayName(); var fieldGraphType = new ObjectGraphType { Name = $"{schemaType}Data{fieldType}Dto" }; var partition = model.ResolvePartition(field.Partitioning); foreach (var partitionItem in partition) { var key = partitionItem.Key; var partitionResolver = new FuncFieldResolver <object>(c => { if (((ContentFieldData)c.Source).TryGetValue(key, out var value)) { return(valueResolver(value, c)); } else { return(null); } }); fieldGraphType.AddField(new FieldType { Name = key.EscapePartition(), Resolver = partitionResolver, ResolvedType = resolvedType, Description = field.RawProperties.Hints }); } fieldGraphType.Description = $"The structure of the {fieldName} field of the {schemaName} content type."; var fieldResolver = new FuncFieldResolver <NamedContentData, IReadOnlyDictionary <string, IJsonValue> >(c => { return(c.Source.GetOrDefault(field.Name)); }); AddField(new FieldType { Name = field.Name.ToCamelCase(), Resolver = fieldResolver, ResolvedType = fieldGraphType, Description = $"The {fieldName} field." }); } } Description = $"The structure of the {schemaName} content type."; }
public void Initialize(IGraphModel model, ISchemaEntity schema, IComplexGraphType contentDataType) { var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); Name = $"{schemaType}Dto"; AddField(new FieldType { Name = "id", ResolvedType = AllTypes.NonNullGuid, Resolver = Resolve(x => x.Id), Description = $"The id of the {schemaName} content." }); AddField(new FieldType { Name = "version", ResolvedType = AllTypes.NonNullInt, Resolver = Resolve(x => x.Version), Description = $"The version of the {schemaName} content." }); AddField(new FieldType { Name = "created", ResolvedType = AllTypes.NonNullDate, Resolver = Resolve(x => x.Created.ToDateTimeUtc()), Description = $"The date and time when the {schemaName} content has been created." }); AddField(new FieldType { Name = "createdBy", ResolvedType = AllTypes.NonNullString, Resolver = Resolve(x => x.CreatedBy.ToString()), Description = $"The user that has created the {schemaName} content." }); AddField(new FieldType { Name = "lastModified", ResolvedType = AllTypes.NonNullDate, Resolver = Resolve(x => x.LastModified.ToDateTimeUtc()), Description = $"The date and time when the {schemaName} content has been modified last." }); AddField(new FieldType { Name = "lastModifiedBy", ResolvedType = AllTypes.NonNullString, Resolver = Resolve(x => x.LastModifiedBy.ToString()), Description = $"The user that has updated the {schemaName} content last." }); AddField(new FieldType { Name = "url", ResolvedType = AllTypes.NonNullString, Resolver = model.ResolveContentUrl(schema), Description = $"The url to the the {schemaName} content." }); if (contentDataType.Fields.Any()) { AddField(new FieldType { Name = "data", ResolvedType = new NonNullGraphType(contentDataType), Resolver = Resolve(x => x.Data), Description = $"The data of the {schemaName} content." }); } Description = $"The structure of a {schemaName} content type."; }
public ContentGraphType(ISchemaEntity schema) { schemaId = schema.Id; var schemaType = schema.TypeName(); var schemaName = schema.DisplayName(); Name = schemaType.SafeTypeName(); AddField(new FieldType { Name = "id", ResolvedType = AllTypes.NonNullString, Resolver = EntityResolvers.Id, Description = $"The id of the {schemaName} content." }); AddField(new FieldType { Name = "version", ResolvedType = AllTypes.NonNullInt, Resolver = EntityResolvers.Version, Description = $"The version of the {schemaName} content." }); AddField(new FieldType { Name = "created", ResolvedType = AllTypes.NonNullDate, Resolver = EntityResolvers.Created, Description = $"The date and time when the {schemaName} content has been created." }); AddField(new FieldType { Name = "createdBy", ResolvedType = AllTypes.NonNullString, Resolver = EntityResolvers.CreatedBy, Description = $"The user that has created the {schemaName} content." }); AddField(new FieldType { Name = "lastModified", ResolvedType = AllTypes.NonNullDate, Resolver = EntityResolvers.LastModified, Description = $"The date and time when the {schemaName} content has been modified last." }); AddField(new FieldType { Name = "lastModifiedBy", ResolvedType = AllTypes.NonNullString, Resolver = EntityResolvers.LastModifiedBy, Description = $"The user that has updated the {schemaName} content last." }); AddField(new FieldType { Name = "status", ResolvedType = AllTypes.NonNullString, Resolver = ContentResolvers.Status, Description = $"The the status of the {schemaName} content." }); AddField(new FieldType { Name = "statusColor", ResolvedType = AllTypes.NonNullString, Resolver = ContentResolvers.StatusColor, Description = $"The color status of the {schemaName} content." }); Interface <ContentInterfaceGraphType>(); Description = $"The structure of a {schemaName} content type."; IsTypeOf = CheckType; }