Browse Source

Bugfixes by creating resolvers manually.

pull/65/head
Sebastian Stehle 9 years ago
parent
commit
2679dca2b4
  1. 14
      Squidex.sln
  2. 14
      src/Squidex.Domain.Apps.Read.MongoDb/Contents/Visitors/PropertyVisitor.cs
  3. 124
      src/Squidex.Domain.Apps.Read/Contents/GraphQL/Types/AssetGraphType.cs
  4. 66
      src/Squidex.Domain.Apps.Read/Contents/GraphQL/Types/ContentGraphType.cs
  5. 4
      src/Squidex.Domain.Apps.Read/Contents/GraphQL/Types/ContentQueryType.cs
  6. 2
      src/Squidex.Domain.Apps.Read/Squidex.Domain.Apps.Read.csproj
  7. 1
      src/Squidex/Squidex.csproj

14
Squidex.sln

@ -56,6 +56,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Domain.Users.MongoD
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Domain.Users.Tests", "tests\Squidex.Domain.Users.Tests\Squidex.Domain.Users.Tests.csproj", "{42184546-E3CB-4D4F-9495-43979B9C63B9}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Domain.Users.Tests", "tests\Squidex.Domain.Users.Tests\Squidex.Domain.Users.Tests.csproj", "{42184546-E3CB-4D4F-9495-43979B9C63B9}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL", "C:\Users\mail2\Downloads\graphql-dotnet\src\GraphQL\GraphQL.csproj", "{A1290A2F-E935-4666-95F0-E015293F5AF6}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -266,6 +268,18 @@ Global
{42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x64.Build.0 = Release|Any CPU {42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x64.Build.0 = Release|Any CPU
{42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x86.ActiveCfg = Release|Any CPU {42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x86.ActiveCfg = Release|Any CPU
{42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x86.Build.0 = Release|Any CPU {42184546-E3CB-4D4F-9495-43979B9C63B9}.Release|x86.Build.0 = Release|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Debug|x64.ActiveCfg = Debug|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Debug|x64.Build.0 = Debug|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Debug|x86.ActiveCfg = Debug|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Debug|x86.Build.0 = Debug|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Release|Any CPU.Build.0 = Release|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Release|x64.ActiveCfg = Release|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Release|x64.Build.0 = Release|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Release|x86.ActiveCfg = Release|Any CPU
{A1290A2F-E935-4666-95F0-E015293F5AF6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

14
src/Squidex.Domain.Apps.Read.MongoDb/Contents/Visitors/PropertyVisitor.cs

@ -46,9 +46,21 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Contents.Visitors
return nodeIn.Source.Accept(this); return nodeIn.Source.Accept(this);
} }
public override ImmutableList<string> Visit(SingleComplexNode nodeIn)
{
if (nodeIn.Source is SingleComplexNode)
{
return nodeIn.Source.Accept(this).Add(nodeIn.Property.Name);
}
else
{
return ImmutableList.Create(nodeIn.Property.Name);
}
}
public override ImmutableList<string> Visit(SingleValuePropertyAccessNode nodeIn) public override ImmutableList<string> Visit(SingleValuePropertyAccessNode nodeIn)
{ {
if (nodeIn.Source is SingleValuePropertyAccessNode) if (nodeIn.Source is SingleComplexNode)
{ {
return nodeIn.Source.Accept(this).Add(nodeIn.Property.Name); return nodeIn.Source.Accept(this).Add(nodeIn.Property.Name);
} }

124
src/Squidex.Domain.Apps.Read/Contents/GraphQL/Types/AssetGraphType.cs

@ -6,6 +6,8 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System;
using GraphQL.Resolvers;
using GraphQL.Types; using GraphQL.Types;
using Squidex.Domain.Apps.Read.Assets; using Squidex.Domain.Apps.Read.Assets;
@ -17,46 +19,116 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL.Types
{ {
Name = "AssetDto"; Name = "AssetDto";
Field("id", x => x.Id.ToString()) AddField(new FieldType
.Description("The id of the asset."); {
Name = "id",
Resolver = Resolver(x => x.Id.ToString()),
ResolvedType = new NonNullGraphType(new StringGraphType()),
Description = "The id of the asset."
});
Field("version", x => x.Version) AddField(new FieldType
.Description("The version of the asset."); {
Name = "version",
Resolver = Resolver(x => x.Version),
ResolvedType = new NonNullGraphType(new IntGraphType()),
Description = "The version of the asset."
});
Field("created", x => x.Created.ToDateTimeUtc()) AddField(new FieldType
.Description("The date and time when the asset has been created."); {
Name = "created",
Resolver = Resolver(x => x.Created.ToDateTimeUtc()),
ResolvedType = new NonNullGraphType(new DateGraphType()),
Description = "The date and time when the asset has been created."
});
Field("createdBy", x => x.CreatedBy.ToString()) AddField(new FieldType
.Description("The user that has created the asset."); {
Name = "createdBy",
Resolver = Resolver(x => x.CreatedBy.ToString()),
ResolvedType = new NonNullGraphType(new StringGraphType()),
Description = "The user that has created the asset."
});
Field("lastModified", x => x.LastModified.ToDateTimeUtc()) AddField(new FieldType
.Description("The date and time when the asset has been modified last."); {
Name = "lastModified",
Resolver = Resolver(x => x.LastModified.ToDateTimeUtc()),
ResolvedType = new NonNullGraphType(new DateGraphType()),
Description = "The date and time when the asset has been modified last."
});
Field("lastModifiedBy", x => x.LastModifiedBy.ToString()) AddField(new FieldType
.Description("The user that has updated the asset last."); {
Name = "lastModifiedBy",
Resolver = Resolver(x => x.LastModifiedBy.ToString()),
ResolvedType = new NonNullGraphType(new StringGraphType()),
Description = "The user that has updated the asset last."
});
Field("mimeType", x => x.MimeType) AddField(new FieldType
.Description("The mime type."); {
Name = "mimeType",
Resolver = Resolver(x => x.MimeType),
ResolvedType = new NonNullGraphType(new StringGraphType()),
Description = "The mime type."
});
Field("fileName", x => x.FileName) AddField(new FieldType
.Description("The file name."); {
Name = "fileName",
Resolver = Resolver(x => x.FileName),
ResolvedType = new NonNullGraphType(new StringGraphType()),
Description = "The file name."
});
Field("fileSize", x => x.FileSize) AddField(new FieldType
.Description("The size of the file in bytes."); {
Name = "fileSize",
Resolver = Resolver(x => x.FileSize),
ResolvedType = new NonNullGraphType(new IntGraphType()),
Description = "The size of the file in bytes."
});
Field("fileVersion", x => x.FileVersion) AddField(new FieldType
.Description("The version of the file."); {
Name = "fileVersion",
Resolver = Resolver(x => x.FileVersion),
ResolvedType = new NonNullGraphType(new IntGraphType()),
Description = "The version of the file."
});
Field("isImage", x => x.IsImage) AddField(new FieldType
.Description("Determines of the created file is an image."); {
Name = "isImage",
Resolver = Resolver(x => x.IsImage),
ResolvedType = new NonNullGraphType(new BooleanGraphType()),
Description = "Determines of the created file is an image."
});
Field("pixelWidth", x => x.PixelWidth, true) AddField(new FieldType
.Description("The width of the image in pixels if the asset is an image."); {
Name = "pixelWidth",
Resolver = Resolver(x => x.PixelWidth),
ResolvedType = new IntGraphType(),
Description = "The width of the image in pixels if the asset is an image."
});
Field("pixelHeight", x => x.PixelHeight, true) AddField(new FieldType
.Description("The height of the image in pixels if the asset is an image."); {
Name = "pixelHeight",
Resolver = Resolver(x => x.PixelHeight),
ResolvedType = new IntGraphType(),
Description = "The height of the image in pixels if the asset is an image."
});
Description = "An asset"; Description = "An asset";
} }
private static IFieldResolver Resolver(Func<IAssetEntity, object> action)
{
return new FuncFieldResolver<IAssetEntity, object>(c => action(c.Source));
}
} }
} }

66
src/Squidex.Domain.Apps.Read/Contents/GraphQL/Types/ContentGraphType.cs

@ -6,9 +6,9 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System;
using GraphQL.Resolvers; using GraphQL.Resolvers;
using GraphQL.Types; using GraphQL.Types;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Schema = Squidex.Domain.Apps.Core.Schemas.Schema; using Schema = Squidex.Domain.Apps.Core.Schemas.Schema;
@ -16,42 +16,74 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL.Types
{ {
public sealed class ContentGraphType : ObjectGraphType<IContentEntity> public sealed class ContentGraphType : ObjectGraphType<IContentEntity>
{ {
private static readonly IFieldResolver DataResolver =
new FuncFieldResolver<IContentEntity, NamedContentData>(c => c.Source.Data);
public ContentGraphType(Schema schema, IGraphQLContext graphQLContext) public ContentGraphType(Schema schema, IGraphQLContext graphQLContext)
{ {
var schemaName = schema.Properties.Label.WithFallback(schema.Name); var schemaName = schema.Properties.Label.WithFallback(schema.Name);
Name = $"{schema.Name.ToPascalCase()}Dto"; Name = $"{schema.Name.ToPascalCase()}Dto";
Field("id", x => x.Id.ToString()) AddField(new FieldType
.Description($"The id of the {schemaName} content."); {
Name = "id",
Resolver = Resolver(x => x.Id.ToString()),
ResolvedType = new NonNullGraphType(new StringGraphType()),
Description = $"The id of the {schemaName} content."
});
Field("version", x => x.Version) AddField(new FieldType
.Description($"The version of the {schemaName} content."); {
Name = "version",
Resolver = Resolver(x => x.Version),
ResolvedType = new NonNullGraphType(new IntGraphType()),
Description = $"The version of the {schemaName} content."
});
Field("created", x => x.Created.ToDateTimeUtc()) AddField(new FieldType
.Description($"The date and time when the {schemaName} content has been created."); {
Name = "created",
Resolver = Resolver(x => x.Created.ToDateTimeUtc()),
ResolvedType = new NonNullGraphType(new DateGraphType()),
Description = $"The date and time when the {schemaName} content has been created."
});
Field("createdBy", x => x.CreatedBy.ToString()) AddField(new FieldType
.Description($"The user that has created the {schemaName} content."); {
Name = "createdBy",
Resolver = Resolver(x => x.CreatedBy.ToString()),
ResolvedType = new NonNullGraphType(new StringGraphType()),
Description = $"The user that has created the {schemaName} content."
});
Field("lastModified", x => x.LastModified.ToDateTimeUtc()) AddField(new FieldType
.Description($"The date and time when the {schemaName} content has been modified last."); {
Name = "lastModified",
Resolver = Resolver(x => x.LastModified.ToDateTimeUtc()),
ResolvedType = new NonNullGraphType(new DateGraphType()),
Description = $"The date and time when the {schemaName} content has been modified last."
});
Field("lastModifiedBy", x => x.LastModifiedBy.ToString()) AddField(new FieldType
.Description($"The user that has updated the {schemaName} content last."); {
Name = "lastModifiedBy",
Resolver = Resolver(x => x.LastModifiedBy.ToString()),
ResolvedType = new NonNullGraphType(new StringGraphType()),
Description = $"The user that has updated the {schemaName} content last."
});
AddField(new FieldType AddField(new FieldType
{ {
Name = "data", Name = "data",
Resolver = DataResolver, Resolver = Resolver(x => x.Data),
ResolvedType = new NonNullGraphType(new ContentDataGraphType(schema, graphQLContext)), ResolvedType = new NonNullGraphType(new ContentDataGraphType(schema, graphQLContext)),
Description = $"The data of the {schemaName} content." Description = $"The data of the {schemaName} content."
}); });
Description = $"The structure of a {schemaName} content type."; Description = $"The structure of a {schemaName} content type.";
} }
private static IFieldResolver Resolver(Func<IContentEntity, object> action)
{
return new FuncFieldResolver<IContentEntity, object>(c => action(c.Source));
}
} }
} }

4
src/Squidex.Domain.Apps.Read/Contents/GraphQL/Types/ContentQueryType.cs

@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL.Types
{ {
AddField(new FieldType AddField(new FieldType
{ {
Name = $"find{schemaEntity.Name.ToPascalCase()}", Name = $"find{schemaEntity.Name.ToPascalCase()}Content",
Arguments = new QueryArguments Arguments = new QueryArguments
{ {
new QueryArgument(typeof(StringGraphType)) new QueryArgument(typeof(StringGraphType))
@ -132,7 +132,7 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL.Types
{ {
AddField(new FieldType AddField(new FieldType
{ {
Name = $"query{schemaEntity.Name.ToPascalCase()}", Name = $"query{schemaEntity.Name.ToPascalCase()}Contents",
Arguments = new QueryArguments Arguments = new QueryArguments
{ {
new QueryArgument(typeof(IntGraphType)) new QueryArgument(typeof(IntGraphType))

2
src/Squidex.Domain.Apps.Read/Squidex.Domain.Apps.Read.csproj

@ -11,9 +11,9 @@
<ProjectReference Include="..\Squidex.Domain.Apps.Core\Squidex.Domain.Apps.Core.csproj" /> <ProjectReference Include="..\Squidex.Domain.Apps.Core\Squidex.Domain.Apps.Core.csproj" />
<ProjectReference Include="..\Squidex.Domain.Apps.Events\Squidex.Domain.Apps.Events.csproj" /> <ProjectReference Include="..\Squidex.Domain.Apps.Events\Squidex.Domain.Apps.Events.csproj" />
<ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" /> <ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" />
<ProjectReference Include="C:\Users\mail2\Downloads\graphql-dotnet\src\GraphQL\GraphQL.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GraphQL" Version="0.16.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="1.1.2" />
<PackageReference Include="NodaTime" Version="2.0.3" /> <PackageReference Include="NodaTime" Version="2.0.3" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.7.0" /> <PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.7.0" />

1
src/Squidex/Squidex.csproj

@ -38,6 +38,7 @@
<ProjectReference Include="..\Squidex.Domain.Apps.Read.MongoDb\Squidex.Domain.Apps.Read.MongoDb.csproj" /> <ProjectReference Include="..\Squidex.Domain.Apps.Read.MongoDb\Squidex.Domain.Apps.Read.MongoDb.csproj" />
<ProjectReference Include="..\Squidex.Domain.Apps.Write\Squidex.Domain.Apps.Write.csproj" /> <ProjectReference Include="..\Squidex.Domain.Apps.Write\Squidex.Domain.Apps.Write.csproj" />
<ProjectReference Include="..\Squidex.Shared\Squidex.Shared.csproj" /> <ProjectReference Include="..\Squidex.Shared\Squidex.Shared.csproj" />
<ProjectReference Include="C:\Users\mail2\Downloads\graphql-dotnet\src\GraphQL\GraphQL.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save