davidyaha/graphql-redis-subscriptions

It is ignoring redis database index

JaLe29 opened this issue · 4 comments

I am using two environments- prod and dev.

Both of them are using same redis server BUT with different redis database index.

Problem is, that when is event fired on dev, its subscribed on prod and dev.

But it should be only dev.

My init code is:

				const options = {
					host: ENV_REDIS_ADR,
					port: 6379,
					db: ENV_REDIS_DB,
					password: ENV_REDIS_PSW,
					keyPrefix: ENV_ENV,
				};

				return new RedisPubSub({
					publisher: new Redis(options),
					subscriber: new Redis(options),
				});

I too have the same issue.

here is my mutation

createMessage: combineResolvers(
      isAuthenticated,
      async (parent, { text }, { models, me }) => {
        const message = await models.Message.create({
          text,
          userId: me.id,
        });

        pubsub.publish(EVENTS.MESSAGE.CREATED, {
          messageCreated: {
            message,
          },
        });

        return message;
      },
    ),

The mutation works fine everytime.
The subscription works fine with PubSub from 'apollo-server',

But when i use RedisPubSub i get the following message:

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Message.id.",
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ],
      "path": [
        "messageCreated",
        "message",
        "id"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR"
      }
    }
  ],
  "data": null
}

The variable 'message' contains id, I can see it when I console.log

Is there something I am missing? I only breaks when in use RedisPubSub. It is really wierd.

Hey @JaLe29!
This is probably an issue with how the Redis clients create the connection. This library uses the Redis client instances you provided to it as-is. Meaning that you should check if the Redis client support database index in the connection string.
Try to create a simple node script that just creates a connection to Redis using either io-redis or node-redis and see if the connection is as you expect it.

@mylifenp This is an unrelated issue. please open a new thread so that it will be indexed for future reference. Also if I remember correctly, this question or similar issues was raised before (a hint - try adding an id to either the messageCreated object)

Я использую две среды: prod и dev.

Оба они используют один и тот же сервер Redis, НО с другим индексом базы данных Redis.

Проблема в том, что когда событие запускается на dev, оно подписывается на prod и dev.

Но это должен быть только dev.

Мой код инициализации:

				const options = {
					host: ENV_REDIS_ADR,
					port: 6379,
					db: ENV_REDIS_DB,
					password: ENV_REDIS_PSW,
					keyPrefix: ENV_ENV,
				};

				return new RedisPubSub({
					publisher: new Redis(options),
					subscriber: new Redis(options),
				});

#300

I don't think this is related to #300. Care to explain?
@JaLe29 @mylifenp Does the issue persists?