Skip to content

How can I implement GraphQL types by ignoring interfaces out of my hands? #1330

@wickedev

Description

@wickedev

Below is the class I want to create.

@GraphQLIgnore
interface SimpleUserDetails : org.springframework.security.core.userdetails.UserDetails {
    @GraphQLIgnore
    override fun isAccountNonExpired(): Boolean = true

    @GraphQLIgnore
    override fun isAccountNonLocked(): Boolean = true

    @GraphQLIgnore
    override fun isCredentialsNonExpired(): Boolean = true

    @GraphQLIgnore
    override fun isEnabled(): Boolean = true
}

@Table("users")
data class User(
    @Id override val id: ID = ID.Empty,

    val email: String,
    val name: String?,
    val hashSalt: String,
    val roles: List<String>,
) : Node, SimpleUserDetails {

    fun posts(
        @GraphQLIgnore @Autowired postRepository: PostRepository,
        env: DataFetchingEnvironment
    ): CompletableFuture<List<Post>> {
        return postRepository.findAllByAuthorId(id, env)
    }

    @GraphQLIgnore
    override fun getUsername(): String = email

    @GraphQLIgnore
    override fun getPassword(): String = hashSalt

    @GraphQLIgnore
    override fun getAuthorities(): Collection<GrantedAuthority> = roles.map { SimpleGrantedAuthority(it) }
}
Caused by: graphql.schema.validation.InvalidSchemaException: invalid schema:
object type 'User' does not implement interface 'UserDetails' because field 'isEnabled' is missing
object type 'User' does not implement interface 'UserDetails' because field 'getAuthorities' is missing
object type 'User' does not implement interface 'UserDetails' because field 'getPassword' is missing
object type 'User' does not implement interface 'UserDetails' because field 'getUsername' is missing
object type 'User' does not implement interface 'UserDetails' because field 'isAccountNonExpired' is missing
object type 'User' does not implement interface 'UserDetails' because field 'isAccountNonLocked' is missing
object type 'User' does not implement interface 'UserDetails' because field 'isCredentialsNonExpired' is missing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions