Skip to content

Support mapping of GraphQL directives to annotations #241

@kobylynskyi

Description

@kobylynskyi

Given schema with custom directive:

type Query {
    version: String @auth(roles: ["ROLE_VIEWER", "ROLE_GUEST"])
    logs: [String] @auth(roles: ["ROLE_ADMIN"])
}

directive @auth (roles: [String] = ["viewer"]) on QUERY | MUTATION | SUBSCRIPTION

and graphql-java-codegen config:

<configuration>
    ...
    <directiveAnnotationsMapping>
        <auth>@org.springframework.security.access.annotation.Secured({{roles}})</auth>
    </directiveAnnotationsMapping>
</configuration>

Note: here {{roles}} will be replaced with the value of the corresponding @auth directive parameter roles.

Generated API resolvers will look like:

public interface VersionQueryResolver {
    @org.springframework.security.access.annotation.Secured({"ROLE_VIEWER", "ROLE_GUEST"})
    String version() throws Exception;
}

public interface LogsQueryResolver {
    @org.springframework.security.access.annotation.Secured({"ROLE_ADMIN"})
    java.util.List<String> logs() throws Exception;
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions