Skip to content

Commit

Permalink
fix: hasura backend url (#623)
Browse files Browse the repository at this point in the history
Co-authored-by: Matéo Mévollon <[email protected]>
  • Loading branch information
gary-van-woerkens and matmut7 authored Jan 17, 2024
1 parent 935a9c5 commit 66ecc95
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 48 deletions.
4 changes: 3 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Node env
NODE_ENV=development

# Hasura backend's URL
# Hasura front-end's URL
NEXT_PUBLIC_HASURA_URL=http://localhost:8080/v1/graphql
# Hasura backend's URL
HASURA_URL=http://localhost:8080/v1/graphql

# NextAuth
NEXTAUTH_URL=http://localhost:3000/
Expand Down
1 change: 1 addition & 0 deletions .kontinuous/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ app:
name: app
vars:
NEXTAUTH_URL: https://{{ .Values.global.host }}
HASURA_URL: http://hasura/v1/graphql
probesPath: /healthz
imagePackage: app

Expand Down
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fileignoreconfig:
- filename: .env.sample
checksum: 0f628c927f046a71318bc0060e8a2c5e3d57b6de629da73ec57e909ad127cbdd
- filename: .kontinuous/env/dev/templates/sentry.sealed-secret.yaml
checksum: 6b3eb493305a8c3d24402c99d7a20b01b6650e7fedb2782648c539a70adc4088
- filename: .kontinuous/env/preprod/templates/sentry.sealed-secret.yaml
Expand Down Expand Up @@ -29,6 +31,8 @@ fileignoreconfig:
checksum: 5e2adf5acd6e8f769a465b573cd9149226526bbce8402abf3c0cc8d6f5520a3a
- filename: src/services/send-email.ts
checksum: 0562c88a33c18be479847c12d3c05dfc00b6edea18ffd61b97bc389536d41cb1
- filename: src/utils/env.ts
checksum: 27141a4c89dd648bfa03837b32f785029371cabad17ae0e977fa79110b091c67
scopeconfig:
- scope: node
version: "1.0"
2 changes: 1 addition & 1 deletion __tests__/api/onboarding/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ vi.mock("@/services/send-email", () => ({
}))
vi.mock("@/utils/env", () => ({
NEXTAUTH_URL: "http://fake.fr",
NEXT_PUBLIC_HASURA_URL: "http://fake.fr",
HASURA_URL: "http://fake",
}))

it("should create request and send email", async () => {
Expand Down
7 changes: 4 additions & 3 deletions src/pages/api/accounts/disable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { getService, updateService } from "@/queries/index"
import { disableGithubAccount } from "@/services/disablers/github"
import { disableMattermostAccount } from "@/services/disablers/mattermost"
import { disableOvhAccount } from "@/services/disablers/ovh"
import graphQLFetcher from "@/utils/graphql-fetcher"
// import graphQLFetcher from "@/utils/graphql-fetcher"
import graphQLServiceFetcher from "@/utils/graphql-service-fetcher"
import httpLogger from "@/utils/http-logger"
import { COOKIE_NAME, decode, getJwt } from "@/utils/jwt"
import logAction from "@/utils/log-action"
Expand Down Expand Up @@ -46,7 +47,7 @@ const Disable = async (req: NextApiRequest, res: NextApiResponse) => {
parameters: JSON.stringify(parsedBody),
})

const { services_by_pk: serviceAccount } = await graphQLFetcher({
const { services_by_pk: serviceAccount } = await graphQLServiceFetcher({
query: getService,
token,
parameters: { id: parsedBody.data.id },
Expand Down Expand Up @@ -86,7 +87,7 @@ const Disable = async (req: NextApiRequest, res: NextApiResponse) => {
}

if (statusOk(response.status)) {
await graphQLFetcher({
await graphQLServiceFetcher({
query: updateService,
token,
parameters: {
Expand Down
7 changes: 4 additions & 3 deletions src/pages/api/accounts/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { getService, updateService } from "@/queries/index"
import { enableGithubAccount } from "@/services/enablers/github"
import { enableMattermostAccount } from "@/services/enablers/mattermost"
import { enableOvhAccount } from "@/services/enablers/ovh"
import graphQLFetcher from "@/utils/graphql-fetcher"
// import graphQLFetcher from "@/utils/graphql-fetcher"
import graphQLServiceFetcher from "@/utils/graphql-service-fetcher"
import httpLogger from "@/utils/http-logger"
import { COOKIE_NAME, decode, getJwt } from "@/utils/jwt"
import logAction from "@/utils/log-action"
Expand Down Expand Up @@ -46,7 +47,7 @@ const Enable = async (req: NextApiRequest, res: NextApiResponse) => {
parameters: JSON.stringify(parsedBody),
})

const { services_by_pk: serviceAccount } = await graphQLFetcher({
const { services_by_pk: serviceAccount } = await graphQLServiceFetcher({
query: getService,
token,
parameters: { id: parsedBody.data.id },
Expand Down Expand Up @@ -96,7 +97,7 @@ const Enable = async (req: NextApiRequest, res: NextApiResponse) => {
}

if (statusOk(response.status)) {
await graphQLFetcher({
await graphQLServiceFetcher({
query: updateService,
token,
parameters: {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import GithubProvider from "next-auth/providers/github"
import CredentialsProvider from "next-auth/providers/credentials"

import { encode, decode, getJwt, COOKIE_NAME } from "@/utils/jwt"
import graphQLFetcher from "@/utils/graphql-fetcher"
// import graphQLFetcher from "@/utils/graphql-fetcher"
import graphQLServiceFetcher from "@/utils/graphql-service-fetcher"
import { getUserTeams as getUserTeamsQuery } from "@/queries/index"
import {
GITHUB_ID,
Expand All @@ -20,7 +21,7 @@ const getUserTeams = async (login: string) => {
organization: {
teams: { nodes: teams },
},
} = await graphQLFetcher({
} = await graphQLServiceFetcher({
query: getUserTeamsQuery,
token: getJwt(),
parameters: { login },
Expand Down
5 changes: 3 additions & 2 deletions src/pages/api/onboarding/confirm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { confirmOnboardingRequest } from "@/queries/index"
import { sendConfirmMail } from "@/services/send-email"
import { NEXTAUTH_URL, ONBOARDING_NOTIFICATION_EMAILS } from "@/utils/env"
import graphQLFetcher from "@/utils/graphql-fetcher"
// import graphQLFetcher from "@/utils/graphql-fetcher"
import graphQLServiceFetcher from "@/utils/graphql-service-fetcher"
import httpLogger from "@/utils/http-logger"
import { getJwt } from "@/utils/jwt"
import logAction from "@/utils/log-action"
Expand Down Expand Up @@ -32,7 +33,7 @@ const Confirm = async (req: NextApiRequest, res: NextApiResponse) => {

const {
update_onboarding_requests: { affected_rows, returning },
} = await graphQLFetcher({
} = await graphQLServiceFetcher({
query: confirmOnboardingRequest,
token,
parameters: {
Expand Down
21 changes: 12 additions & 9 deletions src/pages/api/onboarding/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
} from "@/queries/index"
import { sendRequestMail } from "@/services/send-email"
import { NEXTAUTH_URL } from "@/utils/env"
import graphQLFetcher from "@/utils/graphql-fetcher"
// import graphQLFetcher from "@/utils/graphql-fetcher"
import graphQLServiceFetcher from "@/utils/graphql-service-fetcher"
import httpLogger from "@/utils/http-logger"
import { getJwt } from "@/utils/jwt"
import logAction from "@/utils/log-action"
Expand All @@ -22,13 +23,15 @@ const Request = async (req: NextApiRequest, res: NextApiResponse) => {
const onboardingRequest: OnboardingData = req.body.input.data

// avoid duplicate onboarding requests
const { onboarding_requests: existingRequests } = await graphQLFetcher({
query: getOnboardingRequestContaining,
token,
parameters: {
contains: { email: onboardingRequest.email },
},
})
const { onboarding_requests: existingRequests } = await graphQLServiceFetcher(
{
query: getOnboardingRequestContaining,
token,
parameters: {
contains: { email: onboardingRequest.email },
},
}
)
if (existingRequests.length > 0) {
req.log.info("a request with the same email already exists")
res.status(200).json({
Expand All @@ -46,7 +49,7 @@ const Request = async (req: NextApiRequest, res: NextApiResponse) => {

const {
insert_onboarding_requests_one: { id },
} = await graphQLFetcher({
} = await graphQLServiceFetcher({
query: createOnboardingRequest,
token,
parameters: {
Expand Down
7 changes: 4 additions & 3 deletions src/pages/api/onboarding/review.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getOnboardingRequest, updateOnboardingRequest } from "@/queries/index"
import onboard from "@/services/onboard"
import { sendReviewMail } from "@/services/send-email"
import graphQLFetcher from "@/utils/graphql-fetcher"
// import graphQLFetcher from "@/utils/graphql-fetcher"
import graphQLServiceFetcher from "@/utils/graphql-service-fetcher"
import httpLogger from "@/utils/http-logger"
import { COOKIE_NAME, decode, getJwt } from "@/utils/jwt"
import logAction from "@/utils/log-action"
Expand All @@ -27,7 +28,7 @@ const Review = async (req: NextApiRequest, res: NextApiResponse) => {

const { data, id } = req.body.input

const { onboarding_requests: requests } = await graphQLFetcher({
const { onboarding_requests: requests } = await graphQLServiceFetcher({
query: getOnboardingRequest,
token,
parameters: {
Expand All @@ -50,7 +51,7 @@ const Review = async (req: NextApiRequest, res: NextApiResponse) => {
return
}

graphQLFetcher({
graphQLServiceFetcher({
query: updateOnboardingRequest,
token,
parameters: {
Expand Down
11 changes: 8 additions & 3 deletions src/services/fetchers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import pMap from "p-map"
import { setTimeout } from "timers/promises"

import { getJwt } from "@/utils/jwt"
import graphQLFetcher from "@/utils/graphql-fetcher"
// import graphQLFetcher from "@/utils/graphql-fetcher"
import graphQLServiceFetcher from "@/utils/graphql-service-fetcher"
import { getRemoteGithubTeams, getRemoteGithubUsers } from "@/queries/index"
import logger from "@/utils/logger"

Expand All @@ -17,7 +18,11 @@ const fetchGithubPage = async (token: string, cursor?: string) => {
edges: edgesPage,
},
},
} = await graphQLFetcher({ query: getRemoteGithubUsers, token, parameters })
} = await graphQLServiceFetcher({
query: getRemoteGithubUsers,
token,
parameters,
})

// construct users with nodes union edges
const usersPage = nodesPage.map(
Expand Down Expand Up @@ -57,7 +62,7 @@ export const fetchGithubUsers = async (
organization: {
teams: { nodes: teamsList },
},
} = await graphQLFetcher({
} = await graphQLServiceFetcher({
query: getRemoteGithubTeams,
token,
parameters: {
Expand Down
7 changes: 4 additions & 3 deletions src/services/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
MATTERMOST_API_TOKEN,
OVH_SERVICE_NAME,
} from "@/utils/env"
import graphQLFetcher from "@/utils/graphql-fetcher"
// import graphQLFetcher from "@/utils/graphql-fetcher"
import graphQLServiceFetcher from "@/utils/graphql-service-fetcher"
import { getJwt } from "@/utils/jwt"
import logger from "@/utils/logger"
import ovh from "@/utils/ovh"
Expand Down Expand Up @@ -216,7 +217,7 @@ const createAccountsOnSuccess = async (
// First, create an associated user entry
const {
insert_users_one: { id: userId },
} = await graphQLFetcher({
} = await graphQLServiceFetcher({
query: insertUser,
token,
parameters: {
Expand All @@ -231,7 +232,7 @@ const createAccountsOnSuccess = async (

for (const [serviceName, response] of Object.entries(responses)) {
if (shouldInsertAccount(serviceName, response)) {
await graphQLFetcher({
await graphQLServiceFetcher({
query: insertService,
token,
parameters: {
Expand Down
30 changes: 16 additions & 14 deletions src/services/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { fetchNextcloudUsers } from "@/services/fetchers/nextcloud"
import { fetchOvhUsers } from "@/services/fetchers/ovh"
import { fetchSentryUsers } from "@/services/fetchers/sentry"
import { fetchZammadUsers } from "@/services/fetchers/zammad"
import graphQLFetcher from "@/utils/graphql-fetcher"
// import graphQLFetcher from "@/utils/graphql-fetcher"
import graphQLServiceFetcher from "@/utils/graphql-service-fetcher"
import { getJwt } from "@/utils/jwt"
import logger from "@/utils/logger"
import {
Expand Down Expand Up @@ -48,7 +49,7 @@ export const getServiceFromData = async (
token: string
) => {
const idField = servicesIdFields[serviceName]
const { services: servicesMatchingId } = await graphQLFetcher({
const { services: servicesMatchingId } = await graphQLServiceFetcher({
query: getServicesMatchingId,
token,
parameters: {
Expand Down Expand Up @@ -83,12 +84,12 @@ export const upsertService = async (
// First, create an associated user entry
const {
insert_users_one: { id: userId },
} = await graphQLFetcher({ query: insertUser, token })
} = await graphQLServiceFetcher({ query: insertUser, token })

// Then, create the service entry
const {
insert_services_one: { id: serviceId },
} = await graphQLFetcher({
} = await graphQLServiceFetcher({
query: insertService,
token,
parameters: {
Expand All @@ -100,14 +101,15 @@ export const upsertService = async (
// At this moment, we need to check if the user comes from a Secretariat onboarding or not
// if so, link it to its onboarding request
if (serviceName === "github") {
const { onboarding_requests: onboardingRequests } = await graphQLFetcher({
query: getReviewedOnboardingRequestContaining,
parameters: { _contains: { githubLogin: serviceData.login } },
token,
})
const { onboarding_requests: onboardingRequests } =
await graphQLServiceFetcher({
query: getReviewedOnboardingRequestContaining,
parameters: { _contains: { githubLogin: serviceData.login } },
token,
})

if (onboardingRequests.length === 1) {
await graphQLFetcher({
await graphQLServiceFetcher({
query: linkGithubOnboarding,
token,
parameters: {
Expand All @@ -125,7 +127,7 @@ export const upsertService = async (
// We have to update a service entry
const {
update_services_by_pk: { id: serviceId },
} = await graphQLFetcher({
} = await graphQLServiceFetcher({
query: updateService,
token,
parameters: {
Expand Down Expand Up @@ -183,7 +185,7 @@ const clearDeletedServices = async (
for (const serviceName in existingServicesIds) {
const {
delete_services: { returning: affectedUsersForService },
} = await graphQLFetcher({
} = await graphQLServiceFetcher({
query: deleteServicesNotIn,
token,
parameters: {
Expand All @@ -208,7 +210,7 @@ const deleteOrphanUsers = async (
) => {
const {
delete_users: { affected_rows: deletedUsers },
} = await graphQLFetcher({
} = await graphQLServiceFetcher({
query: deleteUsers,
token,
parameters: {
Expand Down Expand Up @@ -238,7 +240,7 @@ export const deleteService = async (
} else if (servicesMatchingId.length === 1) {
const {
delete_services: { returning: affectedUsersForService },
} = await graphQLFetcher({
} = await graphQLServiceFetcher({
query: deleteServiceQuery,
token,
parameters: {
Expand Down
1 change: 1 addition & 0 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const ONBOARDING_NOTIFICATION_EMAILS = process.env

export const NEXT_PUBLIC_HASURA_URL = process.env
.NEXT_PUBLIC_HASURA_URL as string
export const HASURA_URL = process.env.HASURA_URL as string

// Mattermost review alert
export const MATTERMOST_ALERT_CHANNEL_ID = process.env
Expand Down
6 changes: 4 additions & 2 deletions src/utils/graphql-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { GraphQLClient } from "graphql-request"
import { NEXT_PUBLIC_HASURA_URL } from "./env"

interface GraphQLFetcherParams {
export interface GraphQLFetcherParams {
query: string
includeCookie?: boolean
token?: string
parameters?: Record<string, unknown>
url?: string
}

// Used for all GraphQL interactions with Hasura
Expand All @@ -15,6 +16,7 @@ const graphQLFetcher = ({
includeCookie,
token,
parameters,
url,
}: GraphQLFetcherParams) => {
let options = {}
if (includeCookie) {
Expand All @@ -29,7 +31,7 @@ const graphQLFetcher = ({
}
}

const client = new GraphQLClient(NEXT_PUBLIC_HASURA_URL, options)
const client = new GraphQLClient(url || NEXT_PUBLIC_HASURA_URL, options)

return client.request(query, parameters)
}
Expand Down
Loading

0 comments on commit 66ecc95

Please sign in to comment.