You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
question about the decisions made in the repository
Issue description
Current behavior:
Configuring Apollo to connect to Hasura and trying to setup a GraphQL subscription does not work. No errors or anything else, just does not work.
Expected behavior:
Results of the subscription should be received correctly
Steps to reproduce:
Clone ngx-admin, configure Apollo and try to setup a subscription.
In details:
I have created a simple Angular project (call it Base Demo) and configured Apollo and the subscriptions are indeed working. I am using the same node version and the same libraries and library versions of ngx-admin.
If I use the same exact code to configure GraphQL in ngx-admin (I just cloned the project to be sure I haven't added any code of mine), it just does not work. Nothing is displayed as result of a subscription, but I also do not get any error. The ws connection in the browser console looks exactly the same as in the Base Demo project.
Related code:
// GraphQLModule.tsimport{NgModule}from'@angular/core';import{ApolloModule,APOLLO_OPTIONS}from'apollo-angular';import{ApolloClientOptions,InMemoryCache,split}from'@apollo/client/core';import{HttpLink}from'apollo-angular/http';import{HttpClient,HttpHeaders}from'@angular/common/http';import{GraphQLWsLink}from'@apollo/client/link/subscriptions';import{createClient}from'graphql-ws';import{getMainDefinition}from'@apollo/client/utilities';consturi='http://localhost:8080/v1/graphql';constwsUri='ws://localhost:8080/v1/graphql';exportfunctioncreateApollo(httpLink: HttpLink,http: HttpClient): ApolloClientOptions<any>{vartoken="<token>";constauthLink=httpLink.create({
uri,headers: !token ? newHttpHeaders() :
newHttpHeaders().set('Authorization',`Bearer ${token}`).set('x-hasura-role',"manager"),});constwsLink=newGraphQLWsLink(createClient({url: wsUri,connectionParams: {headers: !token ? {} :
{Authorization: `Bearer ${token}`,'x-hasura-role': "user",}}}));// The split function takes three parameters://// * A function that's called for each operation to execute// * The Link to use for an operation if the function returns a "truthy" value// * The Link to use for an operation if the function returns a "falsy" valueconstsplitLink=split(({ query })=>{constdefinition=getMainDefinition(query);return(definition.kind==='OperationDefinition'&&definition.operation==='subscription');},wsLink,authLink,);return{cache: newInMemoryCache({addTypename: false,}),link: splitLink,};}
@NgModule({exports: [ApolloModule],providers: [{provide: APOLLO_OPTIONS,useFactory: createApollo,deps: [HttpLink,HttpClient],},],})exportclassGraphQLModule{}
After wasting more than 8 hrs between last week and today trying to find what was the problem, looking line by line every file and configuration and doing some tests, I have finally found the solution.
The culprit is pace-js, that is inlcuded in ngx-admin but in the end I have never used. pace-js tracking the websockets causes some problems, so the solution was to disable that tracking:
Issue type
Issue description
Current behavior:
Configuring Apollo to connect to Hasura and trying to setup a GraphQL subscription does not work. No errors or anything else, just does not work.
Expected behavior:
Results of the subscription should be received correctly
Steps to reproduce:
Clone ngx-admin, configure Apollo and try to setup a subscription.
In details:
I have created a simple Angular project (call it Base Demo) and configured Apollo and the subscriptions are indeed working. I am using the same node version and the same libraries and library versions of ngx-admin.
If I use the same exact code to configure GraphQL in ngx-admin (I just cloned the project to be sure I haven't added any code of mine), it just does not work. Nothing is displayed as result of a subscription, but I also do not get any error. The ws connection in the browser console looks exactly the same as in the Base Demo project.
Related code:
Other information:
npm, node, OS, Browser
Angular, Nebular
The text was updated successfully, but these errors were encountered: