Skip to content
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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Add hasura GQL API #110

wants to merge 27 commits into from

Conversation

clostao
Copy link
Collaborator

@clostao clostao commented Nov 25, 2024

This PR implements Hasura GQL API:

  • Adds to the needed metadata for tracking the all the tables needed in Auto-Drive Frontend
  • Adds two roles user & app-admin. The first is the base permission and the second it's assigned to users with the role Admin.
  • Implements Hasura Claims into Custom JWT auth provider
  • Updates how the app is deployed in both production and local

Base automatically changed from feat/custom-jwt to main November 27, 2024 16:41
Copy link
Contributor

@marc-aurele-besner marc-aurele-besner left a 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(),
Copy link
Contributor

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

Copy link
Collaborator Author

@clostao clostao Nov 27, 2024

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?

Copy link
Contributor

@marc-aurele-besner marc-aurele-besner Nov 27, 2024

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,
  ]),

});

Copy link
Contributor

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.

Copy link
Collaborator Author

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!

Copy link
Collaborator Author

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

frontend/src/views/TrashFiles/index.tsx Show resolved Hide resolved
Copy link

netlify bot commented Nov 27, 2024

Deploy Preview for auto-drive-demo ready!

Name Link
🔨 Latest commit f6e4a44
🔍 Latest deploy log https://app.netlify.com/sites/auto-drive-demo/deploys/674870d1a5125200080677dd
😎 Deploy Preview https://deploy-preview-110--auto-drive-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@marc-aurele-besner marc-aurele-besner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWESOME :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants