Search code examples
graphqlgraphql-javaspring-graphql

java-graphql use namespace type resolver with inner class cant access


Using a scheme with such set

type Query {
    client: ClientQuery!
}

type ClientQuery {
    info(clientId: String): Client
}

type Client {
    gender: String
    name: String
}

i have same reoslver for it

@Controller
class ClientResource {
   @QueryMapping
   fun client(@ContextValue clientId: Long): ClientQuery {
        val currentClient = getClient(clientId)
        log.info { "Current client $currentClient" }
        return query
    }

  @Controller
  class ClientQuery {
      @SchemaMapping(typeName = "ClientQuery ", field = "info")
      fun info(@Argument cleintId: String): Client {
         // some manipulation
        return Client()
      }
  }

}

but i want use inner class ClientQuery instead of class ClientQuery but when i use inner class when calling the graphiql request{client{info(clientId:"1"){gender,name}}} in the response comes null and I don’t see that there was a call to the inner class Maybe there is something that I am missing


Solution

  • Please verify you haven't made a typo in your @Argument cleintId , since in your graphiql request you mention you are sending clientId:"1".

    Also you could try putting both mappings at the same level inside the Controller:

       @QueryMapping
       fun client(@ContextValue clientId: Long): ChatQuery {
            val currentClient = getClient(clientId)
            log.info { "Current client $currentClient" }
            return query
        }
    
       @SchemaMapping(typeName = "ClientQuery ", field = "info")
       fun info(@Argument cleintId: String): Client {
          // some manipulation
         return Client()
       }