my apollo node js client not working for unknown reason

my apollo node js client not working for unknown reason


0

I have the following nodejs code :

    const { ApolloClient, InMemoryCache, createHttpLink } = require('@apollo/client');

// Define the HTTP endpoint
const httpEndpoint = 'https://localhost:5000/graphql/';

// Create an HTTP link
const httpLink = createHttpLink({
  uri: httpEndpoint,
});

// Create an Apollo Client with the HTTP link
const client = new ApolloClient({
  link: httpLink,
  cache: new InMemoryCache(),
});

// Define your subscription query
const YOUR_SUBSCRIPTION_QUERY = /* Your subscription query here */ `
  subscription OnAlertAdded {
    onAlertAdded(clientId: 1) {
      id
      name
    }
  }
`;


// Subscribe to the GraphQL subscription
client.subscribe({
  query: YOUR_SUBSCRIPTION_QUERY,
}).subscribe({
  next: (data) => {
    // Handle subscription data here
    console.log('Received data:', data);
  },
  error: (error) => {
    // Handle subscription errors here
    console.error('Subscription error:', error);
  },
});

// Handle any other logic or code here

// ...

it should connect to my graphql server which is working great with postman .
it gives the following errors :

Uncaught Error Invariant Violation: An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#%7B%22version%22%3A%223.8.6%22%2C%22message%22%3A73%2C%22args%22%3A%5B%5D%7D
at InvariantError (c:devGraphQLappolo client node jsnode_modulests-invariantlibinvariant.cjs:16:28)
at invariant (c:devGraphQLappolo client node jsnode_modulests-invariantlibinvariant.cjs:28:15)
at invariant (c:devGraphQLappolo client node [email protected]:63:21)
at checkDocument (c:devGraphQLappolo client node [email protected]:386:13)
at DocumentTransform.transformDocument (c:devGraphQLappolo client node [email protected]:501:9)
at QueryManager.transform (c:devGraphQLappolo client node [email protected]:1647:39)
at QueryManager.startGraphQLSubscription (c:devGraphQLappolo client node [email protected]:1834:22)
at ApolloClient.subscribe (c:devGraphQLappolo client node [email protected]:2381:34)
at (c:devGraphQLappolo client node jsapp.js:29:8)
at Module._compile (internal/modules/cjs/loader:1254:14)
at Module._extensions..js (internal/modules/cjs/loader:1308:10)
at Module.load (internal/modules/cjs/loader:1117:32)
at Module._load (internal/modules/cjs/loader:958:12)
at executeUserEntryPoint (internal/modules/run_main:81:12)
at (internal/main/run_main_module:23:47)
invariant.cjs:16
Process exited with code 1

any idea ?

1

  • Did you try the suggestion mentioned in the link provided as part of the error message?

    – Prerak Sola

    2 hours ago


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *