Closed jamesdh closed 3 years ago
You would have to show what the code that is causing this is in order for us to determine the issue
@jameskleeh I'm facing the same issue. The resolveType
method in Typed
trait is assuming all types held by typeManager
to be of type GraphQLInputType
else if (typeManager.hasType(type)) {
graphQLType = (GraphQLInputType)typeManager.getType(type, nullable)
}
I believe there's no apparent need to cast to GraphQLInputType
. Because of that cast, if I do this:
MyType
custom type:
void doWith(GraphQLTypeManager typeManager) {
typeManager.registerType(MyType, GraphQLObjectType
.newObject()
.name('MyType'))
.fields([
// ...
])
.build()
}
mutation('someMutation', MyType) {
argument('id', Long)
// ...
}
Cannot cast object 'GraphQLObjectType{name='MyType', ... }' with class 'graphql.schema.GraphQLObjectType' to class 'graphql.schema.GraphQLInputType
I hope that's clear
@diffcunha this should be fixed via #62
@jamesdh That is awesome! Let me take a look a your PR
@diffcunha if you're in need of it now, I've got this fix (and a few other additions) in my own published package at https://github.com/jamesdh/gorm-graphql/packages/542850. Feel free to use that, just be aware that your gradle build file needs to be configured with a GitHub Personal Access Token in order to access public packages in the GitHub Package Repo.
repositories {
mavenLocal()
jcenter()
maven { url "https://repo.grails.org/grails/core" }
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/jamesdh/gorm-graphql")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GPR_USER")
password = project.findProperty("gpr.token") ?: System.getenv("GPR_TOKEN")
}
}
}
Working through the docs on Type Conversion and Creation I thought it would be fairly straight forward to register a custom output object (non-scalar) type that isn't a persistent entity. However, I'm not sure it's possible given how the Typed trait resolves output types.
https://github.com/grails/gorm-graphql/blob/4143ecd83f6e13f50f81a0e0354ceacde0ea1df2/core/src/main/groovy/org/grails/gorm/graphql/entity/dsl/helpers/Typed.groovy#L55-L72
As you can see in line 55/56, it tries to retrieve it and typecast it as a GraphQLInputType, resulting in...
Mostly just creating this as a reminder to myself to submit a fix, but would appreciate any insights others might have in case I'm missing something obvious.