Can i add my createGraphQLClient inside of a middleware ?
Unanswered
Siamese Crocodile posted this in #help-forum
Siamese CrocodileOP
I crate a GraphQLClient to send custom headers, also i set up QueryProvider and stasff (there i have set up that
A simple example is
My question is, can i
meta
export function createGraphQLClient(accessToken?: string) {
return new GraphQLClient(Config.gatewayGraphQLUrl, {
headers: {
...(accessToken ? { authorization: `Bearer ${accessToken}` } : {}),
},
credentials: 'include',
})
}
A simple example is
export const useCurrentUser = () => {
const {
data: user,
error,
isLoading,
} = useSuspenseQuery({
queryKey: [STATE_KEYS.CURRENT_USER],
queryFn: async ({ meta }) => {
const client = createGraphQLClient(meta?.accessToken as string);
const { currentUser } = await client.request(CurrentUserDocument);
return currentUser;
},
});
return {
user,
error,
isLoading,
};
};
My question is, can i
createGraphQLClient
inside of a middleware in next.js ?