parse-community / parse-community/parse-server

GraphQL subscriptions not working

Open
#6,617 27 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:feature
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

Issue Description

Based on the Parse-Server documentation at https://docs.parseplatform.org/graphql/guide/#graphql, I am wondering if GraphQL subscriptions work out-of-the-box. So far in my testing, it doesn't work.

Steps to reproduce
  1. Create a class named "todo" with a new column "name"
  2. In parse-dashboard, go to GraphQL Console
  3. Write down this subscription query and hit the execute button:
subscription MySubscription {
  todos {
    edges {
      node {
        id
        objectId
        name
        updatedAt
        createdAt
      }
    }
  }
}
  1. In another console tab, create a mutation as follow:
mutation MyMutation {
  createTodo (input: {fields: {name: "hello world"}}) {
    todo {
      id
      objectId
      name
      createdAt
      updatedAt
    }
  }
}
  1. You can verify your newly created record with this query in a new console tab:
query MyTodos {
  todos {
    edges {
      node {
        id
        objectId
        name
        createdAt
        updatedAt
      }
    }
  }
}
Expected Results

Once the subscription query is executed and running, every mutation result (related to the class in the subscription query) should be displayed on the result side of the console.

Actual Outcome

An error is displayed in the result side of the GraphQL console:

{
  "error": "Could not connect to websocket endpoint ws://localhost:1337/graphql. Please check if the endpoint url is correct."
}

If I uncomment the following 2 lines in my docker-compose file (see at the end), I am not getting the above error, but just a console running and not displaying any result after a mutation:

  • PARSE_SERVER_START_LIVE_QUERY_SERVER=true
  • PARSE_SERVER_LIVE_QUERY={"classNames":["todo"]}
Environment Setup
  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 4.2.0
    • Operating System: windows 10
    • Hardware: docker-compose file with following images:
      • Postgres:12
      • parseplatform/parse-server:4.2.0
      • parseplatform/parse-dashboard:2.0.5
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): local docker-desktop for windows v.2.2.0.5
  • Database

    • Postgres version: 12
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): local docker-desktop for windows v.2.2.0.5
Logs/Trace

Docker logs of my parse-server container:

PS D:\git\parse-platform> docker logs 65a
allowClientClassCreation: true
appId: APPLICATION_ID
cacheMaxSize: 10000
cacheTTL: 5000
customPages: {}
databaseURI: postgres://postgres:example@postgres:5432/postgres
enableAnonymousUsers: true
expireInactiveSessions: true
graphQLPath: /graphql
host: 0.0.0.0
logsFolder: ./logs
masterKey: ***REDACTED***
masterKeyIps: []
maxUploadSize: 20mb
mountGraphQL: true
mountPath: /parse
mountPlayground: true
objectIdSize: 10
playgroundPath: /playground
port: 1337
protectedFields: {"_User":{"*":["email"]}}
revokeSessionOnPasswordReset: true
schemaCacheTTL: 5000
sessionLength: 31536000
allowCustomObjectId: false
collectionPrefix:
directAccess: false
enableExpressErrorHandler: false
enableSingleSchemaCache: false
preserveFileName: false
preventLoginWithUnverifiedEmail: false
scheduledPush: false
verifyUserEmails: false
jsonLogs: false
verbose: false
level: undefined
serverURL: http://localhost:1337/parse

[1] parse-server running on http://localhost:1337/parse
[1] GraphQL running on http://localhost:1337/graphql
[1] Playground running on http://localhost:1337/playground
PS D:\git\parse-platform>

My docker-compose.yml file:

version: "3"
services:
# PostgreSQL image
    postgres:
        image: postgres:12
        restart: always
        container_name: my-postgres
        volumes:
            - db_data:/var/lib/postgresql/data
        environment:
            - POSTGRES_PASSWORD=example

# parse-server application image
    parse-server:
        image: parseplatform/parse-server:4.2.0
        restart: always
        container_name: my-parse-server
        environment:
            - PARSE_SERVER_MASTER_KEY=MASTER_KEY
            - PARSE_SERVER_APPLICATION_ID=APPLICATION_ID
            - PARSE_SERVER_DATABASE_URI=postgres://postgres:example@postgres:5432/postgres
            - PARSE_SERVER_MOUNT_GRAPHQL=true
            - PARSE_SERVER_MOUNT_PLAYGROUND=true
            #- PARSE_SERVER_START_LIVE_QUERY_SERVER=true
            #- PARSE_SERVER_LIVE_QUERY={"classNames":["todo"]}
        depends_on:
            - postgres
        links:
            - postgres
        ports:
            - "1337:1337"
        volumes:
            - parseserverconfig:/parse-server/config
            - parseservercloud:/parse-server/cloud

# parse-dashboard application image
    parse-dashboard:
        image: parseplatform/parse-dashboard:2.0.5
        restart: always
        container_name: my-parse-dashboard
        ports:
            - "4040:4040"
        environment:
            - PARSE_DASHBOARD_ALLOW_INSECURE_HTTP=1
            - PARSE_DASHBOARD_CONFIG={"apps":[{"appId":"APPLICATION_ID","serverURL":"http://localhost:1337/parse","graphQLServerURL":"http://localhost:1337/graphql","masterKey":"MASTER_KEY","appName":"TestApp"}],"users":[{"user":"admin","pass":"admin"}]}
        depends_on:
            - parse-server

volumes:
# create named volume for postgreSQL /var/lib/postgresql/data so data persist when we shutdown/restart the container
    db_data:
  
# create following named volumes so we do not have many anonymous volumes that keeps growing when we run command: docker volume ls
    parseserverconfig:
    parseservercloud:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the GraphQL console subscription against the /graphql endpoint and compare it with the parse-server settings in docker-compose.yml, including the Live Query environment variables. Reproduce the websocket connection error, then verify that a running subscription receives the result of the createTodo mutation without errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker-compose, graphql, javascript, node.js, postgresql
Domain
api, backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.