From 063ef8a4eba523d042e7119a5509f9e29bcb36ff Mon Sep 17 00:00:00 2001 From: Sammy Teillet Date: Mon, 5 Jun 2023 17:36:14 +0200 Subject: [PATCH] Sammy/t refactor services use generated code (#194) * refactor: use generated queries for Companies * refactor: remove useQuery from service, use generated code * refactor: rename to ts file instead of tsx * bugfix: use generatd queries, and fix non existing id in workspace member query --- front/src/generated/graphql.tsx | 3 ++- .../modules/companies/interfaces/company.interface.ts | 4 ++-- front/src/modules/companies/services/select.ts | 11 ++++------- .../src/modules/people/interfaces/person.interface.ts | 2 +- front/src/modules/people/services/select.ts | 9 ++++----- .../pipelines/interfaces/pipeline.interface.ts | 2 +- front/src/modules/users/interfaces/user.interface.ts | 8 ++++---- .../users/interfaces/workspaceMember.interface.ts | 4 ++-- .../modules/users/services/{index.tsx => index.ts} | 11 +++++------ .../src/modules/users/services/{test.tsx => test.ts} | 0 .../workspaces/interfaces/workspace.interface.ts | 4 ++-- 11 files changed, 27 insertions(+), 31 deletions(-) rename front/src/modules/users/services/{index.tsx => index.ts} (55%) rename front/src/modules/users/services/{test.tsx => test.ts} (100%) diff --git a/front/src/generated/graphql.tsx b/front/src/generated/graphql.tsx index 3c44a3eab..e898620c1 100644 --- a/front/src/generated/graphql.tsx +++ b/front/src/generated/graphql.tsx @@ -1219,7 +1219,7 @@ export type GetCurrentUserQueryVariables = Exact<{ }>; -export type GetCurrentUserQuery = { __typename?: 'Query', users: Array<{ __typename?: 'User', id: string, email: string, displayName: string, workspaceMember?: { __typename?: 'WorkspaceMember', workspace: { __typename?: 'Workspace', id: string, domainName: string, displayName: string, logo?: string | null } } | null }> }; +export type GetCurrentUserQuery = { __typename?: 'Query', users: Array<{ __typename?: 'User', id: string, email: string, displayName: string, workspaceMember?: { __typename?: 'WorkspaceMember', id: string, workspace: { __typename?: 'Workspace', id: string, domainName: string, displayName: string, logo?: string | null } } | null }> }; export type GetUsersQueryVariables = Exact<{ [key: string]: never; }>; @@ -1867,6 +1867,7 @@ export const GetCurrentUserDocument = gql` email displayName workspaceMember { + id workspace { id domainName diff --git a/front/src/modules/companies/interfaces/company.interface.ts b/front/src/modules/companies/interfaces/company.interface.ts index 5be8d36b6..7b4fdaa9d 100644 --- a/front/src/modules/companies/interfaces/company.interface.ts +++ b/front/src/modules/companies/interfaces/company.interface.ts @@ -33,7 +33,7 @@ export type GraphqlQueryCompany = { accountOwner?: GraphqlQueryUser | null; pipes?: GraphqlQueryPipeline[] | null; - __typename: string; + __typename?: string; }; export type GraphqlMutationCompany = { @@ -46,7 +46,7 @@ export type GraphqlMutationCompany = { createdAt?: string; accountOwnerId?: string; - __typename: string; + __typename?: string; }; export const mapToCompany = (company: GraphqlQueryCompany): Company => ({ diff --git a/front/src/modules/companies/services/select.ts b/front/src/modules/companies/services/select.ts index df0a7cdc1..49e7fe980 100644 --- a/front/src/modules/companies/services/select.ts +++ b/front/src/modules/companies/services/select.ts @@ -1,14 +1,13 @@ -import { gql, QueryResult, useQuery } from '@apollo/client'; +import { gql } from '@apollo/client'; import { SelectedSortType } from '@/filters-and-sorts/interfaces/sorts/interface'; import { CompanyOrderByWithRelationInput as Companies_Order_By, CompanyWhereInput as Companies_Bool_Exp, SortOrder as Order_By, + useGetCompaniesQuery, } from '~/generated/graphql'; -import { GraphqlQueryCompany } from '../interfaces/company.interface'; - export type CompaniesSelectedSortType = SelectedSortType; export const GET_COMPANIES = gql` @@ -35,10 +34,8 @@ export const GET_COMPANIES = gql` export function useCompaniesQuery( orderBy: Companies_Order_By[], where: Companies_Bool_Exp, -): QueryResult<{ companies: GraphqlQueryCompany[] }> { - return useQuery<{ companies: GraphqlQueryCompany[] }>(GET_COMPANIES, { - variables: { orderBy, where }, - }); +) { + return useGetCompaniesQuery({ variables: { orderBy, where } }); } export const defaultOrderBy: Companies_Order_By[] = [ diff --git a/front/src/modules/people/interfaces/person.interface.ts b/front/src/modules/people/interfaces/person.interface.ts index f4d3fdbb7..d0d5cd871 100644 --- a/front/src/modules/people/interfaces/person.interface.ts +++ b/front/src/modules/people/interfaces/person.interface.ts @@ -33,7 +33,7 @@ export type GraphqlQueryPerson = { company?: GraphqlQueryCompany | null; - __typename: string; + __typename?: string; }; export type GraphqlMutationPerson = { diff --git a/front/src/modules/people/services/select.ts b/front/src/modules/people/services/select.ts index ffa364215..a8efccdff 100644 --- a/front/src/modules/people/services/select.ts +++ b/front/src/modules/people/services/select.ts @@ -1,14 +1,13 @@ -import { gql, QueryResult, useQuery } from '@apollo/client'; +import { gql } from '@apollo/client'; import { SelectedSortType } from '@/filters-and-sorts/interfaces/sorts/interface'; import { PersonOrderByWithRelationInput as People_Order_By, PersonWhereInput as People_Bool_Exp, SortOrder, + useGetPeopleQuery, } from '~/generated/graphql'; -import { GraphqlQueryPerson } from '../interfaces/person.interface'; - export type PeopleSelectedSortType = SelectedSortType; export const GET_PEOPLE = gql` @@ -37,8 +36,8 @@ export const GET_PEOPLE = gql` export function usePeopleQuery( orderBy: People_Order_By[], where: People_Bool_Exp, -): QueryResult<{ people: GraphqlQueryPerson[] }> { - return useQuery<{ people: GraphqlQueryPerson[] }>(GET_PEOPLE, { +) { + return useGetPeopleQuery({ variables: { orderBy, where }, }); } diff --git a/front/src/modules/pipelines/interfaces/pipeline.interface.ts b/front/src/modules/pipelines/interfaces/pipeline.interface.ts index 29de6dc3a..5fc0283fa 100644 --- a/front/src/modules/pipelines/interfaces/pipeline.interface.ts +++ b/front/src/modules/pipelines/interfaces/pipeline.interface.ts @@ -8,5 +8,5 @@ export interface GraphqlQueryPipeline { id: string; name?: string; icon?: string | null; - __typename: string; + __typename?: string; } diff --git a/front/src/modules/users/interfaces/user.interface.ts b/front/src/modules/users/interfaces/user.interface.ts index 1a76ef291..ca787dd6d 100644 --- a/front/src/modules/users/interfaces/user.interface.ts +++ b/front/src/modules/users/interfaces/user.interface.ts @@ -9,15 +9,15 @@ export interface User { id: string; email?: string; displayName?: string; - workspaceMember?: WorkspaceMember; + workspaceMember?: WorkspaceMember | null; } export type GraphqlQueryUser = { id: string; email?: string; displayName?: string; - workspaceMember?: GraphqlQueryWorkspaceMember; - __typename: string; + workspaceMember?: GraphqlQueryWorkspaceMember | null; + __typename?: string; }; export type GraphqlMutationUser = { @@ -25,7 +25,7 @@ export type GraphqlMutationUser = { email?: string; displayName?: string; workspaceMemberId?: string; - __typename: string; + __typename?: string; }; export const mapToUser = (user: GraphqlQueryUser): User => ({ diff --git a/front/src/modules/users/interfaces/workspaceMember.interface.ts b/front/src/modules/users/interfaces/workspaceMember.interface.ts index 1e38d00a1..433d9b876 100644 --- a/front/src/modules/users/interfaces/workspaceMember.interface.ts +++ b/front/src/modules/users/interfaces/workspaceMember.interface.ts @@ -12,13 +12,13 @@ export interface WorkspaceMember { export type GraphqlQueryWorkspaceMember = { id: string; workspace: GraphqlQueryWorkspace; - __typename: string; + __typename?: string; }; export type GraphqlMutationWorkspaceMember = { id: string; workspace_id: string; - __typename: string; + __typename?: string; }; export const mapToWorkspaceMember = ( diff --git a/front/src/modules/users/services/index.tsx b/front/src/modules/users/services/index.ts similarity index 55% rename from front/src/modules/users/services/index.tsx rename to front/src/modules/users/services/index.ts index 5eb898e09..3b4cf45bf 100644 --- a/front/src/modules/users/services/index.tsx +++ b/front/src/modules/users/services/index.ts @@ -1,6 +1,6 @@ -import { gql, QueryResult, useQuery } from '@apollo/client'; +import { gql } from '@apollo/client'; -import { GraphqlQueryUser } from '../interfaces/user.interface'; +import { useGetCurrentUserQuery as generatedUseGetCurrentUserQuery } from '~/generated/graphql'; export const GET_CURRENT_USER = gql` query GetCurrentUser($uuid: String) { @@ -9,6 +9,7 @@ export const GET_CURRENT_USER = gql` email displayName workspaceMember { + id workspace { id domainName @@ -20,10 +21,8 @@ export const GET_CURRENT_USER = gql` } `; -export function useGetCurrentUserQuery(userId: string | null): QueryResult<{ - users: GraphqlQueryUser[]; -}> { - return useQuery<{ users: GraphqlQueryUser[] }>(GET_CURRENT_USER, { +export function useGetCurrentUserQuery(userId: string | null) { + return generatedUseGetCurrentUserQuery({ variables: { uuid: userId, }, diff --git a/front/src/modules/users/services/test.tsx b/front/src/modules/users/services/test.ts similarity index 100% rename from front/src/modules/users/services/test.tsx rename to front/src/modules/users/services/test.ts diff --git a/front/src/modules/workspaces/interfaces/workspace.interface.ts b/front/src/modules/workspaces/interfaces/workspace.interface.ts index 3436b2618..7371ff9b7 100644 --- a/front/src/modules/workspaces/interfaces/workspace.interface.ts +++ b/front/src/modules/workspaces/interfaces/workspace.interface.ts @@ -10,7 +10,7 @@ export type GraphqlQueryWorkspace = { displayName?: string; domainName?: string; logo?: string | null; - __typename: string; + __typename?: string; }; export type GraphqlMutationWorkspace = { @@ -18,7 +18,7 @@ export type GraphqlMutationWorkspace = { displayName?: string; domainName?: string; logo?: string | null; - __typename: string; + __typename?: string; }; export const mapToWorkspace = (