Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is ignoring redis database index #308

Open
JaLe29 opened this issue Jan 8, 2021 · 4 comments
Open

It is ignoring redis database index #308

JaLe29 opened this issue Jan 8, 2021 · 4 comments

Comments

@JaLe29
Copy link

JaLe29 commented Jan 8, 2021

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),
				});
@mylifenp
Copy link

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.

@davidyaha
Copy link
Owner

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)

@kiyasov
Copy link

kiyasov commented Apr 23, 2021

Я использую две среды: 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

@davidyaha
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants