From 055dd52a7d43b82e9592240f790df5171ace1d31 Mon Sep 17 00:00:00 2001 From: Neeraj Date: Tue, 22 Oct 2024 19:28:06 +0530 Subject: [PATCH] Add method to fetch deployers while creating project --- packages/backend/src/database.ts | 6 ++++++ packages/backend/src/resolvers.ts | 4 ++++ packages/backend/src/schema.gql | 1 + packages/backend/src/service.ts | 5 +++++ .../src/components/projects/create/Configure.tsx | 15 +++++++++++++-- packages/gql-client/src/client.ts | 8 ++++++++ packages/gql-client/src/queries.ts | 10 ++++++++++ packages/gql-client/src/types.ts | 4 ++++ 8 files changed, 51 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index 7bcd77bc..518bab6c 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -597,4 +597,10 @@ export class Database { return deployer; } + + async getDeployers(): Promise { + const deployerRepository = this.dataSource.getRepository(Deployer); + const deployers = await deployerRepository.find(); + return deployers; + } } diff --git a/packages/backend/src/resolvers.ts b/packages/backend/src/resolvers.ts index 067a9f72..b4c2c01c 100644 --- a/packages/backend/src/resolvers.ts +++ b/packages/backend/src/resolvers.ts @@ -76,6 +76,10 @@ export const createResolvers = async (service: Service): Promise => { ) => { return service.getAuctionData(auctionId); }, + + deployers: async (_: any, __: any, context: any) => { + return service.getDeployers(); + }, }, // TODO: Return error in GQL response diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index 4a63e584..5accd5a3 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -257,6 +257,7 @@ type Query { searchProjects(searchText: String!): [Project!] getAuctionData(auctionId: String!): Auction! domains(projectId: String!, filter: FilterDomainsInput): [Domain] + deployers: [Deployer] } type Mutation { diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index cfc4fc49..635c522f 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -443,6 +443,11 @@ export class Service { return dbDeployments; } + async getDeployers(): Promise { + const dbDeployers = await this.db.getDeployers(); + return dbDeployers; + } + async getEnvironmentVariablesByProjectId( projectId: string, ): Promise { diff --git a/packages/frontend/src/components/projects/create/Configure.tsx b/packages/frontend/src/components/projects/create/Configure.tsx index d1380f64..95d4712b 100644 --- a/packages/frontend/src/components/projects/create/Configure.tsx +++ b/packages/frontend/src/components/projects/create/Configure.tsx @@ -1,9 +1,9 @@ -import { useCallback, useState } from 'react'; +import { useCallback, useState, useEffect } from 'react'; import { useForm, Controller } from 'react-hook-form'; import { FormProvider, FieldValues } from 'react-hook-form'; import { useNavigate, useSearchParams } from 'react-router-dom'; import { useMediaQuery } from 'usehooks-ts'; -import { AddEnvironmentVariableInput, AuctionParams } from 'gql-client'; +import { AddEnvironmentVariableInput, AuctionParams, Deployer } from 'gql-client'; import { ArrowRightCircleFilledIcon, @@ -30,6 +30,8 @@ type ConfigureFormValues = ConfigureDeploymentFormValues & const Configure = () => { const [isLoading, setIsLoading] = useState(false); + const [deployers, setDeployers] = useState([]); + const [searchParams] = useSearchParams(); const templateId = searchParams.get('templateId'); const queryParams = new URLSearchParams(location.search); @@ -171,6 +173,15 @@ const Configure = () => { [client, createProject, dismiss, toast], ); + const fetchDeployers = useCallback(async () => { + const res = await client.getDeployers() + setDeployers(res.deployers) + }, [client]) + + useEffect(()=>{ + fetchDeployers() + }, []) + return (
diff --git a/packages/gql-client/src/client.ts b/packages/gql-client/src/client.ts index 0e0eff9f..87e4bc80 100644 --- a/packages/gql-client/src/client.ts +++ b/packages/gql-client/src/client.ts @@ -424,4 +424,12 @@ export class GQLClient { return data.getAuctionData; } + + async getDeployers(): Promise { + const { data } = await this.client.query({ + query: queries.getDeployers, + }); + + return data; + } } diff --git a/packages/gql-client/src/queries.ts b/packages/gql-client/src/queries.ts index 0d2ad0f9..da8c9b62 100644 --- a/packages/gql-client/src/queries.ts +++ b/packages/gql-client/src/queries.ts @@ -307,3 +307,13 @@ query ($auctionId: String!) { } } `; + +export const getDeployers = gql` +query { + deployers { + deployerApiUrl + deployerId + deployerLrn + } +} +`; \ No newline at end of file diff --git a/packages/gql-client/src/types.ts b/packages/gql-client/src/types.ts index 74cf17b1..258aeff1 100644 --- a/packages/gql-client/src/types.ts +++ b/packages/gql-client/src/types.ts @@ -233,6 +233,10 @@ export type GetDomainsResponse = { domains: Domain[]; }; +export type GetDeployersResponse = { + deployers: Deployer[]; +}; + export type SearchProjectsResponse = { searchProjects: Project[]; };