Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -365,27 +365,29 @@ class Schema {
}
GraphQLInputType createObjectType = typeManager.getMutationType(entity, GraphQLPropertyType.CREATE, true)

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

createFetcher.dataBinder = dataBinder
createFetcher.dataBinder = dataBinder

final String CREATE_FIELD_NAME = namingConvention.getCreate(entity)
final String CREATE_FIELD_NAME = namingConvention.getCreate(entity)

GraphQLFieldDefinition.Builder create = newFieldDefinition()
.name(CREATE_FIELD_NAME)
.type(OBJECT_TYPE)
.description(createOperation.description)
.deprecate(createOperation.deprecationReason)
.argument(newArgument()
.name(entity.decapitalizedName)
.type(createObjectType))
GraphQLFieldDefinition.Builder create = newFieldDefinition()
.name(CREATE_FIELD_NAME)
.type(OBJECT_TYPE)
.description(createOperation.description)
.deprecate(createOperation.deprecationReason)
.argument(newArgument()
.name(entity.decapitalizedName)
.type(createObjectType))

codeRegistry.dataFetcher(
coordinates(MUTATION_TYPE_NAME, CREATE_FIELD_NAME),
new InterceptingDataFetcher(entity, serviceManager, mutationInterceptorInvoker, CREATE, createFetcher)
)
codeRegistry.dataFetcher(
coordinates(MUTATION_TYPE_NAME, CREATE_FIELD_NAME),
new InterceptingDataFetcher(entity, serviceManager, mutationInterceptorInvoker, CREATE, createFetcher)
)

mutationFields.add(create)
mutationFields.add(create)
}
}

ProvidedOperation updateOperation = mapping.operations.update
Expand Down Expand Up @@ -487,12 +489,20 @@ class Schema {
schemaInterceptor.interceptSchema(queryType, mutationType, additionalTypes)
}

GraphQLSchema.newSchema()
GraphQLSchema.Builder schemaBuilder = GraphQLSchema.newSchema()
.codeRegistry(codeRegistry.build())
.query(queryType)
.mutation(mutationType)
.additionalTypes(additionalTypes)
.build()

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

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class DisableAllOpSpec extends HibernateSpec {
.generate()

then:
schema.queryType.fieldDefinitions.isEmpty()
schema.mutationType.fieldDefinitions.isEmpty()
!schema
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import grails.gorm.annotation.Entity
import graphql.schema.GraphQLSchema
import org.grails.datastore.gorm.GormEntity
import org.grails.gorm.graphql.entity.dsl.GraphQLMapping
import spock.lang.Ignore

class DisableReadOpSpec extends HibernateSpec {

Expand All @@ -12,14 +13,16 @@ class DisableReadOpSpec extends HibernateSpec {
[ReadDisabledEntity]
}

// As of graphql-java 15.0, it appears a queryType is required
@Ignore
void "test that disable all operation in clean way"() {

when:
GraphQLSchema schema = new Schema(hibernateDatastore.mappingContext)
.generate()

then:
schema.queryType.fieldDefinitions.isEmpty()
!schema.queryType

and:
schema.mutationType.fieldDefinitions.size() == 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ReadOnlyOperationsSpec extends HibernateSpec {
.generate()

then:
schema.mutationType.fieldDefinitions.isEmpty()
!schema.mutationType

and:
schema.queryType.fieldDefinitions.size() == 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ class DemoApplication {

@Bean
GraphQL graphQL(@Autowired HibernateDatastore datastore) {
new GraphQL(new Schema(datastore.mappingContext).generate())
GraphQL.newGraphQL(new Schema(datastore.mappingContext).generate()).build()
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ groovyVersion=2.5.14
slf4jVersion=1.7.36
spockVersion=1.3-groovy-2.5
micronautVersion=1.0.3
graphqlJavaVersion=14.1
graphqlJavaVersion=16.1
codenarcVersion=1.6.1
viewGradleVersion=2.0.0
viewsJsonVersion=2.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class GormGraphqlGrailsPlugin extends Plugin {
}

graphQLSchema(graphQLSchemaGenerator: "generate")
graphQL(GraphQL, ref("graphQLSchema"))
graphQLBuilder(GraphQL.Builder, ref("graphQLSchema"))

graphQL(GraphQL) { bean ->
bean.factoryBean = "graphQLBuilder"
bean.factoryMethod = "build"
}
}}
}