Source is sometimes resolved as object and other times as LinkedHashMap
source code:
type Query {
getAccounts: [Account]!
getAccountById(accountId: ID!): Account
}
type Customer {
id: ID!
email: String!
accounts: [Account]!
}
type Account {
id: ID!
balance: Float!
customer: Customer!
}
Controller:
@Controller
class AccountController {
@QueryMapping
fun getAccounts(): List<Account> = getAccounts()
@QueryMapping
fun getAccountById(@Argument accountId: String): Account? = getAccount(accountId)
@SchemaMapping(typeName = "Account", field = "customer")
fun getCustomerFromAccount(source: Account): Customer? = getCustomer(source.customerId)
}
data class Account(
val id: UUID,
val balance: BigDecimal,
val customerId: UUID
)
data class Customer(
val id: UUID,
val email: String
)
Issue Statement
When I try to query
query {
getAccountById(accountId:"2e7a7e62-10fe-4d42-8806-889e7e7a1fa4"){
balance
customer {
email
}
}
}
it works because the getCustomerFromAccount method's source argument is resolved as an Account type.
But if I try this,
query {
getAccounts{
balance
customer {
email
}
}
}
This does not work as getCustomerFromAccount method's source argument is expected as an LinkedHashMap type.
What am I doing wrong?
Stacktrace:
java.lang.IllegalStateException: Parameter [0] in public org.dripto.banking.graphql.aggregator.Customer org.dripto.banking.graphql.aggregator.AccountController.getCustomerFromAccount(org.dripto.banking.graphql.aggregator.Account): does not match the source Object type 'class java.util.LinkedHashMap'.
at org.springframework.graphql.data.method.annotation.support.SourceMethodArgumentResolver.resolveArgument(SourceMethodArgumentResolver.java:75) ~[spring-graphql-1.0.1.jar:1.0.1]
at org.springframework.graphql.data.method.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:83) ~[spring-graphql-1.0.1.jar:1.0.1]
at org.springframework.graphql.data.method.annotation.support.DataFetcherHandlerMethod.getMethodArgumentValues(DataFetcherHandlerMethod.java:170) ~[spring-graphql-1.0.1.jar:1.0.1]
at org.springframework.graphql.data.method.annotation.support.DataFetcherHandlerMethod.invoke(DataFetcherHandlerMethod.java:115) ~[spring-graphql-1.0.1.jar:1.0.1]
at org.springframework.graphql.data.method.annotation.support.AnnotatedControllerConfigurer$SchemaMappingDataFetcher.get(AnnotatedControllerConfigurer.java:514) ~[spring-graphql-1.0.1.jar:1.0.1]
at org.springframework.graphql.execution.ContextDataFetcherDecorator.lambda$get$0(ContextDataFetcherDecorator.java:74) ~[spring-graphql-1.0.1.jar:1.0.1]
at org.springframework.graphql.execution.ReactorContextManager.invokeCallable(ReactorContextManager.java:104) ~[spring-graphql-1.0.1.jar:1.0.1]
at org.springframework.graphql.execution.ContextDataFetcherDecorator.get(ContextDataFetcherDecorator.java:73) ~[spring-graphql-1.0.1.jar:1.0.1]
at graphql.execution.ExecutionStrategy.fetchField(ExecutionStrategy.java:279) ~[graphql-java-18.2.jar:na]
at graphql.execution.ExecutionStrategy.resolveFieldWithInfo(ExecutionStrategy.java:210) ~[graphql-java-18.2.jar:na]
at graphql.execution.AsyncExecutionStrategy.execute(AsyncExecutionStrategy.java:60) ~[graphql-java-18.2.jar:na]
at graphql.execution.ExecutionStrategy.completeValueForObject(ExecutionStrategy.java:667) ~[graphql-java-18.2.jar:na]
Versions
Kotlin Version: 1.7.10 Spring Boot: 2.7.2 JDK: 17 (temurin)
I am unable to reproduce the issue. Generally, SourceMethodArgumentResolver is a trivial resolver that simply returns environment.getSource(), so it's hard to imagine how this could be something on our end. We're simply exposing what GraphQL Java exposes through DataFetchingEnvironment.
I do notice there is recursive nesting in the schema with Account containing Customer and vice versa. It may have something to do that with, if the issue occurs at a more deeply nested level, and it could be why I am not able to reproduce it with my (simple) data.
Could you provide something we can run that demonstrates the issue?
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.