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 GraphQL.Types;
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents; 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; 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)) foreach (var schemaInfo in schemas.Where(x => x.Fields.Count > 0))
{ {
var contentType = new NonNullGraphType(builder.GetContentType(schemaInfo));
var inputType = new DataInputGraphType(builder, 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 AddField(new FieldType
{ {
Name = $"create{schemaInfo.TypeName}Content", Name = $"create{schemaInfo.TypeName}Content",
Arguments = ContentActions.Create.Arguments(inputType), Arguments = ContentActions.Create.Arguments(inputType),
ResolvedType = contentType, ResolvedType = nonNullContentType,
Resolver = ContentActions.Create.Resolver, Resolver = ContentActions.Create.Resolver,
Description = $"Creates an {schemaInfo.DisplayName} content." Description = $"Creates an {schemaInfo.DisplayName} content."
}).WithSchemaNamedId(schemaInfo); }).WithSchemaNamedId(schemaInfo);
@ -34,7 +47,7 @@ internal sealed class ApplicationMutations : ObjectGraphType
{ {
Name = $"update{schemaInfo.TypeName}Content", Name = $"update{schemaInfo.TypeName}Content",
Arguments = ContentActions.Update.Arguments(inputType), Arguments = ContentActions.Update.Arguments(inputType),
ResolvedType = contentType, ResolvedType = nonNullContentType,
Resolver = ContentActions.Update.Resolver, Resolver = ContentActions.Update.Resolver,
Description = $"Update an {schemaInfo.DisplayName} content by id." Description = $"Update an {schemaInfo.DisplayName} content by id."
}).WithSchemaNamedId(schemaInfo); }).WithSchemaNamedId(schemaInfo);
@ -43,7 +56,7 @@ internal sealed class ApplicationMutations : ObjectGraphType
{ {
Name = $"upsert{schemaInfo.TypeName}Content", Name = $"upsert{schemaInfo.TypeName}Content",
Arguments = ContentActions.Upsert.Arguments(inputType), Arguments = ContentActions.Upsert.Arguments(inputType),
ResolvedType = contentType, ResolvedType = nonNullContentType,
Resolver = ContentActions.Upsert.Resolver, Resolver = ContentActions.Upsert.Resolver,
Description = $"Upsert an {schemaInfo.DisplayName} content by id." Description = $"Upsert an {schemaInfo.DisplayName} content by id."
}).WithSchemaNamedId(schemaInfo); }).WithSchemaNamedId(schemaInfo);
@ -52,38 +65,10 @@ internal sealed class ApplicationMutations : ObjectGraphType
{ {
Name = $"patch{schemaInfo.TypeName}Content", Name = $"patch{schemaInfo.TypeName}Content",
Arguments = ContentActions.Patch.Arguments(inputType), Arguments = ContentActions.Patch.Arguments(inputType),
ResolvedType = contentType, ResolvedType = nonNullContentType,
Resolver = ContentActions.Patch.Resolver, Resolver = ContentActions.Patch.Resolver,
Description = $"Patch an {schemaInfo.DisplayName} content by id." Description = $"Patch an {schemaInfo.DisplayName} content by id."
}).WithSchemaNamedId(schemaInfo); }).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."; 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); var contentType = builder.GetContentType(schemaInfo);
if (contentType == null)
{
continue;
}
AddContentFind(schemaInfo, contentType); AddContentFind(schemaInfo, contentType);
AddContentQueries(builder, schemaInfo, contentType); AddContentQueries(builder, schemaInfo, contentType);
} }
@ -52,13 +57,18 @@ internal sealed class ApplicationQueries : ObjectGraphType
Description = $"Query {schemaInfo.DisplayName} content items." Description = $"Query {schemaInfo.DisplayName} content items."
}).WithSchemaId(schemaInfo); }).WithSchemaId(schemaInfo);
var resultType = builder.GetContentResultType(schemaInfo); var contentResultTyp = builder.GetContentResultType(schemaInfo);
if (contentResultTyp == null)
{
return;
}
AddField(new FieldType AddField(new FieldType
{ {
Name = $"query{schemaInfo.TypeName}ContentsWithTotal", Name = $"query{schemaInfo.TypeName}ContentsWithTotal",
Arguments = ContentActions.QueryOrReferencing.Arguments, Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = resultType, ResolvedType = contentResultTyp,
Resolver = ContentActions.QueryOrReferencing.QueryWithTotal, Resolver = ContentActions.QueryOrReferencing.QueryWithTotal,
Description = $"Query {schemaInfo.DisplayName} content items with total count." Description = $"Query {schemaInfo.DisplayName} content items with total count."
}).WithSchemaId(schemaInfo); }).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); 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) public IObjectGraphType? GetContentType(DomainId schemaId)
@ -157,9 +157,9 @@ internal sealed class Builder
return contentTypes.FirstOrDefault(x => x.Key.Schema.Id == schemaId).Value; 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) 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." Description = $"Query {referencingSchemaInfo.DisplayName} content items."
}).WithSchemaId(referencingSchemaInfo); }).WithSchemaId(referencingSchemaInfo);
var contentResultsTyp = builder.GetContentResultType(referencingSchemaInfo); var contentResultTyp = builder.GetContentResultType(referencingSchemaInfo);
if (contentResultTyp == null)
{
return;
}
AddField(new FieldType AddField(new FieldType
{ {
Name = $"referencing{referencingSchemaInfo.TypeName}ContentsWithTotal", Name = $"referencing{referencingSchemaInfo.TypeName}ContentsWithTotal",
Arguments = ContentActions.QueryOrReferencing.Arguments, Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = contentResultsTyp, ResolvedType = contentResultTyp,
Resolver = ContentActions.QueryOrReferencing.ReferencingWithTotal, Resolver = ContentActions.QueryOrReferencing.ReferencingWithTotal,
Description = $"Query {referencingSchemaInfo.DisplayName} content items with total count." Description = $"Query {referencingSchemaInfo.DisplayName} content items with total count."
}).WithSchemaId(referencingSchemaInfo); }).WithSchemaId(referencingSchemaInfo);
@ -123,13 +128,18 @@ internal sealed class ContentGraphType : ObjectGraphType<IEnrichedContentEntity>
Description = $"Query {referencesSchemaInfo.DisplayName} content items." Description = $"Query {referencesSchemaInfo.DisplayName} content items."
}).WithSchemaId(referencesSchemaInfo); }).WithSchemaId(referencesSchemaInfo);
var contentResultsTyp = builder.GetContentResultType(referencesSchemaInfo); var contentResultTyp = builder.GetContentResultType(referencesSchemaInfo);
if (contentResultTyp == null)
{
return;
}
AddField(new FieldType AddField(new FieldType
{ {
Name = $"references{referencesSchemaInfo.TypeName}ContentsWithTotal", Name = $"references{referencesSchemaInfo.TypeName}ContentsWithTotal",
Arguments = ContentActions.QueryOrReferencing.Arguments, Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = contentResultsTyp, ResolvedType = contentResultTyp,
Resolver = ContentActions.QueryOrReferencing.ReferencesWithTotal, Resolver = ContentActions.QueryOrReferencing.ReferencesWithTotal,
Description = $"Query {referencesSchemaInfo.DisplayName} content items with total count." Description = $"Query {referencesSchemaInfo.DisplayName} content items with total count."
}).WithSchemaId(referencesSchemaInfo); }).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); var resolvedType = builder.GetInputGraphType(fieldInfo);
if (resolvedType != null) if (resolvedType == null)
{ {
var fieldGraphType = new InputObjectGraphType continue;
{ }
// 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);
foreach (var partitionKey in partitioning.AllKeys) var fieldGraphType = new InputObjectGraphType
{ {
fieldGraphType.AddField(new FieldType // The name is used for equal comparison. Therefore it is important to treat it as readonly.
{ Name = fieldInfo.LocalizedInputType
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."; var partitioning = builder.ResolvePartition(((RootField)fieldInfo.Field).Partitioning);
AddField(new FieldType foreach (var partitionKey in partitioning.AllKeys)
{
fieldGraphType.AddField(new FieldType
{ {
Name = fieldInfo.FieldName, Name = partitionKey.EscapePartition(),
ResolvedType = fieldGraphType, ResolvedType = resolvedType,
Resolver = null Resolver = null,
}).WithSourceName(fieldInfo); 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."; 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); var resolvedType = builder.GetInputGraphType(nestedFieldInfo);
if (resolvedType != null) if (resolvedType == null)
{ {
AddField(new FieldType continue;
{
Name = nestedFieldInfo.FieldName,
ResolvedType = resolvedType,
Resolver = null,
Description = nestedFieldInfo.Field.RawProperties.Hints
}).WithSourceName(nestedFieldInfo);
} }
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."; 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) 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)) await using (var fs = new FileStream(writtenFile, FileMode.Open))

Loading…
Cancel
Save