Browse Source

be more conservative with null checks.

pull/967/head
Sebastian 3 years ago
parent
commit
b033f25c63
  1. 55
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationMutations.cs
  2. 14
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs
  3. 8
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Builder.cs
  4. 18
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentGraphType.cs
  5. 50
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataInputGraphType.cs
  6. 18
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/NestedInputGraphType.cs
  7. 2
      backend/src/Squidex.Infrastructure/Diagnostics/Diagnoser.cs

55
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationMutations.cs

@ -7,7 +7,6 @@
using GraphQL.Types;
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents;
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Primitives;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types;
@ -17,15 +16,29 @@ internal sealed class ApplicationMutations : ObjectGraphType
{
foreach (var schemaInfo in schemas.Where(x => x.Fields.Count > 0))
{
var contentType = new NonNullGraphType(builder.GetContentType(schemaInfo));
var inputType = new DataInputGraphType(builder, schemaInfo);
// We cannot check before if all fields can be resolved. This might not be the case, e.g. if a reference is empty.
if (inputType.Fields.Count == 0)
{
continue;
}
var contentType = builder.GetContentType(schemaInfo);
// We cannot check before if all fields can be resolved. This might not be the case, e.g. if a reference is empty.
if (contentType == null || contentType.Fields.Count == 0)
{
continue;
}
var nonNullContentType = new NonNullGraphType(contentType);
AddField(new FieldType
{
Name = $"create{schemaInfo.TypeName}Content",
Arguments = ContentActions.Create.Arguments(inputType),
ResolvedType = contentType,
ResolvedType = nonNullContentType,
Resolver = ContentActions.Create.Resolver,
Description = $"Creates an {schemaInfo.DisplayName} content."
}).WithSchemaNamedId(schemaInfo);
@ -34,7 +47,7 @@ internal sealed class ApplicationMutations : ObjectGraphType
{
Name = $"update{schemaInfo.TypeName}Content",
Arguments = ContentActions.Update.Arguments(inputType),
ResolvedType = contentType,
ResolvedType = nonNullContentType,
Resolver = ContentActions.Update.Resolver,
Description = $"Update an {schemaInfo.DisplayName} content by id."
}).WithSchemaNamedId(schemaInfo);
@ -43,7 +56,7 @@ internal sealed class ApplicationMutations : ObjectGraphType
{
Name = $"upsert{schemaInfo.TypeName}Content",
Arguments = ContentActions.Upsert.Arguments(inputType),
ResolvedType = contentType,
ResolvedType = nonNullContentType,
Resolver = ContentActions.Upsert.Resolver,
Description = $"Upsert an {schemaInfo.DisplayName} content by id."
}).WithSchemaNamedId(schemaInfo);
@ -52,38 +65,10 @@ internal sealed class ApplicationMutations : ObjectGraphType
{
Name = $"patch{schemaInfo.TypeName}Content",
Arguments = ContentActions.Patch.Arguments(inputType),
ResolvedType = contentType,
ResolvedType = nonNullContentType,
Resolver = ContentActions.Patch.Resolver,
Description = $"Patch an {schemaInfo.DisplayName} content by id."
}).WithSchemaNamedId(schemaInfo);
AddField(new FieldType
{
Name = $"change{schemaInfo.TypeName}Content",
Arguments = ContentActions.ChangeStatus.Arguments,
ResolvedType = contentType,
Resolver = ContentActions.ChangeStatus.Resolver,
Description = $"Change a {schemaInfo.DisplayName} content."
}).WithSchemaNamedId(schemaInfo);
AddField(new FieldType
{
Name = $"delete{schemaInfo.TypeName}Content",
Arguments = ContentActions.Delete.Arguments,
ResolvedType = EntitySavedGraphType.NonNull,
Resolver = ContentActions.Delete.Resolver,
Description = $"Delete an {schemaInfo.DisplayName} content."
}).WithSchemaNamedId(schemaInfo);
AddField(new FieldType
{
Name = $"publish{schemaInfo.TypeName}Content",
Arguments = ContentActions.ChangeStatus.Arguments,
ResolvedType = contentType,
Resolver = ContentActions.ChangeStatus.Resolver,
Description = $"Publish a {schemaInfo.DisplayName} content.",
DeprecationReason = $"Use 'change{schemaInfo.TypeName}Content' instead"
}).WithSchemaNamedId(schemaInfo);
}
Description = "The app mutations.";

14
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs

@ -22,6 +22,11 @@ internal sealed class ApplicationQueries : ObjectGraphType
{
var contentType = builder.GetContentType(schemaInfo);
if (contentType == null)
{
continue;
}
AddContentFind(schemaInfo, contentType);
AddContentQueries(builder, schemaInfo, contentType);
}
@ -52,13 +57,18 @@ internal sealed class ApplicationQueries : ObjectGraphType
Description = $"Query {schemaInfo.DisplayName} content items."
}).WithSchemaId(schemaInfo);
var resultType = builder.GetContentResultType(schemaInfo);
var contentResultTyp = builder.GetContentResultType(schemaInfo);
if (contentResultTyp == null)
{
return;
}
AddField(new FieldType
{
Name = $"query{schemaInfo.TypeName}ContentsWithTotal",
Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = resultType,
ResolvedType = contentResultTyp,
Resolver = ContentActions.QueryOrReferencing.QueryWithTotal,
Description = $"Query {schemaInfo.DisplayName} content items with total count."
}).WithSchemaId(schemaInfo);

8
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Builder.cs

@ -147,9 +147,9 @@ internal sealed class Builder
return fieldInfo.Field.Accept(fieldInputVisitor, fieldInfo);
}
public IObjectGraphType GetContentResultType(SchemaInfo schemaId)
public IObjectGraphType? GetContentResultType(SchemaInfo schemaId)
{
return contentResultTypes.GetValueOrDefault(schemaId)!;
return contentResultTypes.GetValueOrDefault(schemaId);
}
public IObjectGraphType? GetContentType(DomainId schemaId)
@ -157,9 +157,9 @@ internal sealed class Builder
return contentTypes.FirstOrDefault(x => x.Key.Schema.Id == schemaId).Value;
}
public IObjectGraphType GetContentType(SchemaInfo schemaId)
public IObjectGraphType? GetContentType(SchemaInfo schemaId)
{
return contentTypes.GetValueOrDefault(schemaId)!;
return contentTypes.GetValueOrDefault(schemaId);
}
public IObjectGraphType? GetComponentType(DomainId schemaId)

18
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentGraphType.cs

@ -98,13 +98,18 @@ internal sealed class ContentGraphType : ObjectGraphType<IEnrichedContentEntity>
Description = $"Query {referencingSchemaInfo.DisplayName} content items."
}).WithSchemaId(referencingSchemaInfo);
var contentResultsTyp = builder.GetContentResultType(referencingSchemaInfo);
var contentResultTyp = builder.GetContentResultType(referencingSchemaInfo);
if (contentResultTyp == null)
{
return;
}
AddField(new FieldType
{
Name = $"referencing{referencingSchemaInfo.TypeName}ContentsWithTotal",
Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = contentResultsTyp,
ResolvedType = contentResultTyp,
Resolver = ContentActions.QueryOrReferencing.ReferencingWithTotal,
Description = $"Query {referencingSchemaInfo.DisplayName} content items with total count."
}).WithSchemaId(referencingSchemaInfo);
@ -123,13 +128,18 @@ internal sealed class ContentGraphType : ObjectGraphType<IEnrichedContentEntity>
Description = $"Query {referencesSchemaInfo.DisplayName} content items."
}).WithSchemaId(referencesSchemaInfo);
var contentResultsTyp = builder.GetContentResultType(referencesSchemaInfo);
var contentResultTyp = builder.GetContentResultType(referencesSchemaInfo);
if (contentResultTyp == null)
{
return;
}
AddField(new FieldType
{
Name = $"references{referencesSchemaInfo.TypeName}ContentsWithTotal",
Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = contentResultsTyp,
ResolvedType = contentResultTyp,
Resolver = ContentActions.QueryOrReferencing.ReferencesWithTotal,
Description = $"Query {referencesSchemaInfo.DisplayName} content items with total count."
}).WithSchemaId(referencesSchemaInfo);

50
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataInputGraphType.cs

@ -25,36 +25,38 @@ internal sealed class DataInputGraphType : InputObjectGraphType
{
var resolvedType = builder.GetInputGraphType(fieldInfo);
if (resolvedType != null)
if (resolvedType == null)
{
var fieldGraphType = new InputObjectGraphType
{
// The name is used for equal comparison. Therefore it is important to treat it as readonly.
Name = fieldInfo.LocalizedInputType
};
var partitioning = builder.ResolvePartition(((RootField)fieldInfo.Field).Partitioning);
continue;
}
foreach (var partitionKey in partitioning.AllKeys)
{
fieldGraphType.AddField(new FieldType
{
Name = partitionKey.EscapePartition(),
ResolvedType = resolvedType,
Resolver = null,
Description = fieldInfo.Field.RawProperties.Hints
}).WithSourceName(partitionKey);
}
var fieldGraphType = new InputObjectGraphType
{
// The name is used for equal comparison. Therefore it is important to treat it as readonly.
Name = fieldInfo.LocalizedInputType
};
fieldGraphType.Description = $"The structure of the {fieldInfo.DisplayName} field of the {schemaInfo.DisplayName} content input type.";
var partitioning = builder.ResolvePartition(((RootField)fieldInfo.Field).Partitioning);
AddField(new FieldType
foreach (var partitionKey in partitioning.AllKeys)
{
fieldGraphType.AddField(new FieldType
{
Name = fieldInfo.FieldName,
ResolvedType = fieldGraphType,
Resolver = null
}).WithSourceName(fieldInfo);
Name = partitionKey.EscapePartition(),
ResolvedType = resolvedType,
Resolver = null,
Description = fieldInfo.Field.RawProperties.Hints
}).WithSourceName(partitionKey);
}
fieldGraphType.Description = $"The structure of the {fieldInfo.DisplayName} field of the {schemaInfo.DisplayName} content input type.";
AddField(new FieldType
{
Name = fieldInfo.FieldName,
ResolvedType = fieldGraphType,
Resolver = null
}).WithSourceName(fieldInfo);
}
Description = $"The structure of the {schemaInfo.DisplayName} data input type.";

18
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/NestedInputGraphType.cs

@ -22,16 +22,18 @@ internal sealed class NestedInputGraphType : InputObjectGraphType
{
var resolvedType = builder.GetInputGraphType(nestedFieldInfo);
if (resolvedType != null)
if (resolvedType == null)
{
AddField(new FieldType
{
Name = nestedFieldInfo.FieldName,
ResolvedType = resolvedType,
Resolver = null,
Description = nestedFieldInfo.Field.RawProperties.Hints
}).WithSourceName(nestedFieldInfo);
continue;
}
AddField(new FieldType
{
Name = nestedFieldInfo.FieldName,
ResolvedType = resolvedType,
Resolver = null,
Description = nestedFieldInfo.Field.RawProperties.Hints
}).WithSourceName(nestedFieldInfo);
}
Description = $"The structure of the {fieldInfo.DisplayName} nested schema.";

2
backend/src/Squidex.Infrastructure/Diagnostics/Diagnoser.cs

@ -127,7 +127,7 @@ public sealed class Diagnoser : IInitializable
if (process.ExitCode != 0)
{
ThrowHelper.InvalidOperationException($"Failed to execute tool. Got exit code: {process.ExitCode}.");
ThrowHelper.InvalidOperationException($"Failed to execute tool '{tool}'. Got exit code: {process.ExitCode}.");
}
await using (var fs = new FileStream(writtenFile, FileMode.Open))

Loading…
Cancel
Save