-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hasura GQL API #110
base: main
Are you sure you want to change the base?
Add hasura GQL API #110
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome work 🙌
Just one comment to add the auth directly in ApolloClient
|
||
export const apiv2Client = new ApolloClient({ | ||
uri: process.env.NEXT_PUBLIC_GQL_URL, | ||
cache: new InMemoryCache(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, to pass in the session token on each query, this could be added here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The session token refreshes quite frequently (most times the user interacts with nextjs server). Do you mean that there's a dynamic way to set the token in the apollo client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe something like that should work
import { ApolloClient, createHttpLink, from, InMemoryCache } from '@apollo/client';
import { setContext } from '@apollo/client/link/context'
import { getSession } from 'next-auth/react'
const httpLink = createHttpLink({
uri: process.env.NEXT_PUBLIC_GQL_URL,
})
const authLink = setContext(async (_, { headers }) => {
const session = await getSession()
return {
headers: {
...headers,
...(session?.accessToken && { authorization: `Bearer ${session.accessToken}` }),
},
}
})
export const apiv2Client = new ApolloClient({
cache: new InMemoryCache(),
link: from([
authLink,
httpLink,
]),
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also look into implementing https://www.npmjs.com/package/@apollo/experimental-nextjs-app-support so the ApolloClient to work on both SSR and RSR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It worked thanks for the comment & review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: It worked fine on yarn dev
mode but compiling the nextjs app it failed due to this error.
TLDR; Static generation of routes is checked through the compiler discarding the ones depending on dynamic values (such as cookies()
or headers()
). The issue is that the compiler is unable to detect if a route is dynamic or static when the call to these dynamic values is at another AsyncContext than the page. In this case fails in build-time.
For solving this, you have to explicitly determine that the route is dynamic
✅ Deploy Preview for auto-drive-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWESOME :)
This PR implements Hasura GQL API:
user
&app-admin
. The first is the base permission and the second it's assigned to users with the roleAdmin
.