Skip to content

Commit

Permalink
Merge pull request #70 from kirpi4ik/java-gql-v17
Browse files Browse the repository at this point in the history
Upgrade to the latest graphql-java v17.3
  • Loading branch information
puneetbehl authored Jan 16, 2023
2 parents 69cd202 + d6659d6 commit 3ad0be1
Show file tree
Hide file tree
Showing 32 changed files with 175 additions and 488 deletions.
7 changes: 4 additions & 3 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies {

compile "org.grails:grails-datastore-gorm:${gormVersion}"
compile "com.graphql-java:graphql-java:$graphqlJavaVersion"
compile "com.graphql-java:graphql-java-extended-scalars:$graphqlJavaScalarExtVersion"

codenarc "org.codenarc:CodeNarc:$codenarcVersion"

Expand All @@ -24,12 +25,12 @@ codenarc {
toolVersion = codenarcVersion
configFile = file("${projectDir}/config/codenarc/rules.groovy")
maxPriority1Violations = 0
maxPriority2Violations = 2
maxPriority3Violations = 8
maxPriority2Violations = 0
maxPriority3Violations = 0
}

codenarcMain {
exclude '**/GormScalars.groovy'
exclude '**/CustomScalars.groovy'
}

codenarcTest {
Expand Down
50 changes: 27 additions & 23 deletions core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import org.grails.gorm.graphql.entity.property.manager.GraphQLDomainPropertyMana
import org.grails.gorm.graphql.fetcher.BindingGormDataFetcher
import org.grails.gorm.graphql.fetcher.DeletingGormDataFetcher
import org.grails.gorm.graphql.fetcher.PaginatingGormDataFetcher
import org.grails.gorm.graphql.fetcher.impl.*
import org.grails.gorm.graphql.fetcher.impl.CountEntityDataFetcher
import org.grails.gorm.graphql.fetcher.impl.CreateEntityDataFetcher
import org.grails.gorm.graphql.fetcher.impl.DeleteEntityDataFetcher
import org.grails.gorm.graphql.fetcher.impl.EntityDataFetcher
import org.grails.gorm.graphql.fetcher.impl.PaginatedEntityDataFetcher
import org.grails.gorm.graphql.fetcher.impl.SingleEntityDataFetcher
import org.grails.gorm.graphql.fetcher.impl.UpdateEntityDataFetcher
import org.grails.gorm.graphql.fetcher.interceptor.InterceptingDataFetcher
import org.grails.gorm.graphql.fetcher.interceptor.InterceptorInvoker
import org.grails.gorm.graphql.fetcher.interceptor.MutationInterceptorInvoker
Expand All @@ -40,10 +46,8 @@ import org.grails.gorm.graphql.response.pagination.GraphQLPaginationResponseHand
import org.grails.gorm.graphql.types.DefaultGraphQLTypeManager
import org.grails.gorm.graphql.types.GraphQLPropertyType
import org.grails.gorm.graphql.types.GraphQLTypeManager
import org.grails.gorm.graphql.types.scalars.GraphQLDate
import org.grails.gorm.graphql.types.scalars.coercing.DateCoercion
import org.grails.gorm.graphql.types.scalars.coercing.jsr310.*
import org.grails.gorm.graphql.types.scalars.jsr310.*
import org.springframework.context.support.StaticMessageSource
import javax.annotation.PostConstruct
import java.time.Instant
Expand All @@ -59,6 +63,7 @@ import static graphql.schema.GraphQLArgument.newArgument
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition
import static graphql.schema.GraphQLList.list
import static graphql.schema.GraphQLObjectType.newObject
import static graphql.schema.GraphQLScalarType.newScalar
import static org.grails.gorm.graphql.fetcher.GraphQLDataFetcherType.*

/**
Expand All @@ -83,9 +88,10 @@ class Schema {
GraphQLPaginationResponseHandler paginationResponseHandler
GraphQLServiceManager serviceManager

Map<String, GraphQLInputType> listArguments

List<String> dateFormats
boolean dateFormatLenient = false
Map<String, GraphQLInputType> listArguments

private boolean initialized = false

Expand Down Expand Up @@ -113,28 +119,28 @@ class Schema {

void populateDefaultDateTypes() {
if (!typeManager.hasType(Date)) {
typeManager.registerType(Date, new GraphQLDate(new DateCoercion(dateFormats, dateFormatLenient)))
typeManager.registerType(Date, newScalar().name('Date').description('Built-in Date').coercing(new DateCoercion(dateFormats, dateFormatLenient)).build())
}
if (!typeManager.hasType(Instant)) {
typeManager.registerType(Instant, new GraphQLInstant(new InstantCoercion()))
typeManager.registerType(Instant, newScalar().name('Instant').description('Built-in Instant').coercing(new InstantCoercion()).build())
}
if (!typeManager.hasType(LocalDate)) {
typeManager.registerType(LocalDate, new GraphQLLocalDate(new LocalDateCoercion(dateFormats)))
typeManager.registerType(LocalDate, newScalar().name('LocalDate').description('Built-in LocalDate').coercing(new LocalDateCoercion(dateFormats)).build())
}
if (!typeManager.hasType(LocalDateTime)) {
typeManager.registerType(LocalDateTime, new GraphQLLocalDateTime(new LocalDateTimeCoercion(dateFormats)))
typeManager.registerType(LocalDateTime, newScalar().name('LocalDateTime').description('Built-in LocalDateTime').coercing(new LocalDateTimeCoercion(dateFormats)).build())
}
if (!typeManager.hasType(LocalTime)) {
typeManager.registerType(LocalTime, new GraphQLLocalTime(new LocalTimeCoercion(dateFormats)))
typeManager.registerType(LocalTime, newScalar().name('LocalTime').description('Built-in LocalTime').coercing(new LocalTimeCoercion(dateFormats)).build())
}
if (!typeManager.hasType(OffsetDateTime)) {
typeManager.registerType(OffsetDateTime, new GraphQLOffsetDateTime(new OffsetDateTimeCoercion(dateFormats)))
typeManager.registerType(OffsetDateTime, newScalar().name('OffsetDateTime').description('Built-in OffsetDateTime').coercing(new OffsetDateTimeCoercion(dateFormats)).build())
}
if (!typeManager.hasType(OffsetTime)) {
typeManager.registerType(OffsetTime, new GraphQLOffsetTime(new OffsetTimeCoercion(dateFormats)))
typeManager.registerType(OffsetTime, newScalar().name('OffsetTime').description('Built-in OffsetTime').coercing(new OffsetTimeCoercion(dateFormats)).build())
}
if (!typeManager.hasType(ZonedDateTime)) {
typeManager.registerType(ZonedDateTime, new GraphQLZonedDateTime(new ZonedDateTimeCoercion(dateFormats)))
typeManager.registerType(ZonedDateTime, newScalar().name('ZonedDateTime').description('Built-in ZonedDateTime').coercing(new ZonedDateTimeCoercion(dateFormats)).build())
}
}

Expand Down Expand Up @@ -365,9 +371,8 @@ class Schema {
}
GraphQLInputType createObjectType = typeManager.getMutationType(entity, GraphQLPropertyType.CREATE, true)

if(!createObjectType.getChildren().isEmpty()) {
if (!createObjectType.children.empty) {
BindingGormDataFetcher createFetcher = dataFetcherManager.getBindingFetcher(entity, CREATE).orElse(new CreateEntityDataFetcher(entity))

createFetcher.dataBinder = dataBinder

final String CREATE_FIELD_NAME = namingConvention.getCreate(entity)
Expand All @@ -378,8 +383,8 @@ class Schema {
.description(createOperation.description)
.deprecate(createOperation.deprecationReason)
.argument(newArgument()
.name(entity.decapitalizedName)
.type(createObjectType))
.name(entity.decapitalizedName)
.type(createObjectType))

codeRegistry.dataFetcher(
coordinates(MUTATION_TYPE_NAME, CREATE_FIELD_NAME),
Expand Down Expand Up @@ -489,20 +494,19 @@ class Schema {
schemaInterceptor.interceptSchema(queryType, mutationType, additionalTypes)
}

GraphQLSchema.Builder schemaBuilder = GraphQLSchema.newSchema()
GraphQLSchema.Builder schema = GraphQLSchema.newSchema()
.codeRegistry(codeRegistry.build())
.additionalTypes(additionalTypes)

GraphQLObjectType mutation = mutationType.build()
if(mutation.fieldDefinitions) {
schemaBuilder.mutation(mutation)
if (mutation.fieldDefinitions) {
schema.mutation(mutation)
}
GraphQLObjectType query = queryType.build()
if(query.fieldDefinitions) {
schemaBuilder.query(query)
return schemaBuilder.build()
if (query.fieldDefinitions) {
schema.query(query)
return schema.build()
}

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.grails.gorm.graphql.testing

import graphql.GraphQLContext
import graphql.cachecontrol.CacheControl
import graphql.execution.ExecutionId
import graphql.execution.ExecutionStepInfo
Expand All @@ -9,12 +10,7 @@ import graphql.language.Document
import graphql.language.Field
import graphql.language.FragmentDefinition
import graphql.language.OperationDefinition
import graphql.schema.DataFetchingEnvironment
import graphql.schema.DataFetchingFieldSelectionSet
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.GraphQLOutputType
import graphql.schema.GraphQLSchema
import graphql.schema.GraphQLType
import graphql.schema.*
import groovy.transform.CompileStatic
import org.dataloader.DataLoader
import org.dataloader.DataLoaderRegistry
Expand Down Expand Up @@ -58,6 +54,11 @@ class MockDataFetchingEnvironment implements DataFetchingEnvironment {
arguments.containsKey(name)
}

@Override
GraphQLContext getGraphQlContext() {
GraphQLContext.newContext().build()
}

@Override
Object getArgumentOrDefault(String name, Object defaultValue) {
arguments.getOrDefault(name, defaultValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.gorm.graphql.types

import graphql.Scalars
import graphql.scalars.ExtendedScalars
import graphql.schema.*
import groovy.transform.CompileStatic
import org.grails.datastore.mapping.model.PersistentEntity
Expand All @@ -16,7 +17,7 @@ import org.grails.gorm.graphql.types.output.EmbeddedObjectTypeBuilder
import org.grails.gorm.graphql.types.output.ObjectTypeBuilder
import org.grails.gorm.graphql.types.output.PaginatedObjectTypeBuilder
import org.grails.gorm.graphql.types.output.ShowObjectTypeBuilder
import org.grails.gorm.graphql.types.scalars.*
import org.grails.gorm.graphql.types.scalars.CustomScalars

import java.lang.reflect.Array
import java.sql.Time
Expand All @@ -36,26 +37,26 @@ class DefaultGraphQLTypeManager implements GraphQLTypeManager {

protected static final Map<Class, GraphQLType> TYPE_MAP = new ConcurrentHashMap<Class, GraphQLType>([
(Integer): Scalars.GraphQLInt,
(Long): Scalars.GraphQLLong,
(Short): Scalars.GraphQLShort,
(Byte): Scalars.GraphQLByte,
(Byte[]): new GraphQLByteArray(),
(Long): ExtendedScalars.GraphQLLong,
(Short): ExtendedScalars.GraphQLShort,
(Byte): ExtendedScalars.GraphQLByte,
(Byte[]): CustomScalars.GraphQLByteArray,
(Double): Scalars.GraphQLFloat,
(Float): Scalars.GraphQLFloat,
(BigInteger): Scalars.GraphQLBigInteger,
(BigDecimal): Scalars.GraphQLBigDecimal,
(BigInteger): ExtendedScalars.GraphQLBigInteger,
(BigDecimal): ExtendedScalars.GraphQLBigDecimal,
(String): Scalars.GraphQLString,
(Boolean): Scalars.GraphQLBoolean,
(Character): Scalars.GraphQLChar,
(Character[]): new GraphQLCharacterArray(),
(UUID): new GraphQLUUID(),
(URL): new GraphQLURL(),
(URI): new GraphQLURI(),
(Time): new GraphQLTime(),
(java.sql.Date): new GraphQLSqlDate(),
(Timestamp): new GraphQLTimestamp(),
(Currency): new GraphQLCurrency(),
(TimeZone): new GraphQLTimeZone()
(Character): ExtendedScalars.GraphQLChar,
(Character[]): CustomScalars.GraphQLCharacterArray,
(UUID): CustomScalars.GraphQLUUID,
(URL): CustomScalars.GraphQLURL,
(URI): CustomScalars.GraphQLURI,
(Time): CustomScalars.GraphQLTime,
(java.sql.Date): CustomScalars.GraphQLSqlDate,
(Timestamp): CustomScalars.GraphQLTimestamp,
(Currency): CustomScalars.GraphQLCurrency,
(TimeZone): CustomScalars.GraphQLTimeZone
])

protected static final Map<Class, GraphQLEnumType> ENUM_TYPES = new ConcurrentHashMap<>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.grails.gorm.graphql.types.scalars

import graphql.schema.GraphQLScalarType
import org.grails.gorm.graphql.types.scalars.coercing.*

/**
* Custom scalars
*/
class CustomScalars {

public static final GraphQLScalarType GraphQLByteArray = GraphQLScalarType.newScalar()
.name('ByteArray').description('Built-in ByteArray').coercing(new ByteArrayCoercion()).build()
public static final GraphQLScalarType GraphQLCharacterArray = GraphQLScalarType.newScalar()
.name('CharacterArray').description('Built-in CharacterArray').coercing(new CharacterArrayCoercion()).build()
public static final GraphQLScalarType GraphQLCurrency = GraphQLScalarType.newScalar()
.name('Currency').description('Accepts a string currency code').coercing(new CurrencyCoercion()).build()
public static final GraphQLScalarType GraphQLSqlDate = GraphQLScalarType.newScalar()
.name('SqlDate').description('Accepts a number or a string in the format "yyyy-[m]m-[d]d"').coercing(new SqlDateCoercion()).build()
public static final GraphQLScalarType GraphQLTime = GraphQLScalarType.newScalar()
.name('Time').description('Accepts a number or string in the format "hh:mm:ss"').coercing(new TimeCoercion()).build()
public static final GraphQLScalarType GraphQLTimestamp = GraphQLScalarType.newScalar()
.name('Timestamp').description('Accepts a numer or a string in the format "yyyy-[m]m-[d]d hh:mm:ss[.f...]"').coercing(new TimestampCoercion()).build()
public static final GraphQLScalarType GraphQLTimeZone = GraphQLScalarType.newScalar()
.name('TimeZone').description('Accepts a string time zone id').coercing(new TimeZoneCoercion()).build()
public static final GraphQLScalarType GraphQLURI = GraphQLScalarType.newScalar()
.name('URI').description('Accepts a string in the form of a URI').coercing(new URICoercion()).build()
public static final GraphQLScalarType GraphQLURL = GraphQLScalarType.newScalar()
.name('URL').description('Accepts a string in the form of a URL').coercing(new URLCoercion()).build()
public static final GraphQLScalarType GraphQLUUID = GraphQLScalarType.newScalar()
.name('UUID').description('Accepts a string to be converted to a UUID').coercing(new UUIDCoercion()).build()

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 3ad0be1

Please sign in to comment.