diff --git a/graphql-jpa-query-build/pom.xml b/graphql-jpa-query-build/pom.xml index 756de3690..0ef5df724 100644 --- a/graphql-jpa-query-build/pom.xml +++ b/graphql-jpa-query-build/pom.xml @@ -35,7 +35,7 @@ org.springframework.boot spring-boot-dependencies - 2.6.12 + 2.7.5 pom import diff --git a/graphql-jpa-query-dependencies/pom.xml b/graphql-jpa-query-dependencies/pom.xml index a2ab65433..3348a0f99 100644 --- a/graphql-jpa-query-dependencies/pom.xml +++ b/graphql-jpa-query-dependencies/pom.xml @@ -16,6 +16,7 @@ 1.2.2 2.2 2.10.5 + 19.0 @@ -25,6 +26,11 @@ graphql-java ${graphql-java.version} + + com.graphql-java + graphql-java-extended-scalars + ${graphql-java-extended-scalars.version} + javax.persistence javax.persistence-api diff --git a/graphql-jpa-query-schema/pom.xml b/graphql-jpa-query-schema/pom.xml index c07d2be7e..03d818348 100644 --- a/graphql-jpa-query-schema/pom.xml +++ b/graphql-jpa-query-schema/pom.xml @@ -28,6 +28,11 @@ graphql-java + + com.graphql-java + graphql-java-extended-scalars + + org.atteo evo-inflector diff --git a/graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/JavaScalars.java b/graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/JavaScalars.java index cce0dea98..3726e364f 100644 --- a/graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/JavaScalars.java +++ b/graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/JavaScalars.java @@ -15,7 +15,27 @@ */ package com.introproventures.graphql.jpa.query.schema; -import static graphql.schema.GraphQLScalarType.newScalar; +import graphql.Assert; +import graphql.Scalars; +import graphql.language.ArrayValue; +import graphql.language.BooleanValue; +import graphql.language.EnumValue; +import graphql.language.FloatValue; +import graphql.language.IntValue; +import graphql.language.NullValue; +import graphql.language.ObjectField; +import graphql.language.ObjectValue; +import graphql.language.StringValue; +import graphql.language.Value; +import graphql.language.VariableReference; +import graphql.scalars.ExtendedScalars; +import graphql.schema.Coercing; +import graphql.schema.CoercingParseLiteralException; +import graphql.schema.CoercingParseValueException; +import graphql.schema.CoercingSerializeException; +import graphql.schema.GraphQLScalarType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.math.BigDecimal; import java.math.BigInteger; @@ -47,28 +67,7 @@ import java.util.function.Function; import java.util.stream.Collectors; -import graphql.scalar.GraphqlFloatCoercing; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import graphql.Assert; -import graphql.Scalars; -import graphql.language.ArrayValue; -import graphql.language.BooleanValue; -import graphql.language.EnumValue; -import graphql.language.FloatValue; -import graphql.language.IntValue; -import graphql.language.NullValue; -import graphql.language.ObjectField; -import graphql.language.ObjectValue; -import graphql.language.StringValue; -import graphql.language.Value; -import graphql.language.VariableReference; -import graphql.schema.Coercing; -import graphql.schema.CoercingParseLiteralException; -import graphql.schema.CoercingParseValueException; -import graphql.schema.CoercingSerializeException; -import graphql.schema.GraphQLScalarType; +import static graphql.schema.GraphQLScalarType.newScalar; /** * Provides Registry to resolve GraphQL Query Java Scalar Types @@ -78,56 +77,10 @@ */ public class JavaScalars { - private static final BigInteger LONG_MAX = BigInteger.valueOf(Long.MAX_VALUE); - private static final BigInteger LONG_MIN = BigInteger.valueOf(Long.MIN_VALUE); - private static final BigInteger INT_MAX = BigInteger.valueOf(Integer.MAX_VALUE); - private static final BigInteger INT_MIN = BigInteger.valueOf(Integer.MIN_VALUE); - private static final BigInteger BYTE_MAX = BigInteger.valueOf(Byte.MAX_VALUE); - private static final BigInteger BYTE_MIN = BigInteger.valueOf(Byte.MIN_VALUE); - private static final BigInteger SHORT_MAX = BigInteger.valueOf(Short.MAX_VALUE); - private static final BigInteger SHORT_MIN = BigInteger.valueOf(Short.MIN_VALUE); - static final Logger log = LoggerFactory.getLogger(JavaScalars.class); private static HashMap, GraphQLScalarType> scalarsRegistry = new HashMap, GraphQLScalarType>(); - public static GraphQLScalarType GraphQLLong = GraphQLScalarType.newScalar() - .name("Long") - .description("Long type") - .coercing(new GraphqlLongCoercing()) - .build(); - - public static GraphQLScalarType GraphQLShort = GraphQLScalarType.newScalar() - .name("Short") - .description("Short type") - .coercing(new GraphqlShortCoercing()) - .build(); - - public static GraphQLScalarType GraphQLBigInteger = GraphQLScalarType.newScalar() - .name("BigInteger") - .description("BigInteger type") - .coercing(new GraphqlBigIntegerCoercing()) - .build(); - - public static GraphQLScalarType GraphQLChar = GraphQLScalarType.newScalar() - .name("Char") - .description("Char type") - .coercing(new GraphqlCharCoercing()) - .build(); - - public static GraphQLScalarType GraphQLByte = GraphQLScalarType.newScalar() - .name("Byte") - .description("Byte type") - .coercing(new GraphqlByteCoercing()) - .build(); - - public static GraphQLScalarType GraphQLBigDecimal = GraphQLScalarType.newScalar() - .name("BigDecimal") - .description("BigDecimal type") - .coercing(new GraphqlBigDecimalCoercing()) - .build(); - - private static JavaScalars instance = new JavaScalars(); static { @@ -136,8 +89,8 @@ public class JavaScalars { scalarsRegistry.put(Integer.class, Scalars.GraphQLInt); scalarsRegistry.put(int.class, Scalars.GraphQLInt); - scalarsRegistry.put(Short.class, JavaScalars.GraphQLShort); - scalarsRegistry.put(short.class, JavaScalars.GraphQLShort); + scalarsRegistry.put(Short.class, ExtendedScalars.GraphQLShort); + scalarsRegistry.put(short.class, ExtendedScalars.GraphQLShort); scalarsRegistry.put(Float.class, Scalars.GraphQLFloat); scalarsRegistry.put(float.class, Scalars.GraphQLFloat); @@ -145,21 +98,21 @@ public class JavaScalars { scalarsRegistry.put(Double.class, Scalars.GraphQLFloat); scalarsRegistry.put(double.class, Scalars.GraphQLFloat); - scalarsRegistry.put(Long.class, JavaScalars.GraphQLLong); - scalarsRegistry.put(long.class, JavaScalars.GraphQLLong); + scalarsRegistry.put(Long.class, ExtendedScalars.GraphQLLong); + scalarsRegistry.put(long.class, ExtendedScalars.GraphQLLong); scalarsRegistry.put(Boolean.class, Scalars.GraphQLBoolean); scalarsRegistry.put(boolean.class, Scalars.GraphQLBoolean); - scalarsRegistry.put(BigInteger.class, JavaScalars.GraphQLBigInteger); + scalarsRegistry.put(BigInteger.class, ExtendedScalars.GraphQLBigInteger); - scalarsRegistry.put(char.class, JavaScalars.GraphQLChar); - scalarsRegistry.put(Character.class, JavaScalars.GraphQLChar); + scalarsRegistry.put(char.class, ExtendedScalars.GraphQLChar); + scalarsRegistry.put(Character.class, ExtendedScalars.GraphQLChar); - scalarsRegistry.put(Byte.class, JavaScalars.GraphQLByte); - scalarsRegistry.put(byte.class, JavaScalars.GraphQLByte); + scalarsRegistry.put(Byte.class, ExtendedScalars.GraphQLByte); + scalarsRegistry.put(byte.class, ExtendedScalars.GraphQLByte); - scalarsRegistry.put(BigDecimal.class, JavaScalars.GraphQLBigDecimal); + scalarsRegistry.put(BigDecimal.class, ExtendedScalars.GraphQLBigDecimal); scalarsRegistry.put(LocalDateTime.class, newScalarType("LocalDateTime", "LocalDateTime type", new GraphQLLocalDateTimeCoercing())); scalarsRegistry.put(LocalDate.class, newScalarType("LocalDate", "LocalDate type", new GraphQLLocalDateCoercing())); @@ -869,392 +822,4 @@ public Instant apply(String date) { } } } - - /** - * This represents the "Long" type which is a representation of java.lang.Long - */ - public static class GraphqlLongCoercing implements Coercing { - - private Long convertImpl(Object input) { - if (input instanceof Long) { - return (Long) input; - } else if (isNumberIsh(input)) { - BigDecimal value; - try { - value = new BigDecimal(input.toString()); - } catch (NumberFormatException e) { - return null; - } - try { - return value.longValueExact(); - } catch (ArithmeticException e) { - return null; - } - } else { - return null; - } - - } - - @Override - public Long serialize(Object input) { - Long result = convertImpl(input); - if (result == null) { - throw new CoercingSerializeException( - "Expected type 'Long' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public Long parseValue(Object input) { - Long result = convertImpl(input); - if (result == null) { - throw new CoercingParseValueException( - "Expected type 'Long' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public Long parseLiteral(Object input) { - if (input instanceof StringValue) { - try { - return Long.parseLong(((StringValue) input).getValue()); - } catch (NumberFormatException e) { - throw new CoercingParseLiteralException( - "Expected value to be a Long but it was '" + String.valueOf(input) + "'" - ); - } - } else if (input instanceof IntValue) { - BigInteger value = ((IntValue) input).getValue(); - if (value.compareTo(LONG_MIN) < 0 || value.compareTo(LONG_MAX) > 0) { - throw new CoercingParseLiteralException( - "Expected value to be in the Long range but it was '" + value.toString() + "'" - ); - } - return value.longValue(); - } - throw new CoercingParseLiteralException( - "Expected AST type 'IntValue' or 'StringValue' but was '" + typeName(input) + "'." - ); - } - } - - public static class GraphqlShortCoercing implements Coercing { - - private Short convertImpl(Object input) { - if (input instanceof Short) { - return (Short) input; - } else if (isNumberIsh(input)) { - BigDecimal value; - try { - value = new BigDecimal(input.toString()); - } catch (NumberFormatException e) { - return null; - } - try { - return value.shortValueExact(); - } catch (ArithmeticException e) { - return null; - } - } else { - return null; - } - - } - - @Override - public Short serialize(Object input) { - Short result = convertImpl(input); - if (result == null) { - throw new CoercingSerializeException( - "Expected type 'Short' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public Short parseValue(Object input) { - Short result = convertImpl(input); - if (result == null) { - throw new CoercingParseValueException( - "Expected type 'Short' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public Short parseLiteral(Object input) { - if (!(input instanceof IntValue)) { - throw new CoercingParseLiteralException( - "Expected AST type 'IntValue' but was '" + typeName(input) + "'." - ); - } - BigInteger value = ((IntValue) input).getValue(); - if (value.compareTo(SHORT_MIN) < 0 || value.compareTo(SHORT_MAX) > 0) { - throw new CoercingParseLiteralException( - "Expected value to be in the Short range but it was '" + value.toString() + "'" - ); - } - return value.shortValue(); - } - } - - public static class GraphqlBigIntegerCoercing implements Coercing { - - private BigInteger convertImpl(Object input) { - if (isNumberIsh(input)) { - BigDecimal value; - try { - value = new BigDecimal(input.toString()); - } catch (NumberFormatException e) { - return null; - } - try { - return value.toBigIntegerExact(); - } catch (ArithmeticException e) { - return null; - } - } - return null; - - } - - @Override - public BigInteger serialize(Object input) { - BigInteger result = convertImpl(input); - if (result == null) { - throw new CoercingSerializeException( - "Expected type 'BigInteger' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public BigInteger parseValue(Object input) { - BigInteger result = convertImpl(input); - if (result == null) { - throw new CoercingParseValueException( - "Expected type 'BigInteger' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public BigInteger parseLiteral(Object input) { - if (input instanceof StringValue) { - try { - return new BigDecimal(((StringValue) input).getValue()).toBigIntegerExact(); - } catch (NumberFormatException | ArithmeticException e) { - throw new CoercingParseLiteralException( - "Unable to turn AST input into a 'BigInteger' : '" + String.valueOf(input) + "'" - ); - } - } else if (input instanceof IntValue) { - return ((IntValue) input).getValue(); - } else if (input instanceof FloatValue) { - try { - return ((FloatValue) input).getValue().toBigIntegerExact(); - } catch (ArithmeticException e) { - throw new CoercingParseLiteralException( - "Unable to turn AST input into a 'BigInteger' : '" + String.valueOf(input) + "'" - ); - } - } - throw new CoercingParseLiteralException( - "Expected AST type 'IntValue', 'StringValue' or 'FloatValue' but was '" + typeName(input) + "'." - ); - } - } - - public static class GraphqlCharCoercing implements Coercing { - - private Character convertImpl(Object input) { - if (input instanceof String && ((String) input).length() == 1) { - return ((String) input).charAt(0); - } else if (input instanceof Character) { - return (Character) input; - } else { - return null; - } - - } - - @Override - public Character serialize(Object input) { - Character result = convertImpl(input); - if (result == null) { - throw new CoercingSerializeException( - "Expected type 'Char' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public Character parseValue(Object input) { - Character result = convertImpl(input); - if (result == null) { - throw new CoercingParseValueException( - "Expected type 'Char' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public Character parseLiteral(Object input) { - if (!(input instanceof StringValue)) { - throw new CoercingParseLiteralException( - "Expected AST type 'StringValue' but was '" + typeName(input) + "'." - ); - } - String value = ((StringValue) input).getValue(); - if (value.length() != 1) { - throw new CoercingParseLiteralException( - "Empty 'StringValue' provided." - ); - } - return value.charAt(0); - } - } - - public static class GraphqlByteCoercing implements Coercing { - - private Byte convertImpl(Object input) { - if (input instanceof Byte) { - return (Byte) input; - } else if (isNumberIsh(input)) { - BigDecimal value; - try { - value = new BigDecimal(input.toString()); - } catch (NumberFormatException e) { - return null; - } - try { - return value.byteValueExact(); - } catch (ArithmeticException e) { - return null; - } - } else { - return null; - } - - } - - @Override - public Byte serialize(Object input) { - Byte result = convertImpl(input); - if (result == null) { - throw new CoercingSerializeException( - "Expected type 'Byte' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public Byte parseValue(Object input) { - Byte result = convertImpl(input); - if (result == null) { - throw new CoercingParseValueException( - "Expected type 'Byte' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public Byte parseLiteral(Object input) { - if (!(input instanceof IntValue)) { - throw new CoercingParseLiteralException( - "Expected AST type 'IntValue' but was '" + typeName(input) + "'." - ); - } - BigInteger value = ((IntValue) input).getValue(); - if (value.compareTo(BYTE_MIN) < 0 || value.compareTo(BYTE_MAX) > 0) { - throw new CoercingParseLiteralException( - "Expected value to be in the Byte range but it was '" + value.toString() + "'" - ); - } - return value.byteValue(); - } - } - - public static class GraphqlBigDecimalCoercing implements Coercing { - - private BigDecimal convertImpl(Object input) { - if (isNumberIsh(input)) { - try { - return new BigDecimal(input.toString()); - } catch (NumberFormatException e) { - return null; - } - } - return null; - - } - - @Override - public BigDecimal serialize(Object input) { - BigDecimal result = convertImpl(input); - if (result == null) { - throw new CoercingSerializeException( - "Expected type 'BigDecimal' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public BigDecimal parseValue(Object input) { - BigDecimal result = convertImpl(input); - if (result == null) { - throw new CoercingParseValueException( - "Expected type 'BigDecimal' but was '" + typeName(input) + "'." - ); - } - return result; - } - - @Override - public BigDecimal parseLiteral(Object input) { - if (input instanceof StringValue) { - try { - return new BigDecimal(((StringValue) input).getValue()); - } catch (NumberFormatException e) { - throw new CoercingParseLiteralException( - "Unable to turn AST input into a 'BigDecimal' : '" + String.valueOf(input) + "'" - ); - } - } else if (input instanceof IntValue) { - return new BigDecimal(((IntValue) input).getValue()); - } else if (input instanceof FloatValue) { - return ((FloatValue) input).getValue(); - } - throw new CoercingParseLiteralException( - "Expected AST type 'IntValue', 'StringValue' or 'FloatValue' but was '" + typeName(input) + "'." - ); - } - } - - static boolean isNumberIsh(Object input) { - return input instanceof Number || input instanceof String; - } - - static String typeName(Object input) { - if (input == null) { - return "null"; - } - - return input.getClass().getSimpleName(); - } - } diff --git a/graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java b/graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java index f536876b6..ed39faefa 100644 --- a/graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java +++ b/graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java @@ -16,41 +16,6 @@ package com.introproventures.graphql.jpa.query.schema.impl; -import static graphql.Scalars.GraphQLBoolean; -import static graphql.schema.GraphQLArgument.newArgument; -import static graphql.schema.GraphQLInputObjectField.newInputObjectField; -import static graphql.schema.GraphQLInputObjectType.newInputObject; - -import java.beans.Introspector; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.persistence.Convert; -import javax.persistence.EntityManager; -import javax.persistence.metamodel.Attribute; -import javax.persistence.metamodel.EmbeddableType; -import javax.persistence.metamodel.EntityType; -import javax.persistence.metamodel.ManagedType; -import javax.persistence.metamodel.PluralAttribute; -import javax.persistence.metamodel.SingularAttribute; -import javax.persistence.metamodel.Type; - -import org.dataloader.MappedBatchLoaderWithContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.introproventures.graphql.jpa.query.annotation.GraphQLIgnore; import com.introproventures.graphql.jpa.query.annotation.GraphQLIgnoreFilter; import com.introproventures.graphql.jpa.query.annotation.GraphQLIgnoreOrder; @@ -80,6 +45,39 @@ import graphql.schema.GraphQLType; import graphql.schema.GraphQLTypeReference; import graphql.schema.PropertyDataFetcher; +import org.dataloader.MappedBatchLoaderWithContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.Convert; +import javax.persistence.EntityManager; +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.EmbeddableType; +import javax.persistence.metamodel.EntityType; +import javax.persistence.metamodel.ManagedType; +import javax.persistence.metamodel.PluralAttribute; +import javax.persistence.metamodel.SingularAttribute; +import javax.persistence.metamodel.Type; +import java.beans.Introspector; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Field; +import java.lang.reflect.Member; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static graphql.Scalars.GraphQLBoolean; +import static graphql.schema.GraphQLArgument.newArgument; +import static graphql.schema.GraphQLInputObjectField.newInputObjectField; +import static graphql.schema.GraphQLInputObjectType.newInputObject; /** @@ -308,13 +306,13 @@ private GraphQLObjectType getSelectType(EntityType entityType) { .field(GraphQLFieldDefinition.newFieldDefinition() .name(GraphQLJpaSchemaBuilder.PAGE_PAGES_PARAM_NAME) .description("Total number of pages calculated on the database for this page size.") - .type(JavaScalars.GraphQLLong) + .type(JavaScalars.of(Long.class)) .build() ) .field(GraphQLFieldDefinition.newFieldDefinition() .name(GraphQLJpaSchemaBuilder.PAGE_TOTAL_PARAM_NAME) .description("Total number of records in the database for this query.") - .type(JavaScalars.GraphQLLong) + .type(JavaScalars.of(Long.class)) .build() ) .field(GraphQLFieldDefinition.newFieldDefinition() diff --git a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/AbstractSpringBootTestSupport.java b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/AbstractSpringBootTestSupport.java index 84b0d6fee..cfd392b3d 100644 --- a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/AbstractSpringBootTestSupport.java +++ b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/AbstractSpringBootTestSupport.java @@ -8,7 +8,6 @@ @RunWith(SpringRunner.class) @TestPropertySource({"classpath:hibernate.properties"}) -@AutoConfigureTestDatabase(replace = Replace.ANY) public abstract class AbstractSpringBootTestSupport { } diff --git a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/converter/GraphQLJpaConverterTests.java b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/converter/GraphQLJpaConverterTests.java index eb63275fc..27d0e406f 100644 --- a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/converter/GraphQLJpaConverterTests.java +++ b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/converter/GraphQLJpaConverterTests.java @@ -35,6 +35,7 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; @@ -51,7 +52,10 @@ import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder; -@SpringBootTest(properties = "spring.datasource.data=GraphQLJpaConverterTests.sql") +@SpringBootTest(properties = { + "spring.sql.init.data-locations=GraphQLJpaConverterTests.sql", + "spring.datasource.url=jdbc:h2:mem:db;NON_KEYWORDS=VALUE" +}) public class GraphQLJpaConverterTests extends AbstractSpringBootTestSupport { @SpringBootApplication diff --git a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/embeddedid/EntityWithEmbeddedIdTest.java b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/embeddedid/EntityWithEmbeddedIdTest.java index 020cb4efe..3768992aa 100644 --- a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/embeddedid/EntityWithEmbeddedIdTest.java +++ b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/embeddedid/EntityWithEmbeddedIdTest.java @@ -16,7 +16,7 @@ import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor; import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder; -@SpringBootTest(properties = "spring.datasource.data=EntityWithEmbeddedIdTest.sql") +@SpringBootTest(properties = "spring.sql.init.data-locations=EntityWithEmbeddedIdTest.sql") public class EntityWithEmbeddedIdTest extends AbstractSpringBootTestSupport { @SpringBootApplication diff --git a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/idclass/EntityWithIdClassTest.java b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/idclass/EntityWithIdClassTest.java index 3e1b70556..1591360db 100644 --- a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/idclass/EntityWithIdClassTest.java +++ b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/idclass/EntityWithIdClassTest.java @@ -16,7 +16,7 @@ import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor; import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder; -@SpringBootTest(properties = "spring.datasource.data=EntityWithIdClassTest.sql") +@SpringBootTest(properties = "spring.sql.init.data-locations=EntityWithIdClassTest.sql") public class EntityWithIdClassTest extends AbstractSpringBootTestSupport { @SpringBootApplication diff --git a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/localdatetime/GraphQLLocalDateTimeTest.java b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/localdatetime/GraphQLLocalDateTimeTest.java index a51977c20..a0e316226 100644 --- a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/localdatetime/GraphQLLocalDateTimeTest.java +++ b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/localdatetime/GraphQLLocalDateTimeTest.java @@ -19,7 +19,7 @@ import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor; import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder; -@SpringBootTest(properties = "spring.datasource.data=LocalDatetTmeData.sql") +@SpringBootTest(properties = "spring.sql.init.data-locations=LocalDatetTmeData.sql") public class GraphQLLocalDateTimeTest extends AbstractSpringBootTestSupport { @SpringBootApplication diff --git a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/restricted/RestrictedKeysProviderRelayTests.java b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/restricted/RestrictedKeysProviderRelayTests.java index ee2da8f39..0060a1e91 100644 --- a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/restricted/RestrictedKeysProviderRelayTests.java +++ b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/restricted/RestrictedKeysProviderRelayTests.java @@ -21,7 +21,7 @@ import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder; import com.introproventures.graphql.jpa.query.schema.model.uuid.Thing; -@SpringBootTest(properties = "spring.datasource.data=RestrictedKeysProviderTests.sql") +@SpringBootTest(properties = "spring.sql.init.data-locations=RestrictedKeysProviderTests.sql") public class RestrictedKeysProviderRelayTests extends AbstractSpringBootTestSupport { @SpringBootApplication diff --git a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/restricted/RestrictedKeysProviderSelectTests.java b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/restricted/RestrictedKeysProviderSelectTests.java index 991044b52..094213223 100644 --- a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/restricted/RestrictedKeysProviderSelectTests.java +++ b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/restricted/RestrictedKeysProviderSelectTests.java @@ -21,7 +21,7 @@ import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder; import com.introproventures.graphql.jpa.query.schema.model.uuid.Thing; -@SpringBootTest(properties = "spring.datasource.data=RestrictedKeysProviderTests.sql") +@SpringBootTest(properties = "spring.sql.init.data-locations=RestrictedKeysProviderTests.sql") public class RestrictedKeysProviderSelectTests extends AbstractSpringBootTestSupport { @SpringBootApplication diff --git a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/StarwarsQueryExecutorTests.java b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/StarwarsQueryExecutorTests.java index cbd9be3bd..a37e8811a 100644 --- a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/StarwarsQueryExecutorTests.java +++ b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/StarwarsQueryExecutorTests.java @@ -17,11 +17,13 @@ package com.introproventures.graphql.jpa.query.schema; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.tuple; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import javax.persistence.EntityManager; import javax.persistence.Query; @@ -90,6 +92,21 @@ public void JPASampleTester() { assertThat(result).hasSize(13); } + @Test + @Transactional + public void thingsTester() { + // given: + Query query = em.createQuery("select t from Thing t"); + + // when: + List result = query.getResultList(); + + // then: + assertThat(result).hasSize(1) + .extracting("id", "type") + .containsOnly(tuple(UUID.fromString("2d1ebc5b-7d27-4197-9cf0-e84451c5bbb1"), "Thing1")); + } + @Test @Transactional public void queryManyToManyTester() { diff --git a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/model/uuid/Thing.java b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/model/uuid/Thing.java index 010bbef65..bb5c5713d 100644 --- a/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/model/uuid/Thing.java +++ b/graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/model/uuid/Thing.java @@ -2,6 +2,7 @@ import java.util.UUID; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -14,6 +15,7 @@ public class Thing { @Id @GraphQLDescription("Primary Key for the Thing Class") + @Column(columnDefinition = "uuid") UUID id; String type;