the-guild-org / the-guild-org/apollo-angular

Feedback for “Subscriptions”

Open
#2,331 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.5k
Forks
309
Avg merge
1h 45m
Merged PRs (30d)
3

Description

Authentication on the subscription topic in the documentation is unclear. I failed to authenticate using the following link over my named client.

const token = 'my_token';

const basic = setContext(() => ({
  headers: {
    Accept: 'charset=utf-8'
  }
}));

const authLink = setContext((operation, context) =>  ({
  headers: {
    Authorization: `Bearer ${token}`,
  },
}));

const splitLink = split(
  ({ query }) => {
    const definition = getMainDefinition(query);
    return (
      definition.kind === Kind.OPERATION_DEFINITION &&
      definition.operation === OperationTypeNode.SUBSCRIPTION
    );
  },
  new WebSocketLink({
    uri: `ws://localhost:5079/graphql`,
    options: {
      reconnect: true,
      connectionParams: () => ({
        authToken: `Bearer ${token}`, // also tried using Authorization:  `Bearer ${token}`,
      }),
    },
  }),
  authLink.concat(inject(HttpLink).create({
    uri: `http://localhost:5079/graphql`,
  })),
);

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes),
    provideHttpClient(withFetch()),
    provideNamedApollo(() => ({
      myNamedClient: {
        link: ApolloLink.from([
          basic,
          splitLink
        ]),
        cache: new InMemoryCache(),
      }
    }))
  ]
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue points to the Subscriptions authentication documentation and provides an Angular/TypeScript Apollo setup using a named client, an HTTP auth link, and WebSocket connection parameters. Locate that documentation and its subscription authentication examples first; reproduce the named-client setup and verify that the documented authentication configuration works for subscriptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, graphql, typescript
Domain
api, authentication, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.