datadvance / DjangoChannelsGraphqlWs

Django Channels based WebSocket GraphQL server with Graphene-like subscriptions
MIT License
281 stars 85 forks source link

Add support for batch GraphQL operations #18

Open Thibaut-Fatus opened 5 years ago

Thibaut-Fatus commented 5 years ago

Hi,

When trying to call multiple subscriptions from the same component, only the first subscription is registered by the server:

subscription mySubscription {
  firstSubscription {
    foo
  }
  secondSubscription {
    bar
  }
}

triggers the correct frame on the WS:

{
  id: "1",
  payload: {
    operationName: "mySubscription"
    query: "subscription mySubscription {
      firstSubscription {
        foo
        __typename
      }
      secondSubscription {
        bar
        __typename
      }
    },
    variables: {}
    type: "start"
  },
}

however only the firstSubscription subscribe method seems to be executed (when logging we only see this one being called)

Switching order like this

subscription mySubscription {
  secondSubscription {
    bar
  }
  firstSubscription {
    foo
  }
}

leads to only the secondSubscription subscribe method to be called.

frontend: apollo-client: 1.4.0 (needed for compatibility issues) subscriptions-transport-ws: 0.8.3

backend: django==2.2.2 channels==2.2.0 django-channels-graphql-ws==0.2.0 graphene==2.1.5 graphene-django==2.2.0 graphql-core==2.1 graphql-relay==0.4.5

Thibaut-Fatus commented 5 years ago

I tried with a node server, and it returns: Subscription "mySubscription" must select only one top level field.

It might not be supported by graphql spec, and then we might need an error message instead.

hozblok commented 5 years ago

Hi @Thibaut-Fatus ,

Thank you for your research. Yes, we do not support such batch operations now. We will think about how to work with this in future versions.