Skip to content

Commit

Permalink
Fix serialization of wrong reference
Browse files Browse the repository at this point in the history
  • Loading branch information
quinchs committed Aug 31, 2022
1 parent e7451f8 commit 1604eee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
28 changes: 14 additions & 14 deletions examples/EdgeDB.Examples.ExampleApp/Examples/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,6 @@ public async Task ExecuteAsync(EdgeDBClient client)

private static async Task QueryBuilderDemo(EdgeDBClient client)
{
var test = QueryBuilder.With(new
{
Args = EdgeQL.AsJson(new ConstraintPerson
{
Name = "Example",
Email = "[email protected]"
})
}).Select(ctx => new
{
PassedName = ctx.Variables.Args.Value.Name,
PassedEmail = ctx.Variables.Args.Value.Email
}).Build();


// Selecting a type with autogen shape
var query = QueryBuilder.Select<LinkPerson>().Build().Prettify();

Expand Down Expand Up @@ -146,6 +132,20 @@ private static async Task QueryBuilderDemo(EdgeDBClient client)
})
}).Build().Prettify();

// With object variables
query = QueryBuilder.With(new
{
Args = EdgeQL.AsJson(new ConstraintPerson
{
Name = "Example",
Email = "[email protected]"
})
}).Select(ctx => new
{
PassedName = ctx.Variables.Args.Value.Name,
PassedEmail = ctx.Variables.Args.Value.Email
}).Build();

// Inserting a new type
var person = new LinkPerson
{
Expand Down
5 changes: 3 additions & 2 deletions src/EdgeDB.Net.QueryBuilder/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,12 @@ public QueryBuilder<TType, QueryContext<TVariables>> With<TVariables>(TVariables
{
_queryGlobals.Add(new QueryGlobal(property.Name, new SubQuery($"(select {property.PropertyType.GetEdgeDBTypeName()} filter .id = <uuid>'{id}')")));
}
else if (property.PropertyType.IsAssignableTo(typeof(IJsonVariable)))
else if (ReflectionUtils.IsSubTypeOfGenericType(typeof(JsonReferenceVariable<>), property.PropertyType))
{
// Serialize and add as global and variable
var referenceValue = property.PropertyType.GetProperty("Value")!.GetValue(value);
var jsonVarName = QueryUtils.GenerateRandomVariableName();
_queryVariables.Add(jsonVarName, DataTypes.Json.Serialize(value));
_queryVariables.Add(jsonVarName, DataTypes.Json.Serialize(referenceValue));
_queryGlobals.Add(new QueryGlobal(property.Name, new SubQuery($"<json>${jsonVarName}"), value));
}
else
Expand Down

0 comments on commit 1604eee

Please sign in to comment.