diff --git a/client/package.json b/client/package.json index 11616b8c..d0062c9d 100644 --- a/client/package.json +++ b/client/package.json @@ -5,36 +5,36 @@ "dependencies": { "@apollo/react-hooks": "3.1.5", "@capacitor/core": "2.1.2", - "@ionic/react": "5.0.7", - "@ionic/react-router": "5.0.7", - "@testing-library/jest-dom": "5.3.0", - "@testing-library/react": "10.0.2", - "@testing-library/user-event": "10.0.1", - "@types/jest": "25.1.4", - "@types/node": "12.12.34", - "@types/react": "16.9.29", - "@types/react-dom": "16.9.5", - "@types/react-router": "5.1.4", - "@types/react-router-dom": "5.1.3", + "@ionic/react": "5.1.1", + "@ionic/react-router": "5.1.1", + "@testing-library/jest-dom": "5.9.0", + "@testing-library/react": "10.2.0", + "@testing-library/user-event": "10.4.1", + "@types/jest": "25.2.3", + "@types/node": "12.12.44", + "@types/react": "16.9.35", + "@types/react-dom": "16.9.8", + "@types/react-router": "5.1.7", + "@types/react-router-dom": "5.1.5", "apollo-link-context": "1.0.20", "apollo-link-ws": "1.0.20", "graphql": "14.6.0", "graphql-tag": "2.10.3", "ionicons": "5.0.1", "keycloak-js": "10.0.2", - "offix-cache": "0.15.0", - "offix-client": "0.15.0", + "offix-cache": "0.15.1", + "offix-client": "0.15.1", "react": "16.13.1", "react-dom": "16.13.1", - "react-offix-hooks": "0.15.0", + "react-offix-hooks": "0.15.1", "react-router": "5.2.0", "react-router-dom": "5.2.0", "react-scripts": "3.4.1", "subscriptions-transport-ws": "0.9.16", - "typescript": "3.8.3", + "typescript": "3.9.5", "uniforms-ionic": "0.0.11", - "uniforms": "3.0.0-alpha.3", - "uniforms-bridge-simple-schema-2": "3.0.0-alpha.3" + "uniforms": "3.0.0-alpha.4", + "uniforms-bridge-simple-schema-2": "3.0.0-alpha.4" }, "scripts": { "start": "npm run build && cap serve", diff --git a/client/src/components/NetworkBadge.tsx b/client/src/components/NetworkBadge.tsx index 59044d95..95dccf33 100644 --- a/client/src/components/NetworkBadge.tsx +++ b/client/src/components/NetworkBadge.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { IonBadge } from '@ionic/react'; -export const NetworkBadge: React.FC<{ isOnline: boolean}> = ({ isOnline }) => { +export const NetworkBadge: React.FC<{ isOnline?: boolean}> = ({ isOnline }) => { return (isOnline) ?Online diff --git a/package.json b/package.json index 7073e7e9..0f81081b 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "description": "Mono repository for DataSync Starter", "main": "index.js", "devDependencies": { - "del-cli": "3.0.0", - "@graphback/codegen-offix": "0.11.4", - "graphback-cli": "0.11.4" + "del-cli": "3.0.1", + "@graphback/codegen-offix": "0.12.1", + "graphback-cli": "0.12.1" }, "scripts": { "start:server": "cd server && yarn start", @@ -26,6 +26,6 @@ "server" ], "resolutions": { - "@types/react": "16.9.34" + "@types/react": "16.9.35" } } diff --git a/server/package.json b/server/package.json index 2d0cecd7..c031e93d 100644 --- a/server/package.json +++ b/server/package.json @@ -13,26 +13,26 @@ "license": "MIT", "devDependencies": { "@types/cors": "2.8.6", - "@types/express": "4.17.3", - "@types/node": "13.9.8", + "@types/express": "4.17.6", + "@types/node": "13.13.10", "graphql": "14.6.0", "keycloak-request-token": "0.1.0", - "ts-node": "8.8.1", + "ts-node": "8.10.2", "ts-node-dev": "1.0.0-pre.44", - "tslint": "6.1.0", - "typescript": "3.8.3" + "tslint": "6.1.2", + "typescript": "3.9.5" }, "dependencies": { "@graphql-toolkit/file-loading": "0.10.7", "@aerogear/graphql-mqtt-subscriptions": "1.1.3", - "@graphback/runtime-mongo": "0.11.4", - "mongodb": "3.5.5", - "@types/react": "16.9.29", + "@graphback/runtime-mongo": "0.12.1", + "mongodb": "3.5.8", + "@types/react": "16.9.35", "apollo-server-express": "2.14.2", "cors": "2.8.5", "dotenv": "8.2.0", "express": "4.17.1", - "express-session": "1.17.0", + "express-session": "1.17.1", "graphql-tag": "2.10.3", "keycloak-connect": "10.0.2", "keycloak-connect-graphql": "0.6.0", diff --git a/server/src/auth.ts b/server/src/auth.ts index b950853f..b12fed1b 100644 --- a/server/src/auth.ts +++ b/server/src/auth.ts @@ -1,7 +1,7 @@ import { Express } from "express"; import { config } from './config/config'; -import { +import { KeycloakTypeDefs, KeycloakSchemaDirectives, KeycloakSubscriptionContext, @@ -13,55 +13,50 @@ const session = require('express-session') const Keycloak = require('keycloak-connect') export function buildKeycloakApolloConfig(app: Express, apolloConfig: any) { - if (config.keycloakConfig) { - const graphqlPath = `/graphql`; - console.log("Using keycloak configuration") - - const memoryStore = new session.MemoryStore() - app.use(session({ - secret: process.env.SESSION_SECRET_STRING || 'this should be a long secret', - resave: false, - saveUninitialized: true, - store: memoryStore - })) - - const keycloak = new Keycloak({ - store: memoryStore - }, config.keycloakConfig); - const keycloakSubscriptionHandler = new KeycloakSubscriptionHandler({ keycloak }) - - app.use(keycloak.middleware()) - - app.use(graphqlPath, keycloak.protect()); - - return { - typeDefs: [KeycloakTypeDefs, apolloConfig.typeDefs], // 1. Add the Keycloak Type Defs - schemaDirectives: KeycloakSchemaDirectives, - resolvers: apolloConfig.resolvers, - playground: apolloConfig.playground, - path: graphqlPath, - context: ({ req }) => { + const graphqlPath = `/graphql`; + console.log("Using keycloak configuration") + + const memoryStore = new session.MemoryStore() + app.use(session({ + secret: process.env.SESSION_SECRET_STRING || 'this should be a long secret', + resave: false, + saveUninitialized: true, + store: memoryStore + })) + + const keycloak = new Keycloak({ + store: memoryStore + }, config.keycloakConfig); + const keycloakSubscriptionHandler = new KeycloakSubscriptionHandler({ keycloak }) + + app.use(keycloak.middleware()) + + app.use(graphqlPath, keycloak.protect()); + + return { + typeDefs: [KeycloakTypeDefs, apolloConfig.typeDefs], // 1. Add the Keycloak Type Defs + schemaDirectives: KeycloakSchemaDirectives, + resolvers: apolloConfig.resolvers, + playground: apolloConfig.playground, + path: graphqlPath, + context: ({ req }) => { + return { + ...apolloConfig.context, + kauth: new KeycloakContext({ req }) // 3. add the KeycloakContext to `kauth` + } + }, + subscriptions: { + onConnect: async (connectionParams, websocket, connectionContext) => { + const token = await keycloakSubscriptionHandler.onSubscriptionConnect(connectionParams) + if (!token) { + throw new Error("Cannot build keycloak token. Connection will be terminated") + } return { ...apolloConfig.context, - kauth: new KeycloakContext({ req }) // 3. add the KeycloakContext to `kauth` - } - }, - subscriptions: { - onConnect: async (connectionParams, websocket, connectionContext) => { - const token = await keycloakSubscriptionHandler.onSubscriptionConnect(connectionParams) - if (!token) { - throw new Error("Cannot build keycloak token. Connection will be terminated") - } - return { - ...apolloConfig.context, - kauth: new KeycloakSubscriptionContext(token) - } + kauth: new KeycloakSubscriptionContext(token) } - }, - } - } else { - console.log("Keycloak not configured. Auth will be disabled"); - return apolloConfig; + } + }, } } diff --git a/server/src/graphql.ts b/server/src/graphql.ts index ef7af2de..a24453be 100644 --- a/server/src/graphql.ts +++ b/server/src/graphql.ts @@ -11,7 +11,7 @@ import { Express } from "express"; import { buildKeycloakApolloConfig } from './auth'; import { createKeycloakRuntimeContext } from '@graphback/keycloak-authz'; import { authConfig } from './config/auth'; -import { OffixMongoDBDataProvider } from '@graphback/runtime-mongo'; +import { OffixMongoDBDataProvider, createOffixMongoCRUDRuntimeContext } from '@graphback/runtime-mongo'; import { AMQCRUDService } from './AMQCrudService' /** @@ -23,26 +23,31 @@ export const createApolloServer = async function (app: Express, config: Config) const typeDefs = loadSchemaFiles(join(__dirname, '/schema/')).join('\n'); const schema = buildSchema(typeDefs, { assumeValid: true }); + let context; - const context = createKeycloakRuntimeContext({ - models, - schema, - db, - pubSub, - authConfig, - dataProvider: OffixMongoDBDataProvider, - crudService: AMQCRUDService - }) + let apolloConfig; - let apolloConfig = { - typeDefs: typeDefs, - resolvers, - playground: true, - context: context + if (config.keycloakConfig) { + context = createKeycloakRuntimeContext({ + models, + schema, + db, + pubSub, + authConfig, + dataProvider: OffixMongoDBDataProvider, + crudService: AMQCRUDService + }) + apolloConfig = buildKeycloakApolloConfig(app, apolloConfig) + } else { + context = createOffixMongoCRUDRuntimeContext(models, schema, db, pubSub); + apolloConfig = { + typeDefs: typeDefs, + resolvers, + playground: true, + context: context + } } - apolloConfig = buildKeycloakApolloConfig(app, apolloConfig) - const apolloServer = new ApolloServer(apolloConfig) apolloServer.applyMiddleware({ app });