Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
From my medium post about Keycloak Auth in GraphQL
const typeDefs = gql`
type Article {
id: ID!
title: String!
content: String!
}
type Query {
listArticles: [Article]! @auth
}
type Mutation {
publishArticle(title: String!, content: String!): Article! @hasRole(role: "editor")
}
`
const resolvers = {
Query: {
listArticles: (obj, args, context, info) => {
return Database.listArticles()
}
},
mutation: {
publishArticle: (object, args, context, info) => {
const user = context.kauth.accessToken.content // get the user details from the access token
return Database.createArticle(args.title, args.content, user)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment