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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trait Typed<T> {
graphQLType = typeManager.getEnumType(type, nullable)
}
else if (typeManager.hasType(type)) {
graphQLType = (GraphQLInputType)typeManager.getType(type, nullable)
graphQLType = typeManager.getType(type, nullable)
}
else {
PersistentEntity entity = mappingContext?.getPersistentEntity(type.name)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package grails.test.app

import grails.test.app.pogo.Painting
import org.grails.gorm.graphql.entity.dsl.GraphQLMapping

class Artist {

String name

static graphql = GraphQLMapping.build {
add('paintings', [Painting]) {
dataFetcher {
return [new Painting(name: 'test', artistName: 'Picasso', heightCm: 60, widthCm: 120)]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package grails.test.app

import grails.gorm.transactions.Rollback
import grails.testing.mixin.integration.Integration
import org.grails.gorm.graphql.plugin.testing.GraphQLSpec
import org.hibernate.SessionFactory
import spock.lang.Specification

@Integration
@Rollback
class ArtistIntegrationSpec extends Specification implements GraphQLSpec {

SessionFactory sessionFactory

void "test listing artists and paintings"() {
given:
def a = new Artist(name: "Picasso").save(flush: true, failOnError: true)
sessionFactory.currentSession.flush()
sessionFactory.currentSession.transaction.commit()

when:
def resp = graphQL.graphql("""
{
artistList {
id
name
paintings {
name
heightCm
widthCm
}
}
}
""")
def json = resp.body()
println json.toString()
def artists = json.data.artistList
def artist = artists[0]

then:
artists.size() == 1
artist.id == a.id
artist.name == "Picasso"
artist.paintings.size() == 1
artist.paintings[0].name == "test"
artist.paintings[0].heightCm == 60
artist.paintings[0].widthCm == 120
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package grails.test.app

import grails.test.app.pogo.Painting
import grails.test.app.pogo.Profile
import graphql.schema.GraphQLObjectType
import graphql.schema.GraphQLOutputType
import org.grails.gorm.graphql.binding.manager.GraphQLDataBinderManager
import org.grails.gorm.graphql.fetcher.GraphQLDataFetcherType
import org.grails.gorm.graphql.interceptor.impl.BaseGraphQLFetcherInterceptor
Expand All @@ -14,6 +18,9 @@ import org.grails.gorm.graphql.fetcher.impl.EntityDataFetcher
import org.grails.gorm.graphql.fetcher.impl.SingleEntityDataFetcher
import org.grails.gorm.graphql.fetcher.impl.SoftDeleteEntityDataFetcher
import org.grails.gorm.graphql.fetcher.manager.GraphQLDataFetcherManager
import org.grails.gorm.graphql.types.GraphQLTypeManager

import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition


@CompileStatic
Expand Down Expand Up @@ -57,4 +64,27 @@ class GraphQLCustomizer extends GraphQLPostProcessor {
binderManager.registerDataBinder(User, new UserDataBinder())
binderManager.registerDataBinder(Role, new RoleDataBinder())
}

@Override
void doWith(GraphQLTypeManager typeManager) {
GraphQLOutputType stringType = (GraphQLOutputType)typeManager.getType(String)
GraphQLOutputType intType = (GraphQLOutputType)typeManager.getType(Integer)
GraphQLObjectType.Builder builder = GraphQLObjectType.newObject()
.name('Painting')
.field(newFieldDefinition()
.name('name')
.type(stringType))
.field(newFieldDefinition()
.name('artistName')
.type(stringType))
.field(newFieldDefinition()
.name('heightCm')
.type(intType))
.field(newFieldDefinition()
.name('widthCm')
.type(intType))


typeManager.registerType(Painting, builder.build())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package grails.test.app.pogo

class Painting {

String name
String artistName
Integer heightCm
Integer widthCm

}