-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aaron Klish
committed
May 6, 2020
1 parent
8f59746
commit 6a79c31
Showing
5 changed files
with
145 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
elide-graphql/src/test/java/com/yahoo/elide/graphql/GraphQLEntityProjectionMakerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2020, Yahoo Inc. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
|
||
package com.yahoo.elide.graphql; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.yahoo.elide.ElideSettings; | ||
import com.yahoo.elide.ElideSettingsBuilder; | ||
import com.yahoo.elide.core.filter.dialect.RSQLFilterDialect; | ||
import com.yahoo.elide.graphql.parser.GraphQLEntityProjectionMaker; | ||
import com.yahoo.elide.graphql.parser.GraphQLProjectionInfo; | ||
import com.yahoo.elide.request.Attribute; | ||
import com.yahoo.elide.request.EntityProjection; | ||
import example.models.inheritance.Character; | ||
import example.models.inheritance.Droid; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.TimeZone; | ||
|
||
public class GraphQLEntityProjectionMakerTest extends GraphQLTest { | ||
ElideSettings settings; | ||
|
||
public GraphQLEntityProjectionMakerTest() { | ||
RSQLFilterDialect filterDialect = new RSQLFilterDialect(dictionary); | ||
|
||
settings = new ElideSettingsBuilder(null) | ||
.withEntityDictionary(dictionary) | ||
.withJoinFilterDialect(filterDialect) | ||
.withSubqueryFilterDialect(filterDialect) | ||
.withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void testInlineFragment() { | ||
GraphQLEntityProjectionMaker maker = new GraphQLEntityProjectionMaker(settings); | ||
|
||
String query = "{ character { edges { node { " | ||
+ "__typename ... on Character { name } " | ||
+ "__typename ... on Droid { primaryFunction }}}}}"; | ||
|
||
GraphQLProjectionInfo info = maker.make(query); | ||
|
||
EntityProjection projection = info.getProjection("", "character"); | ||
|
||
Attribute nameAttribute = projection.getAttributes().stream() | ||
.filter(attr -> attr.getName().equals("name")) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalStateException()); | ||
|
||
assertEquals(Character.class, nameAttribute.getParentType()); | ||
|
||
Attribute primaryFunctionAttribute = projection.getAttributes().stream() | ||
.filter(attr -> attr.getName().equals("primaryFunction")) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalStateException()); | ||
|
||
assertEquals(Droid.class, primaryFunctionAttribute.getParentType()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
elide-graphql/src/test/java/com/yahoo/elide/graphql/GraphQLNameUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2020, Yahoo Inc. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
|
||
package com.yahoo.elide.graphql; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.yahoo.elide.core.EntityDictionary; | ||
import example.models.inheritance.Character; | ||
import example.models.inheritance.Droid; | ||
import example.models.inheritance.Hero; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Collections; | ||
|
||
public class GraphQLNameUtilsTest { | ||
|
||
@Test | ||
public void testBoundNameMapping() { | ||
EntityDictionary dictionary = new EntityDictionary(Collections.EMPTY_MAP); | ||
|
||
dictionary.bindEntity(Droid.class); | ||
dictionary.bindEntity(Hero.class); | ||
dictionary.bindEntity(Character.class); | ||
|
||
GraphQLNameUtils nameUtils = new GraphQLNameUtils(dictionary); | ||
|
||
assertEquals("droid", nameUtils.toBoundName("Droid")); | ||
assertEquals("hero", nameUtils.toBoundName("Hero")); | ||
assertEquals("character", nameUtils.toBoundName("Character")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters