Use Graphql types in FE and complete mappers removal (#348)
Fix Typescript build issues
This commit is contained in:
@ -1,8 +1,20 @@
|
||||
import { getOperationName } from '@apollo/client/utilities';
|
||||
import { graphql } from 'msw';
|
||||
|
||||
import { GraphqlQueryCompany } from '@/companies/interfaces/company.interface';
|
||||
import { GraphqlQueryPerson } from '@/people/interfaces/person.interface';
|
||||
import { GraphqlQueryUser } from '@/users/interfaces/user.interface';
|
||||
import { GET_COMPANIES } from '@/companies/services';
|
||||
import { GET_PEOPLE, UPDATE_PERSON } from '@/people/services';
|
||||
import {
|
||||
SEARCH_COMPANY_QUERY,
|
||||
SEARCH_USER_QUERY,
|
||||
} from '@/search/services/search';
|
||||
import { GET_CURRENT_USER } from '@/users/services';
|
||||
import {
|
||||
GetCompaniesQuery,
|
||||
GetPeopleQuery,
|
||||
GetUsersQuery,
|
||||
SearchCompanyQuery,
|
||||
SearchUserQuery,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
import { mockedCompaniesData } from './mock-data/companies';
|
||||
import { mockedPeopleData } from './mock-data/people';
|
||||
@ -10,8 +22,10 @@ import { mockedUsersData } from './mock-data/users';
|
||||
import { filterAndSortData, updateOneFromData } from './mock-data';
|
||||
|
||||
export const graphqlMocks = [
|
||||
graphql.query('GetCompanies', (req, res, ctx) => {
|
||||
const returnedMockedData = filterAndSortData<GraphqlQueryCompany>(
|
||||
graphql.query(getOperationName(GET_COMPANIES) ?? '', (req, res, ctx) => {
|
||||
const returnedMockedData = filterAndSortData<
|
||||
GetCompaniesQuery['companies'][0]
|
||||
>(
|
||||
mockedCompaniesData,
|
||||
req.variables.where,
|
||||
req.variables.orderBy,
|
||||
@ -23,21 +37,28 @@ export const graphqlMocks = [
|
||||
}),
|
||||
);
|
||||
}),
|
||||
graphql.query('SearchCompany', (req, res, ctx) => {
|
||||
const returnedMockedData = filterAndSortData<GraphqlQueryCompany>(
|
||||
mockedCompaniesData,
|
||||
req.variables.where,
|
||||
req.variables.orderBy,
|
||||
req.variables.limit,
|
||||
);
|
||||
return res(
|
||||
ctx.data({
|
||||
searchResults: returnedMockedData,
|
||||
}),
|
||||
);
|
||||
}),
|
||||
graphql.query('SearchUser', (req, res, ctx) => {
|
||||
const returnedMockedData = filterAndSortData<GraphqlQueryUser>(
|
||||
graphql.query(
|
||||
getOperationName(SEARCH_COMPANY_QUERY) ?? '',
|
||||
(req, res, ctx) => {
|
||||
const returnedMockedData = filterAndSortData<
|
||||
SearchCompanyQuery['searchResults'][0]
|
||||
>(
|
||||
mockedCompaniesData,
|
||||
req.variables.where,
|
||||
req.variables.orderBy,
|
||||
req.variables.limit,
|
||||
);
|
||||
return res(
|
||||
ctx.data({
|
||||
searchResults: returnedMockedData,
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
graphql.query(getOperationName(SEARCH_USER_QUERY) ?? '', (req, res, ctx) => {
|
||||
const returnedMockedData = filterAndSortData<
|
||||
SearchUserQuery['searchResults'][0]
|
||||
>(
|
||||
mockedUsersData,
|
||||
req.variables.where,
|
||||
req.variables.orderBy,
|
||||
@ -49,7 +70,7 @@ export const graphqlMocks = [
|
||||
}),
|
||||
);
|
||||
}),
|
||||
graphql.query('GetCurrentUser', (req, res, ctx) => {
|
||||
graphql.query(getOperationName(GET_CURRENT_USER) ?? '', (req, res, ctx) => {
|
||||
const customWhere = {
|
||||
...req.variables.where,
|
||||
id: {
|
||||
@ -57,20 +78,17 @@ export const graphqlMocks = [
|
||||
},
|
||||
};
|
||||
|
||||
const returnedMockedData = filterAndSortData<GraphqlQueryUser>(
|
||||
mockedUsersData,
|
||||
customWhere,
|
||||
req.variables.orderBy,
|
||||
req.variables.limit,
|
||||
);
|
||||
const returnedMockedData = filterAndSortData<
|
||||
GetUsersQuery['findManyUser'][0]
|
||||
>(mockedUsersData, customWhere, req.variables.orderBy, req.variables.limit);
|
||||
return res(
|
||||
ctx.data({
|
||||
users: returnedMockedData,
|
||||
}),
|
||||
);
|
||||
}),
|
||||
graphql.query('GetPeople', (req, res, ctx) => {
|
||||
const returnedMockedData = filterAndSortData<GraphqlQueryPerson>(
|
||||
graphql.query(getOperationName(GET_PEOPLE) ?? '', (req, res, ctx) => {
|
||||
const returnedMockedData = filterAndSortData<GetPeopleQuery['people'][0]>(
|
||||
mockedPeopleData,
|
||||
req.variables.where,
|
||||
req.variables.orderBy,
|
||||
@ -82,7 +100,7 @@ export const graphqlMocks = [
|
||||
}),
|
||||
);
|
||||
}),
|
||||
graphql.mutation('UpdatePeople', (req, res, ctx) => {
|
||||
graphql.mutation(getOperationName(UPDATE_PERSON) ?? '', (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.data({
|
||||
updateOnePerson: updateOneFromData(
|
||||
|
||||
@ -1,6 +1,28 @@
|
||||
import { CommentableType, CommentThread } from '~/generated/graphql';
|
||||
import {
|
||||
CommentableType,
|
||||
CommentThread,
|
||||
CommentThreadTarget,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
export const mockedCommentThreads: Array<CommentThread> = [
|
||||
type MockedCommentThread = Pick<
|
||||
CommentThread,
|
||||
'id' | 'createdAt' | 'updatedAt' | '__typename'
|
||||
> & {
|
||||
commentThreadTargets: Array<
|
||||
Pick<
|
||||
CommentThreadTarget,
|
||||
| 'id'
|
||||
| '__typename'
|
||||
| 'createdAt'
|
||||
| 'updatedAt'
|
||||
| 'commentableType'
|
||||
| 'commentableId'
|
||||
| 'commentThreadId'
|
||||
> & { commentThread: Pick<CommentThread, 'id' | 'createdAt' | 'updatedAt'> }
|
||||
>;
|
||||
};
|
||||
|
||||
export const mockedCommentThreads: Array<MockedCommentThread> = [
|
||||
{
|
||||
id: '89bb825c-171e-4bcc-9cf7-43448d6fb230',
|
||||
createdAt: '2023-04-26T10:12:42.33625+00:00',
|
||||
|
||||
@ -1,6 +1,23 @@
|
||||
import { Company } from '../../generated/graphql';
|
||||
import { Company, User } from '../../generated/graphql';
|
||||
|
||||
export const mockedCompaniesData = [
|
||||
type MockedCompany = Pick<
|
||||
Company,
|
||||
| 'id'
|
||||
| 'name'
|
||||
| 'domainName'
|
||||
| '__typename'
|
||||
| 'createdAt'
|
||||
| 'address'
|
||||
| 'employees'
|
||||
| '_commentCount'
|
||||
> & {
|
||||
accountOwner: Pick<
|
||||
User,
|
||||
'id' | 'email' | 'displayName' | '__typename'
|
||||
> | null;
|
||||
};
|
||||
|
||||
export const mockedCompaniesData: Array<MockedCompany> = [
|
||||
{
|
||||
id: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
|
||||
domainName: 'airbnb.com',
|
||||
@ -83,4 +100,4 @@ export const mockedCompaniesData = [
|
||||
accountOwner: null,
|
||||
__typename: 'Company',
|
||||
},
|
||||
] as Array<Company>;
|
||||
];
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
import { GraphQLVariables } from 'msw';
|
||||
|
||||
import { Company } from '@/companies/interfaces/company.interface';
|
||||
import { Person } from '@/people/interfaces/person.interface';
|
||||
import { User } from '@/users/interfaces/user.interface';
|
||||
import { BoolExpType } from '@/utils/interfaces/generic.interface';
|
||||
import {
|
||||
CompanyOrderByWithRelationInput,
|
||||
PersonOrderByWithRelationInput,
|
||||
@ -13,7 +9,7 @@ import {
|
||||
|
||||
function filterData<DataT>(
|
||||
data: Array<DataT>,
|
||||
where: BoolExpType<Company> | BoolExpType<Person>,
|
||||
where: Record<string, any>,
|
||||
): Array<DataT> {
|
||||
return data.filter((item) => {
|
||||
// { firstname: {contains: '%string%' }}
|
||||
@ -76,7 +72,7 @@ function filterData<DataT>(
|
||||
|
||||
export function filterAndSortData<DataT>(
|
||||
data: Array<DataT>,
|
||||
where?: BoolExpType<Company> | BoolExpType<Person> | BoolExpType<User>,
|
||||
where?: Record<string, any>,
|
||||
orderBy?: Array<
|
||||
PersonOrderByWithRelationInput &
|
||||
CompanyOrderByWithRelationInput &
|
||||
|
||||
@ -1,6 +1,21 @@
|
||||
import { Person } from '../../modules/people/interfaces/person.interface';
|
||||
import { Company, Person } from '~/generated/graphql';
|
||||
|
||||
export const mockedPeopleData = [
|
||||
type MockedPerson = Pick<
|
||||
Person,
|
||||
| 'id'
|
||||
| 'firstname'
|
||||
| 'lastname'
|
||||
| 'email'
|
||||
| '__typename'
|
||||
| 'phone'
|
||||
| 'city'
|
||||
| '_commentCount'
|
||||
| 'createdAt'
|
||||
> & {
|
||||
company: Pick<Company, 'id' | 'name' | 'domainName' | '__typename'>;
|
||||
};
|
||||
|
||||
export const mockedPeopleData: Array<MockedPerson> = [
|
||||
{
|
||||
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
|
||||
__typename: 'Person',
|
||||
@ -73,4 +88,4 @@ export const mockedPeopleData = [
|
||||
|
||||
city: 'Paris',
|
||||
},
|
||||
] satisfies Array<Person>;
|
||||
];
|
||||
|
||||
@ -1,6 +1,18 @@
|
||||
import { GraphqlQueryUser } from '@/users/interfaces/user.interface';
|
||||
import { User, Workspace, WorkspaceMember } from '~/generated/graphql';
|
||||
|
||||
export const mockedUsersData: Array<GraphqlQueryUser> = [
|
||||
type MockedUser = Pick<
|
||||
User,
|
||||
'id' | 'email' | 'displayName' | 'avatarUrl' | '__typename'
|
||||
> & {
|
||||
workspaceMember: Pick<WorkspaceMember, 'id' | '__typename'> & {
|
||||
workspace: Pick<
|
||||
Workspace,
|
||||
'id' | 'displayName' | 'domainName' | 'logo' | '__typename'
|
||||
>;
|
||||
};
|
||||
};
|
||||
|
||||
export const mockedUsersData: Array<MockedUser> = [
|
||||
{
|
||||
id: '374fe3a5-df1e-4119-afe0-2a62a2ba481e',
|
||||
__typename: 'User',
|
||||
@ -37,4 +49,4 @@ export const mockedUsersData: Array<GraphqlQueryUser> = [
|
||||
},
|
||||
},
|
||||
},
|
||||
] as GraphqlQueryUser[];
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user