2

I am using graphql-spqr-spring-boot-starter, version 0.0.5 in my spring boot application.

@GraphQLApi & @GraphQLQuery working fine and I am fetching data on /gui as well.

But as many have faced I am trying to apply the authentication part on graphql server calls. I am using JWT token in my application for REST API authorization/authentication.

So I have token which I suppose can be used for validation here as well.

I have tried using:

@PreAuthorize("hasRole('ROLE_RECRUITER_HR')")

but it gives compile time error:

io.leangen.graphql.metadata.exceptions.TypeMappingException: The registered object of type com.sun.proxy.$Proxy90 appears to be a dynamically generated proxy

For these and other possible issues, is it better to use wrapper graphql library like spring-boot-starter or it is safer to use graphql-spqr which more steps in my hand.

Talha DX
  • 33
  • 2
  • Hm, this really shouldn't be happening with recent versions. Spring Security should work transparently. Is it possible to see your project somewhere by any chance? Or, if not, could I bother you to make an example that reproduces the issue and I'll troubleshoot it for you? The only case where I'd expect this to happen is if you manually registered the beans using `GraphQLSchemaGenerator#withOperationsFromSingleton`, but since you mention you're using the starter, I reckon this is not what you're doing. – kaqqao Mar 07 '21 at 23:29
  • Yeah I can add you on github in the repo. Please share your username – Talha DX Mar 08 '21 at 04:40
  • It's [@kaqqao](https://github.com/kaqqao), same as here – kaqqao Mar 08 '21 at 09:54
  • Added. also there is a separate branch for graph-impl for testing out things. – Talha DX Mar 08 '21 at 13:24

1 Answers1

1

EDIT: GraphQL SPQR Spring Boot starter v0.0.6 fixed the issue and should work out of the box.

This is a bug in the starter. It doesn't properly detect the types when JDK proxies (and not CGLib) are used. I will make sure to fix this for the next release. There's a couple of ways to temporarily work around this, but none of them are nice unfortunately.

You could e.g. force Spring to use CGLIB by e.g.

@EnableAspectJAutoProxy(proxyTargetClass = true)

but this has potentially wide implications so I would recommend you simply wait a bit. I'll release a new version with a fix in a couple of days, as this is a very important bug.

kaqqao
  • 12,984
  • 10
  • 64
  • 118