apollographql / apollographql/apollo-client-integrations
Next14 initialize ApolloWrapper with Cookie
- Dominant language
- TypeScript
- Stars
- 556
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I needed to initialize ApolloWrapper with an Authorization header (Cookie), so I made a few changes to make it work. Do you have any comments about this decision? If I open a PR, I'll make some breaking changes in your API in order to support Cookies.
```js
"use client";
import {
ApolloNextAppProvider,
NextSSRInMemoryCache,
NextSSRApolloClient,
SSRMultipartLink,
} from "@apollo/experimental-nextjs-app-support/ssr";
import { ApolloLink, HttpLink } from "@apollo/client";
function makeClient(cookie: string) {
const httpLink = new HttpLink({
fetchOptions: { cache: "no-store" },
headers: { authorization: cookie }, // <= our token
uri: process.env.NEXT_PUBLIC_URL,
credentials: "include";
});
return new NextSSRApolloClient({
link:
typeof window === "undefined"
? ApolloLink.from([
new SSRMultipartLink({
stripDefer: true,
}),
httpLink,
])
: httpLink,
cache: new NextSSRInMemoryCache(),
});
}
export function ApolloWrapper({ children, cookie }: React.PropsWithChildren<{ cookie: string }>) {
const initializeClientWithCookie = () => makeClient(cookie); // initialize ApolloWrapper with Cookie
return (
{children}
);
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the ApolloWrapper and makeClient example in the issue, then inspect the Next.js App Router integration entry points for how ApolloNextAppProvider creates clients. No repository files or tests are named. Done would require an agreed cookie-based authorization API and documented behavior for the proposed breaking changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, next.js, typescript
- Domain
- api, authentication
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100