Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "graphql-redis-subscriptions in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'graphql-redis-subscriptions' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

/* eslint-disable no-console*/
import { RedisPubSub } from 'graphql-redis-subscriptions';
import settings from 'settings';

const pubsub = new RedisPubSub({
  connection: {
    url: settings.REDIS_URI,
    host: 'redis',
    retry_strategy: options => {
      // reconnect after
      return Math.max(options.attempt * 100, 3000);
    }
  },
  connectionListener: (err) => {
    if (err) {
      console.error(err);
    }
    console.info('Pubsub: Succefuly connected to redis');
  }
});
import {RedisPubSub} from 'graphql-redis-subscriptions';
import {config} from '../settings/config'
export const CHANNEL = config.channel;

const options = {
    host: config.host,
    port: config.port,
    retry_strategy: options => {
        // reconnect after
        return Math.max(options.attempt * 100, 3000);
    }
};

export const redisPubSub = new RedisPubSub({
    connection: options
});



// redisPubSub.subscribe(config.channel, (payload) => {
//
//     try {
//         // console.log("redisPubSub:" + JSON.stringify(payload));
//     } catch (error) {
//         console.error(`Error trying to extract new message from payload`);
//         console.error(error.message);
//     }
// });
async function bootstrap() {
  // configure Redis connection options
  const options: Redis.RedisOptions = {
    host: REDIS_HOST,
    port: REDIS_PORT,
    retryStrategy: times => Math.max(times * 100, 3000),
  };

  // create Redis-based pub-sub
  const pubSub = new RedisPubSub({
    publisher: new Redis(options),
    subscriber: new Redis(options),
  });

  // Build the TypeGraphQL schema
  const schema = await buildSchema({
    resolvers: [RecipeResolver],
    validate: false,
    pubSub, // provide redis-based instance of PubSub
  });

  // Create GraphQL server
  const server = new ApolloServer({ schema });

  // Start the server
  const { url } = await server.listen(4000);
// @flow
/**
 * Our PubSub instance
 */
import { RedisPubSub } from 'graphql-redis-subscriptions';

const connection =
  process.env.NODE_ENV === 'production'
    ? {
        port: process.env.COMPOSE_REDIS_PORT,
        host: process.env.COMPOSE_REDIS_URL,
        password: process.env.COMPOSE_REDIS_PASSWORD,
      }
    : undefined; // Use the local instance of Redis in development by not passing any connection string

module.exports = new RedisPubSub({
  connection,
});
const getClient = () => {
  if (pubsub !== null) {
    return pubsub;
  }

  // Create the new PubSub client, we only need one per instance of Talk.
  pubsub = new RedisPubSub({
    publisher: createClient(),
    subscriber: createClient(),
  });

  return pubsub;
};
publish: () => null,
    };

    return pubsub;
  }

  if (PUBSUB_TYPE === 'GOOGLE') {
    const googleOptions = configGooglePubsub();

    const GooglePubSub = require('@axelspringer/graphql-google-pubsub').GooglePubSub;

    const googlePubsub = new GooglePubSub(googleOptions, undefined, commonMessageHandler);

    pubsub = googlePubsub;
  } else {
    const redisPubSub = new RedisPubSub({
      connectionListener: error => {
        if (error) {
          console.error(error);
        }
      },
      publisher: new Redis(redisOptions),
      subscriber: new Redis(redisOptions),
    });

    pubsub = redisPubSub;
  }

  return pubsub;
};
export const startServer = async () => {
  if (process.env.NODE_ENV === "test") {
    await redis.flushall();
  }

  const schema = genSchema() as any;
  applyMiddleware(schema, middleware);

  const pubsub = new RedisPubSub(
    process.env.NODE_ENV === "production"
      ? {
          connection: process.env.REDIS_URL as any
        }
      : {}
  );

  const server = new GraphQLServer({
    schema,
    context: ({ request, response }) => ({
      redis,
      url: request ? request.protocol + "://" + request.get("host") : "",
      session: request ? request.session : undefined,
      req: request,
      res: response,
      userLoader: userLoader(),
export async function startPubsub(): Promise {
  await startSubscriberAndPublisherRedisClients();

  pubsub = new RedisPubSub({
    subscriber,
    publisher,
  });
}
import Redis from 'ioredis';
import { RedisPubSub } from 'graphql-redis-subscriptions';
import { assoc, isEmpty, map } from 'ramda';
import conf, { isAppRealTime, logger } from '../config/conf';

const redisOptions = {
  port: conf.get('redis:port'),
  host: conf.get('redis:hostname'),
  password: conf.get('redis:password'),
  retryStrategy: times => Math.min(times * 50, 2000),
  maxRetriesPerRequest: 2
};

export const pubsub = isAppRealTime
  ? new RedisPubSub({
      publisher: new Redis(redisOptions),
      subscriber: new Redis(redisOptions)
    })
  : null;

const client = isAppRealTime && new Redis(redisOptions);
if (client) {
  client.on('error', error => {
    logger.error('[REDIS] An error occurred on redis > ', error);
  });
}
const isActive = () => client && client.status === 'ready';

export const getRedisVersion = () => {
  if (isActive()) return client.serverInfo.redis_version;
  return 'Disconnected';
export async function startPubsub(): Promise {
  await startSubscriberAndPublisherRedisClients();

  pubsub = new RedisPubSub({
    subscriber,
    publisher,
  });

  logger.info('📡 pubsub ready');
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now