This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { KeycloakCrudService } from '@graphback/keycloak-authz' | |
| class CustomCrudService extends KeycloakCrudService { | |
| // custom implementation | |
| } | |
| const services = createKeycloakRuntimeContext({ | |
| models, | |
| schema: model, | |
| db, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ApolloServer } from 'apollo-server-express' | |
| import { createKeycloakRuntimeContext } from '@graphback/keycloak-authz' | |
| import { GraphbackRuntime } from 'graphback' | |
| import { KnexDbDataProvider } from '@graphback/runtime-knex' | |
| import { PubSub } from 'graphql-subscriptions' | |
| import * as Knex from 'knex' | |
| import { printSchema } from 'graphql' | |
| // the application model | |
| const model = ` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const authConfig = { | |
| Task: { | |
| create: {}, | |
| read: {}, | |
| update: { roles: ["admin"] }, | |
| delete: { roles: ["admin"] } | |
| }, | |
| Report: { | |
| create: { roles: ["admin"] }, | |
| read: {}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| input CreateNoteInput { | |
| id: ID | |
| content: String! | |
| _version: Int | |
| } | |
| input CreateTaskInput { | |
| id: ID | |
| title: String! | |
| description: String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ApolloOfflineClient } from 'offix-client'; | |
| import { InMemoryCache } from 'apollo-cache-inmemory'; | |
| import { HttpLink } from "apollo-link-http"; | |
| const config = { | |
| link: new HttpLink({ uri: 'http://example.com/graphql' }) | |
| cache: new InMemoryCache() | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Keycloak from 'keycloak-js' | |
| import { WebSocketLink } from 'apollo-link-ws' | |
| var keycloak = Keycloak({ | |
| url: 'http://keycloak-server/auth', | |
| realm: 'myrealm', | |
| clientId: 'myapp' | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const resolvers = { | |
| Subscription: { | |
| commentAdded: { | |
| subscribe: () => pubsub.asyncIterator(COMMENT_ADDED) | |
| }, | |
| messageAdded: { | |
| subscribe: auth(() => pubsub.asyncIterator(COMMENT_ADDED)) | |
| }, | |
| alertAdded: { | |
| subscribe: hasRole('admin')(() => pubsub.asyncIterator(ALERT_ADDED)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const keycloakSubscriptionHandler = new KeycloakSubscriptionHandler({ keycloak }) | |
| new SubscriptionServer({ | |
| execute, | |
| subscribe, | |
| schema: server.schema, | |
| onConnect: async (connectionParams, websocket, connectionContext) => { | |
| const token = await keycloakSubscriptionHandler.onSubscriptionConnect(connectionParams) | |
| return { | |
| kauth: new KeycloakSubscriptionContext(token) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { auth, hasRole } = require('keycloak-connect-graphql') | |
| const resolvers = { | |
| Article: { | |
| analytics: hasRole('editor')(articleAnalyticsResolver) | |
| }, | |
| Query: { | |
| listArticles: auth(listArticlesResolver) | |
| }, | |
| mutation: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const typeDefs = gql` | |
| type Article { | |
| id: ID! | |
| title: String! | |
| content: String! | |
| } | |
| type Query { | |
| listArticles: [Article]! @auth | |
| } |
NewerOlder