This blog also assumes that you are familiar with GraphQL Schema Directives. If not, I recommend reading this Apollo documentation on Schema Directive.

Let’s say we have a basic Blogs application in which an User hasMany Posts and each Post in turn hasMany Comments.

Below is the gist containing the basic GraphQL schema of this application.

const typeDefs = gql`
  input PostInputType {
    id: Int!
    title: String!
    description: String
  }
  type CommentType {
    id: Int!
    comment: String!
  }
  type PostType {
    id: Int!
    title: String
    description: String
    comments: [CommentType]
  }
  type UserType {
    id: Int
    name: String
    email: String
    posts: [PostType]
  }
  type Query {
    users: [UserType]
    posts: [PostType]
  }
`;

#authorization #graphql #javascript #optimization #apollo-server

Authorization in GraphQL - Schema Directive vs. GraphQL Shield
7.75 GEEK