-
-
Notifications
You must be signed in to change notification settings - Fork 241
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
"Error calling module function" with WebSocketLink (apollo-link-ws) #1285
Comments
Hi @darkbasic, |
Hi @tsonevn const subscriptionLink = new WebSocketLink({
uri: 'ws://localhost:3000/subscriptions',
options: {
reconnect: true,
},
webSocketImpl: SocketIO,
}); As you can see from the previous code snippet I'm using I cannot use plain |
Even if we don't use nor even import If they'll accept such a PR I could export ony the client in a different namespace like |
Not directly an angular issue but more of an apollo-link-ws issue. At any rate, this can be worked around using webpack's NormalModuleReplacementPlugin to swap in |
Thanks for sharing. One question: which websocket implementation did you end up using? SocketIO, nativescript or the default? |
HI recently I have the same probleme, Im trying to implement, realtime with apollo client using angular, and at configure the subscriptions, getting ERROR, there is solution to this problem. I,m lost :(, how alternative i try to use https://market.nativescript.org/plugins/nativescript-subscriptions-transport-ws, but i didnt had success. |
@Richard095 |
Hi, No, by time issues, i decided to change to SocketIO,It was a good option on Real-Time. |
Apparently yes, I had that problem a long time ago, however I think SocketIO is also going well. Only in this way was I able to continue with my project. |
@Richard095, @darkbasic, @NickIliev
plugins: [
// Define useful constants like TNS_WEBPACK
new webpack.NormalModuleReplacementPlugin(
/^ws$/,
'nativescript-websockets'
),
const WS = require('nativescript-websockets');
var WebSocket = require('nativescript-websockets');
import {NgModule, NO_ERRORS_SCHEMA} from '@angular/core';
import {NativeScriptHttpClientModule, NativeScriptModule} from "@nativescript/angular";
import {HTTP_INTERCEPTORS, HttpClient, HttpClientModule, HttpHeaders} from '@angular/common/http';
// @ts-ignore
import {Apollo, APOLLO_OPTIONS, ApolloModule} from 'apollo-angular';
import {Subject} from 'rxjs';
import {WebSocketLink} from "@apollo/client/link/ws";
import {RouterModule} from "@angular/router";
import {tap} from "rxjs/internal/operators";
import {getMainDefinition} from '@apollo/client/utilities';
const uri = 'http://192.168.1.21:3000/graphql';
const GRAPHQL_ENDPOINT = 'ws://192.168.1.21:3000/graphql';
const errorSubject = new Subject<any>();
const getErrorSubject = () => errorSubject.asObservable();
import {HttpLink} from 'apollo-angular/http';
import {ApolloLink, InMemoryCache, split} from '@apollo/client/core';
import {onError} from "@apollo/client/link/error";
import {RetryLink} from "@apollo/client/link/retry";
const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJkdWRpcHNoQGdtYWlsLmNvbSIsInZlcmlmaWVkIjp0cnVlLCJyb2xlcyI6W3siaWQiOjEsIm5hbWUiOiJERUZBVUxUX1JPTEVfQURNSU4iLCJkZXNjcmlwdGlvbiI6bnVsbCwicmVhZCI6WyIyMTQ3NDE4MDc1IiwiOCJdLCJ1cGRhdGUiOlsiMjE0NzQ4MzYwMSIsIjgiXSwiZGVzdHJveSI6WyIyMTQ3NDE4MDc1IiwiOCJdLCJyZWFkT3RoZXIiOlsiMjE0NzQ4MzYwMSIsIjgiXSwidXBkYXRlT3RoZXIiOlsiMjE0NzQxODA3NSIsIjgiXSwiZGVzdHJveU90aGVyIjpbIjIxNDc0MTgwNzUiLCI4Il0sImFwcGx5T25PdGhlcnMiOmZhbHNlLCJyb2xlTGV2ZWwiOjR9XSwibGVnYWxOYW1lIjoiRHVkaSBQYXJ0dXNoIiwiYWNjb3VudElkIjoxLCJhY2Nlc3NMZXZlbCI6NCwiYnVja2V0TmFtZSI6Ii90aW1lLXRhbGstYnVja2V0cy1jb21wYW55LXRlc3Rjb21wMSIsImVtcGxveWVlQ2hhdElkIjoiNjAzMjIxY2JkZWE5MjM4OGY5OTFiODI4IiwiY2hhdEFwcElkIjoiNjAzMjIxY2JkZWE5MjM4OGY5OTFiODI1IiwiY2hhdEJvdElkIjoiNjAzMjIxY2JkZWE5MjM4OGY5OTFiODI2IiwibXlDaGFubmVsSWQiOiI2MDMyMjFjY2RlYTkyMzg4Zjk5MWI4MmMiLCJpYXQiOjE2MTM5MDQ2NTIsImV4cCI6MTYxNDUwOTQ1Mn0.ISt0akAnQn6Adjd-nYXHcyapRT7zAwkcBIvz3s31gGs";
const HTTP_STATUS = {
NO_CONNECTION: 0,
INTERNAL_SERVER_ERROR: 500,
SERVICE_UNAVAILABLE: 503,
GATEWAY_TIMEOUT: 504,
BAD_GATEWAY: 502,
UNAUTHORIZED: 401,
FORBIDDEN: 403,
OK: 200,
CREATED: 201,
};
@NgModule({
imports: [
RouterModule,
NativeScriptHttpClientModule,
],
providers: [],
schemas: [
NO_ERRORS_SCHEMA
]
})
export class GraphQLModule {
constructor(
apollo: Apollo,
httpLink: HttpLink,
) {
const http = httpLink.create({
uri
});
const error = onError(({networkError, graphQLErrors}) => {
console.log('ERROR@@@@')
console.log(networkError)
console.log(graphQLErrors)
})
const wsClient = new WebSocketLink({
uri: 'ws://192.168.1.21:3000/graphql',
options: {
reconnect: true,
connectionParams: {
authorization: token,
},
},
connectionParams: async () => {
return {
authorization: token
};
},
webSocketImpl: WebSocket,
reconnectionAttempts: 99,
});
const retryLink = new RetryLink({
delay: {
initial: 1000,
max: Infinity,
},
attempts: {
max: 10,
retryIf: (error) => {
console.log(error)
return error.status === HTTP_STATUS.SERVICE_UNAVAILABLE ||
error.status === HTTP_STATUS.GATEWAY_TIMEOUT
}
},
});
const auth = new ApolloLink((operation, forward) => {
operation.setContext({
headers: new HttpHeaders().set('authorization', `${token}`),
});
return forward(operation);
});
const link = split(
({query}) => {
const {kind, operation}: any = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsClient,
auth.concat(http)
);
getErrorSubject().subscribe((data) => {
console.log(data)
}, (error) => console.log(error));
apollo.create({
link: ApolloLink.from([retryLink, link]),
cache: new InMemoryCache({
addTypename: false,
dataIdFromObject: (object: any) => object.id
}),
defaultOptions: {
watchQuery: {
errorPolicy: 'all'
}
}
});
}
}
` |
I don't understand |
https://github.com/darkbasic/nativescript-repro2/blob/master/app/app.module.ts
Full Error: https://paste.ubuntu.com/p/NrffmYWRDJ/
Removing the previous snippet of code fixes the error.
I think it could be related to #1284
The text was updated successfully, but these errors were encountered: