apollographql / apollographql/apollo-client-integrations

async registerApolloClient ?

Open
#195 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
556
Forks
53
PR merge metrics
No merged PRs in 30d

Description

Be really handy if `registerApolloClient` was async...here's what im trying to do

``` typescript
import { HttpLink } from "@apollo/client";
import {
NextSSRInMemoryCache,
NextSSRApolloClient,
} from "@apollo/experimental-nextjs-app-support/ssr";
import { registerApolloClient } from "@apollo/experimental-nextjs-app-support/rsc";
import { runWithAmplifyServerContext } from "../amplify/amplifyServerUtils";
import { fetchAuthSession } from "aws-amplify/auth/server";
import { cookies } from "next/headers";

export const { getClient } = registerApolloClient(async () => {
const token = await runWithAmplifyServerContext({
nextServerContext: { cookies },
operation: async (contextSpec) => {
const session = await fetchAuthSession(contextSpec);
return session.tokens?.accessToken.toString();
},
});
const httpLink = new HttpLink({
uri: "http://localhost:4000/graphql",
headers: {
Authorization: `Bearer ${token}`,
},
});

return new NextSSRApolloClient({
cache: new NextSSRInMemoryCache(),
link: httpLink,
});
});
```

all my auth its handled by aws congnito / amplify. I can get my jwts using the amplify utils, and them pass them to the API. But, its an async process, so needs to live in an async fn...

Contributor guide

No contributing guide indexed for this repository

Research direction

The example centers on the registerApolloClient entry point and an async AWS Amplify token lookup; start by reading how that entry point currently creates and exposes the client. Define the expected behavior for async registration and getClient, then add or update tests covering the async factory and authenticated client creation.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql, nextjs, typescript
Domain
api, authentication, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.