Skip to content

Commit

Permalink
nested field unique name
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Hladik committed Jun 21, 2019
1 parent 40b75a0 commit 7a3ca86
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public IFieldPartitioning ResolvePartition(Partitioning key)
return partitionResolver(key);
}

public (IGraphType ResolveType, ValueResolver Resolver) GetGraphType(ISchemaEntity schema, IField field)
public (IGraphType ResolveType, ValueResolver Resolver) GetGraphType(ISchemaEntity schema, IField field, string fieldName)
{
return field.Accept(new QueryGraphTypeVisitor(schema, GetContentType, this, assetListType));
return field.Accept(new QueryGraphTypeVisitor(schema, GetContentType, this, assetListType, fieldName));
}

public IGraphType GetAssetType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public interface IGraphModel

IGraphType GetContentDataType(Guid schemaId);

(IGraphType ResolveType, ValueResolver Resolver) GetGraphType(ISchemaEntity schema, IField field);
(IGraphType ResolveType, ValueResolver Resolver) GetGraphType(ISchemaEntity schema, IField field, string fieldName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Initialize(IGraphModel model, ISchemaEntity schema)

foreach (var (field, fieldName, typeName) in schema.SchemaDef.Fields.SafeFields())
{
var (resolvedType, valueResolver) = model.GetGraphType(schema, field);
var (resolvedType, valueResolver) = model.GetGraphType(schema, field, fieldName);

if (valueResolver != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
{
public sealed class NestedGraphType : ObjectGraphType<JsonObject>
{
public NestedGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field)
public NestedGraphType(IGraphModel model, ISchemaEntity schema, IArrayField field, string fieldName)
{
var schemaType = schema.TypeName();
var schemaName = schema.DisplayName();

var fieldName = field.DisplayName();
var fieldDisplayName = field.DisplayName();

Name = $"{schemaType}{field.Name.ToCamelCase()}ChildDto";
Name = $"{schemaType}{fieldName}ChildDto";

foreach (var (nestedField, nestedName, _) in field.Fields.SafeFields())
{
var fieldInfo = model.GetGraphType(schema, nestedField);
var fieldInfo = model.GetGraphType(schema, nestedField, nestedName);

if (fieldInfo.ResolveType != null)
{
Expand All @@ -38,12 +38,12 @@ public NestedGraphType(IGraphModel model, ISchemaEntity schema, IArrayField fiel
Name = nestedName,
Resolver = resolver,
ResolvedType = fieldInfo.ResolveType,
Description = $"The {fieldName}/{nestedField.DisplayName()} nested field."
Description = $"The {fieldDisplayName}/{nestedField.DisplayName()} nested field."
});
}
}

Description = $"The structure of the {schemaName}.{fieldName} nested schema.";
Description = $"The structure of the {schemaName}.{fieldDisplayName} nested schema.";
}

private static FuncFieldResolver<object> ValueResolver(NestedField nestedField, (IGraphType ResolveType, ValueResolver Resolver) fieldInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ public sealed class QueryGraphTypeVisitor : IFieldVisitor<(IGraphType ResolveTyp
private readonly Func<Guid, IGraphType> schemaResolver;
private readonly IGraphModel model;
private readonly IGraphType assetListType;
private readonly string fieldName;

public QueryGraphTypeVisitor(ISchemaEntity schema, Func<Guid, IGraphType> schemaResolver, IGraphModel model, IGraphType assetListType)
public QueryGraphTypeVisitor(ISchemaEntity schema, Func<Guid, IGraphType> schemaResolver, IGraphModel model, IGraphType assetListType, string fieldName)
{
this.model = model;
this.assetListType = assetListType;
this.schema = schema;
this.schemaResolver = schemaResolver;
this.fieldName = fieldName;
}

public (IGraphType ResolveType, ValueResolver Resolver) Visit(IArrayField field)
{
return ResolveNested(field);
return ResolveNested(field, this.fieldName);
}

public (IGraphType ResolveType, ValueResolver Resolver) Visit(IField<AssetsFieldProperties> field)
Expand Down Expand Up @@ -91,9 +93,9 @@ private static (IGraphType ResolveType, ValueResolver Resolver) ResolveDefault(I
return (type, NoopResolver);
}

private (IGraphType ResolveType, ValueResolver Resolver) ResolveNested(IArrayField field)
private (IGraphType ResolveType, ValueResolver Resolver) ResolveNested(IArrayField field, string fieldName)
{
var schemaFieldType = new ListGraphType(new NonNullGraphType(new NestedGraphType(model, schema, field)));
var schemaFieldType = new ListGraphType(new NonNullGraphType(new NestedGraphType(model, schema, field, fieldName)));

return (schemaFieldType, NoopResolver);
}
Expand Down

0 comments on commit 7a3ca86

Please sign in to comment.