Skip to content

Commit

Permalink
Fix multi-link deserialization (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinchs authored Feb 26, 2024
1 parent c492fc9 commit 5fb9a14
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dbschema/migrations/00008.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE MIGRATION m1xt33ahn2zm5wiwbdubmpttdcg5ywahjme2dnpj3jx3hfhkzcc3sq
ONTO m1tig3qk3mnrb2xpszwyodgurkdeyza6yt67zo7kfljc2icy3e7yma
{
CREATE TYPE tests::Links {
CREATE LINK b: tests::Links;
CREATE MULTI LINK c: tests::Links;
CREATE PROPERTY a: std::str;
};
};
9 changes: 9 additions & 0 deletions dbschema/migrations/00009.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE MIGRATION m1hds33s7w5uj53nhqljjf7cqpzzv64csyo7r4di4cf5f22q5ydywa
ONTO m1xt33ahn2zm5wiwbdubmpttdcg5ywahjme2dnpj3jx3hfhkzcc3sq
{
ALTER TYPE tests::Links {
ALTER PROPERTY a {
CREATE CONSTRAINT std::exclusive;
};
};
};
8 changes: 8 additions & 0 deletions dbschema/tests.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ module tests {
required property b -> str;
required property c -> str;
}

type Links {
a: str {
constraint exclusive;
};
b: Links;
multi c: Links;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.edgedb.examples;

import com.edgedb.driver.EdgeDBClient;
import com.edgedb.driver.annotations.EdgeDBLinkType;
import com.edgedb.driver.annotations.EdgeDBType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -16,6 +17,7 @@ public static final class Person {
public String name;
public Long age;
public Person bestFriend;
@EdgeDBLinkType(Person.class)
public Collection<Person> friends;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public static Codec<?> visitCompilableCodec(@NotNull TypeVisitor visitor, @NotNu
// context type control:
// inner codec:
try(var ignored = visitor.enterNewContext(v -> {
if(v.isRealType) {
return;
}

var innerType = TypeUtils.tryPullWrappingType(visitor.getContext().type);

if(innerType == null) {
Expand Down
35 changes: 35 additions & 0 deletions src/driver/src/test/java/QueryTests.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
import com.edgedb.driver.EdgeDBClient;
import com.edgedb.driver.annotations.EdgeDBLinkType;
import com.edgedb.driver.annotations.EdgeDBType;
import com.edgedb.driver.datatypes.MultiRange;
import com.edgedb.driver.datatypes.Range;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import static org.assertj.core.api.Assertions.assertThat;

public class QueryTests {
@EdgeDBType
public static final class Links {
public String a;
public Links b;
@EdgeDBLinkType(Links.class)
public Collection<Links> c;
}

@Test
public void testLinkProperties() throws Exception {
try(var client = new EdgeDBClient().withModule("tests")) {
var result = client
.execute(
"with a := (insert Links { a := 'A' } unless conflict on .a)," +
"b := (insert Links { a := 'B'} unless conflict on .a)," +
"c := (insert Links { a := 'C', c := b } unless conflict on .a)" +
"insert Links { a := 'D', c := { a, b, c }, b := c } unless conflict on .a")
.thenCompose(v ->
client.queryRequiredSingle(
Links.class,
"select Links { a, c: { a, b, c }, b: { a, b, c } } filter .a = 'D'"
)
)
.toCompletableFuture().get();

assertThat(result.a).isEqualTo("D");

for (var linkClass : result.c) {
assertThat(linkClass.getClass()).isEqualTo(Links.class); // verify its deserialized an actual object
}
}
}

@Test
public void testMultiRanges() {
try(var client = new EdgeDBClient()) {
Expand Down

0 comments on commit 5fb9a14

Please sign in to comment.