Hey Redwood Community,
I’m looking for some advice on the proper usage of directives. How should I restrict specific schema fields to only the owner, depending on another model?
For example (simplified):
// users.sdl.ts
export const schema = gql`
type User {
id: String!
username: String!
realname: String!
privacy PrivacyConfiguration
}
// privacyConfigurations.sdl.ts
export const schema = gql`
type PrivacyConfiguration {
id: String!
user: User!
userId: String!
showRealname: Boolean!
}
I would like always to include the realname
field when the user themselves sends the query. However, if someone else sends the query, only include the realname
field if showRealname
is set to true.
Is this too complex for a directive? If not, how would I go about implementing it?