Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { appTypeDefs, appResolvers } = require('./schema')
const agSender = require("unifiedpush-node-sender")
process.on('unhandledRejection', error => {
console.error('unhandledRejection', error.message);
process.exit(1);
});
let keycloakService = null
let pushClient = null
// if a keycloak config is present we create
// a keycloak service which will be passed into
// ApolloVoyagerServer
if (config.keycloakConfig) {
keycloakService = new KeycloakSecurityService(config.keycloakConfig)
}
if (config.pushConfig) {
let pushService = agSender(config.pushConfig)
pushClient = pushService.then((client) => {
return client;
})
}
async function start() {
const app = express()
app.use(cors())
metrics.applyMetricsMiddlewares(app, {
path: '/metrics'
// Resolver functions. This is our business logic
const resolvers = {
Query: {
hello: (obj, args, context, info) => {
// log some of the auth related info added to the context
console.log(context.auth.isAuthenticated())
console.log(context.auth.accessToken.content.name)
const name = context.auth.accessToken.content.name || 'world'
return `Hello ${name} from ${context.serverName}`
}
}
}
// Initialize the keycloak service
const keycloakService = new KeycloakSecurityService(keycloakConfig)
// The context is a function or object that can add some extra data
// That will be available via the `context` argument the resolver functions
const context = ({ req }) => {
return {
serverName: 'Voyager Server'
}
}
// Initialize the voyager server with our schema and context
const apolloConfig = {
typeDefs: [typeDefs, keycloakService.getTypeDefs()],
resolvers,
context
}