77 * Eventually we will have one ApolloProvider, not multiple.
88 */
99
10+ import { useContext } from 'react'
11+
1012import type {
1113 ApolloCache ,
1214 ApolloClientOptions ,
15+ ApolloLink ,
1316 HttpOptions ,
1417 InMemoryCacheConfig ,
1518 setLogVerbosity ,
16- ApolloLink ,
1719} from '@apollo/client'
1820import {
1921 setLogVerbosity as apolloSetLogVerbosity ,
@@ -24,14 +26,14 @@ import {
2426 ApolloNextAppProvider ,
2527 NextSSRApolloClient ,
2628 NextSSRInMemoryCache ,
27- useSuspenseQuery ,
2829 useBackgroundQuery ,
29- useReadQuery ,
3030 useQuery ,
31+ useReadQuery ,
32+ useSuspenseQuery ,
3133} from '@apollo/experimental-nextjs-app-support/ssr'
3234
3335import type { UseAuth } from '@redwoodjs/auth'
34- import { useNoAuth } from '@redwoodjs/auth'
36+ import { ServerAuthContext , useNoAuth } from '@redwoodjs/auth'
3537import './typeOverride'
3638
3739import {
@@ -46,13 +48,7 @@ import type {
4648 RedwoodApolloLinkName ,
4749 RedwoodApolloLinks ,
4850} from './links'
49- import {
50- createAuthApolloLink ,
51- createFinalLink ,
52- createHttpLink ,
53- createTokenLink ,
54- createUpdateDataLink ,
55- } from './links'
51+ import { createFinalLink , createHttpLink , createUpdateDataLink } from './links'
5652
5753export type ApolloClientCacheConfig = InMemoryCacheConfig
5854
@@ -120,12 +116,13 @@ const ApolloProviderWithFetchConfig: React.FunctionComponent<{
120116 logLevel : ReturnType < typeof setLogVerbosity >
121117 children : React . ReactNode
122118} > = ( { config, children, useAuth = useNoAuth , logLevel } ) => {
119+ console . log ( `👉 \n ~ file: suspense.tsx:119 ~ useAuth:` , useAuth )
123120 // Should they run into it, this helps users with the "Cannot render cell; GraphQL success but data is null" error.
124121 // See https://github.com/redwoodjs/redwood/issues/2473.
125122 apolloSetLogVerbosity ( logLevel )
126123
127124 // See https://www.apollographql.com/docs/react/api/link/introduction.
128- const { getToken, type : authProviderType } = useAuth ( )
125+ // const { getToken, type: authProviderType } = useAuth()
129126
130127 // `updateDataApolloLink` keeps track of the most recent req/res data so they can be passed to
131128 // any errors passed up to an error boundary.
@@ -134,7 +131,13 @@ const ApolloProviderWithFetchConfig: React.FunctionComponent<{
134131 mostRecentResponse : undefined ,
135132 } as any
136133
137- const { headers, uri } = useFetchConfig ( )
134+ const { uri } = useFetchConfig ( )
135+
136+ const serverAuthState = useContext ( ServerAuthContext )
137+ console . log (
138+ `👉 \n ~ file: suspense.tsx:142 ~ serverAuthState:` ,
139+ serverAuthState
140+ )
138141
139142 const getGraphqlUrl = ( ) => {
140143 // @NOTE : This comes from packages/vite/src/streaming/registerGlobals.ts
@@ -152,14 +155,21 @@ const ApolloProviderWithFetchConfig: React.FunctionComponent<{
152155
153156 // We use this object, because that's the shape of what we pass to the config.link factory
154157 const redwoodApolloLinks : RedwoodApolloLinks = [
155- { name : 'withToken' , link : createTokenLink ( getToken ) } ,
156- {
157- name : 'authMiddleware' ,
158- link : createAuthApolloLink ( authProviderType , headers ) ,
159- } ,
158+ // { name: 'withToken', link: createTokenLink(getToken) },
159+ // {
160+ // name: 'authMiddleware',
161+ // link: createAuthApolloLink(authProviderType, headers),
162+ // },
160163 // @TODO : do we need this in prod? I think it's only for dev errors
161164 { name : 'updateDataApolloLink' , link : createUpdateDataLink ( data ) } ,
162- { name : 'httpLink' , link : createHttpLink ( getGraphqlUrl ( ) , httpLinkConfig ) } ,
165+ {
166+ name : 'httpLink' ,
167+ link : createHttpLink (
168+ getGraphqlUrl ( ) ,
169+ httpLinkConfig ,
170+ serverAuthState . cookieHeader
171+ ) ,
172+ } ,
163173 ]
164174
165175 const extendErrorAndRethrow = ( error : any , _errorInfo : React . ErrorInfo ) => {
0 commit comments