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
This commit is contained in:
Sammy Teillet
2023-06-05 17:36:14 +02:00
committed by GitHub
parent fe70f30a29
commit 063ef8a4eb
11 changed files with 27 additions and 31 deletions

View File

@@ -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; }>; export type GetUsersQueryVariables = Exact<{ [key: string]: never; }>;
@@ -1867,6 +1867,7 @@ export const GetCurrentUserDocument = gql`
email email
displayName displayName
workspaceMember { workspaceMember {
id
workspace { workspace {
id id
domainName domainName

View File

@@ -33,7 +33,7 @@ export type GraphqlQueryCompany = {
accountOwner?: GraphqlQueryUser | null; accountOwner?: GraphqlQueryUser | null;
pipes?: GraphqlQueryPipeline[] | null; pipes?: GraphqlQueryPipeline[] | null;
__typename: string; __typename?: string;
}; };
export type GraphqlMutationCompany = { export type GraphqlMutationCompany = {
@@ -46,7 +46,7 @@ export type GraphqlMutationCompany = {
createdAt?: string; createdAt?: string;
accountOwnerId?: string; accountOwnerId?: string;
__typename: string; __typename?: string;
}; };
export const mapToCompany = (company: GraphqlQueryCompany): Company => ({ export const mapToCompany = (company: GraphqlQueryCompany): Company => ({

View File

@@ -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 { SelectedSortType } from '@/filters-and-sorts/interfaces/sorts/interface';
import { import {
CompanyOrderByWithRelationInput as Companies_Order_By, CompanyOrderByWithRelationInput as Companies_Order_By,
CompanyWhereInput as Companies_Bool_Exp, CompanyWhereInput as Companies_Bool_Exp,
SortOrder as Order_By, SortOrder as Order_By,
useGetCompaniesQuery,
} from '~/generated/graphql'; } from '~/generated/graphql';
import { GraphqlQueryCompany } from '../interfaces/company.interface';
export type CompaniesSelectedSortType = SelectedSortType<Companies_Order_By>; export type CompaniesSelectedSortType = SelectedSortType<Companies_Order_By>;
export const GET_COMPANIES = gql` export const GET_COMPANIES = gql`
@@ -35,10 +34,8 @@ export const GET_COMPANIES = gql`
export function useCompaniesQuery( export function useCompaniesQuery(
orderBy: Companies_Order_By[], orderBy: Companies_Order_By[],
where: Companies_Bool_Exp, where: Companies_Bool_Exp,
): QueryResult<{ companies: GraphqlQueryCompany[] }> { ) {
return useQuery<{ companies: GraphqlQueryCompany[] }>(GET_COMPANIES, { return useGetCompaniesQuery({ variables: { orderBy, where } });
variables: { orderBy, where },
});
} }
export const defaultOrderBy: Companies_Order_By[] = [ export const defaultOrderBy: Companies_Order_By[] = [

View File

@@ -33,7 +33,7 @@ export type GraphqlQueryPerson = {
company?: GraphqlQueryCompany | null; company?: GraphqlQueryCompany | null;
__typename: string; __typename?: string;
}; };
export type GraphqlMutationPerson = { export type GraphqlMutationPerson = {

View File

@@ -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 { SelectedSortType } from '@/filters-and-sorts/interfaces/sorts/interface';
import { import {
PersonOrderByWithRelationInput as People_Order_By, PersonOrderByWithRelationInput as People_Order_By,
PersonWhereInput as People_Bool_Exp, PersonWhereInput as People_Bool_Exp,
SortOrder, SortOrder,
useGetPeopleQuery,
} from '~/generated/graphql'; } from '~/generated/graphql';
import { GraphqlQueryPerson } from '../interfaces/person.interface';
export type PeopleSelectedSortType = SelectedSortType<People_Order_By>; export type PeopleSelectedSortType = SelectedSortType<People_Order_By>;
export const GET_PEOPLE = gql` export const GET_PEOPLE = gql`
@@ -37,8 +36,8 @@ export const GET_PEOPLE = gql`
export function usePeopleQuery( export function usePeopleQuery(
orderBy: People_Order_By[], orderBy: People_Order_By[],
where: People_Bool_Exp, where: People_Bool_Exp,
): QueryResult<{ people: GraphqlQueryPerson[] }> { ) {
return useQuery<{ people: GraphqlQueryPerson[] }>(GET_PEOPLE, { return useGetPeopleQuery({
variables: { orderBy, where }, variables: { orderBy, where },
}); });
} }

View File

@@ -8,5 +8,5 @@ export interface GraphqlQueryPipeline {
id: string; id: string;
name?: string; name?: string;
icon?: string | null; icon?: string | null;
__typename: string; __typename?: string;
} }

View File

@@ -9,15 +9,15 @@ export interface User {
id: string; id: string;
email?: string; email?: string;
displayName?: string; displayName?: string;
workspaceMember?: WorkspaceMember; workspaceMember?: WorkspaceMember | null;
} }
export type GraphqlQueryUser = { export type GraphqlQueryUser = {
id: string; id: string;
email?: string; email?: string;
displayName?: string; displayName?: string;
workspaceMember?: GraphqlQueryWorkspaceMember; workspaceMember?: GraphqlQueryWorkspaceMember | null;
__typename: string; __typename?: string;
}; };
export type GraphqlMutationUser = { export type GraphqlMutationUser = {
@@ -25,7 +25,7 @@ export type GraphqlMutationUser = {
email?: string; email?: string;
displayName?: string; displayName?: string;
workspaceMemberId?: string; workspaceMemberId?: string;
__typename: string; __typename?: string;
}; };
export const mapToUser = (user: GraphqlQueryUser): User => ({ export const mapToUser = (user: GraphqlQueryUser): User => ({

View File

@@ -12,13 +12,13 @@ export interface WorkspaceMember {
export type GraphqlQueryWorkspaceMember = { export type GraphqlQueryWorkspaceMember = {
id: string; id: string;
workspace: GraphqlQueryWorkspace; workspace: GraphqlQueryWorkspace;
__typename: string; __typename?: string;
}; };
export type GraphqlMutationWorkspaceMember = { export type GraphqlMutationWorkspaceMember = {
id: string; id: string;
workspace_id: string; workspace_id: string;
__typename: string; __typename?: string;
}; };
export const mapToWorkspaceMember = ( export const mapToWorkspaceMember = (

View File

@@ -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` export const GET_CURRENT_USER = gql`
query GetCurrentUser($uuid: String) { query GetCurrentUser($uuid: String) {
@@ -9,6 +9,7 @@ export const GET_CURRENT_USER = gql`
email email
displayName displayName
workspaceMember { workspaceMember {
id
workspace { workspace {
id id
domainName domainName
@@ -20,10 +21,8 @@ export const GET_CURRENT_USER = gql`
} }
`; `;
export function useGetCurrentUserQuery(userId: string | null): QueryResult<{ export function useGetCurrentUserQuery(userId: string | null) {
users: GraphqlQueryUser[]; return generatedUseGetCurrentUserQuery({
}> {
return useQuery<{ users: GraphqlQueryUser[] }>(GET_CURRENT_USER, {
variables: { variables: {
uuid: userId, uuid: userId,
}, },

View File

@@ -10,7 +10,7 @@ export type GraphqlQueryWorkspace = {
displayName?: string; displayName?: string;
domainName?: string; domainName?: string;
logo?: string | null; logo?: string | null;
__typename: string; __typename?: string;
}; };
export type GraphqlMutationWorkspace = { export type GraphqlMutationWorkspace = {
@@ -18,7 +18,7 @@ export type GraphqlMutationWorkspace = {
displayName?: string; displayName?: string;
domainName?: string; domainName?: string;
logo?: string | null; logo?: string | null;
__typename: string; __typename?: string;
}; };
export const mapToWorkspace = ( export const mapToWorkspace = (