I have already created a hasRole directive. I only want to include certain input parameters if the user has the admin role:
const typeDefs = gql`
type Article {
id: ID!
title: String!
content: String!
sponsor: String
}
input CreateArticleInput {
title: String!
content: String!
sponsor: String // include if @hasRole(role: "admin")
type Mutation {
createArticle(input: CreateArticleInput!): Article!
publishArticle(articleId: ID!): Boolean! @hasRole(role: "editor")
}
`
The goal is to provide the sponsor input parameter optionally if the user has the role "admin", otherwise, do not let the user include a "sponsor". I wonder if the native @include or @skip directives can be used in tandem with my custom @hasRole directive to achieve this? ..just a thought.
Is something like this possible? I am not even sure if this is allowed in the input type.
Comments
Post a Comment