Skip to content
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

Adding different error links for different endpoints #430

Open
f1devrouaa opened this issue Jan 16, 2023 · 2 comments
Open

Adding different error links for different endpoints #430

f1devrouaa opened this issue Jan 16, 2023 · 2 comments

Comments

@f1devrouaa
Copy link

f1devrouaa commented Jan 16, 2023

We are trying to pass an apollo link object instead of string to the two endpoints but we are getting error that the apollo link is not assignable to type string.

  return new ApolloClient({
    ssrMode: typeof window === 'undefined',
    link: ApolloLink.from([
      new MultiAPILink({
          endpoints: {
              laravel: {
                  link: ApolloLink.from([
                      authLink,
                      errorLink,
                      httpLink
                  ])
              },
              wordpress: {
                  link: ApolloLink.from([
                      authLinkwp,
                      errorLinkwp,
                      httpLinkwp
                  ])
              }
          } 
      })
  ]),
  cache: new InMemoryCache(),
  });
}

How can this be fixed and how can we add different cache for each

@f1devrouaa
Copy link
Author

  return new ApolloClient({
    ssrMode: typeof window === 'undefined',
    link: ApolloLink.from([
      new MultiAPILink({
        getContext: (endpoint) => {
            if (endpoint === 'laravel') {
                return {
                    headers: {
                        authorization: `Bearer ${Cookies.get(AUTH_TOKEN_KEY)}`,
                    },
                    errorLink: errorLink,
                    authLink : authLink,
                    cache : new InMemoryCache(),
                }
              } else if (endpoint === 'wordpress') {
                return {
                  headers: {

                  },
                  errorLink: errorLinkwp,
                  authLink: authLinkwp,
                  afterware,
                  cache : new InMemoryCache(),
              }
          }
          return {}
      },
      endpoints: {
          laravel: httpLink,
          wordpress: httpLinkwp,
          ...

      }, //expression expected
      createHttpLink: () => createHttpLink(),
  }),

This is the alternative method we tried to get rid of error but we get now an error expression expected

@ibatra
Copy link

ibatra commented Oct 15, 2023

So I ran into same issue as you and mananegd to fix it with a bit of struggle, basically instead of setting context or instead of using createHttpLink I did something like (url, endpoint) => if (endpoint == "main") { return ApolloLink.from([authLink, httpLink])}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants