Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test & improve SchemaValidator #109

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Backend/Confix.sln
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Authoring.Authentication.Te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Authoring.Integration.Tests", "test\Authoring.Integration.Tests\Authoring.Integration.Tests.csproj", "{A6467E98-B5F2-488A-984D-D80C158B49C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Authoring.Core.Tests", "test\Authoring.Core.Tests\Authoring.Core.Tests.csproj", "{99F7E325-A61C-46EF-9F66-641C6BA23F14}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -220,6 +222,10 @@ Global
{A6467E98-B5F2-488A-984D-D80C158B49C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6467E98-B5F2-488A-984D-D80C158B49C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6467E98-B5F2-488A-984D-D80C158B49C2}.Release|Any CPU.Build.0 = Release|Any CPU
{99F7E325-A61C-46EF-9F66-641C6BA23F14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99F7E325-A61C-46EF-9F66-641C6BA23F14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99F7E325-A61C-46EF-9F66-641C6BA23F14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99F7E325-A61C-46EF-9F66-641C6BA23F14}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A506ADEE-0136-4A7B-B3C8-0D23C176F4DE} = {8C4B0F32-7C73-4C83-80AF-CDD992121D3D}
Expand Down Expand Up @@ -256,5 +262,6 @@ Global
{3957135B-E458-44D1-9C9B-9D7AD6220638} = {8C4B0F32-7C73-4C83-80AF-CDD992121D3D}
{D7B34C75-E53E-4DAD-8ADD-C92D7576C714} = {D40302DA-D28B-4601-BD53-3A7D4405826B}
{A6467E98-B5F2-488A-984D-D80C158B49C2} = {D40302DA-D28B-4601-BD53-3A7D4405826B}
{99F7E325-A61C-46EF-9F66-641C6BA23F14} = {D40302DA-D28B-4601-BD53-3A7D4405826B}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public InvalidSchemaException(GraphQLSchemaError[] errors) : base("The Provided

public GraphQLSchemaError[] Errors;
}
public record GraphQLSchemaError(string message);
public record GraphQLSchemaError(string Message);
1 change: 1 addition & 0 deletions src/Backend/src/Authoring.Core/InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
using Confix.Authentication.ApiKey;

[assembly: InternalsVisibleTo("Confix.Authoring.GraphQL")]
[assembly: InternalsVisibleTo("Confix.Authoring.Core.Tests")]
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public void ValidateSchema(string schemaSdl)
{
throw new InvalidSchemaException(ex.Errors.Select(e => new GraphQLSchemaError(e.Message)).ToArray());
}
catch (SyntaxException)
{
throw new InvalidSchemaException(
new GraphQLSchemaError[] {
new("Could not parse Schema")
});
}
}

public void ValidateValues(JsonElement values, string schemaSdl)
Expand Down Expand Up @@ -57,11 +64,11 @@ private ISchema CreateSchema(string schemaSdl)
.ModifyOptions(c =>
{
c.QueryTypeName = "Configuration";
c.StrictValidation = false;
c.StrictValidation = true;
})
.Create();
})!;

private static string CacheKey(string input)
=> Encoding.UTF8.GetString(SHA256.HashData(Encoding.UTF8.GetBytes(input)));
=> "schema." + Encoding.UTF8.GetString(SHA256.HashData(Encoding.UTF8.GetBytes(input)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ internal static class ValueHelper
public static Dictionary<string, object?> DeserializeDictionary(JsonElement element, IType type)
{
var dictionary = new Dictionary<string, object?>();
// TODO: fix this for unionTypes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Union Types are currently not working

var objectType = (ObjectType)type.NamedType();

foreach (var property in element.EnumerateObject())
Expand Down
13 changes: 13 additions & 0 deletions src/Backend/test/Authoring.Core.Tests/Authoring.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>Confix.Authoring.Core.Tests</AssemblyName>
<RootNamespace>Confix.Authoring.Core.Tests</RootNamespace>
</PropertyGroup>


<ItemGroup>
<ProjectReference Include="..\..\src\Authoring.Core\Authoring.Core.csproj" />
</ItemGroup>

</Project>
Loading
Loading