[CoreViewField BREAKING_CHANGES] Refactor view field service v2 and resolver (#14396)
## Introduction ### Twenty-sever Standardizing resolver input and transpilation models + return type on destroy and delete ~~Finally~~ Did plug everything under a feature flag and add coverage Next will do same for the view resolver and service v2 ### Twenty-front Refactored view field service in order to use codegenerated strictly typed mutations and adapt to new api contract
This commit is contained in:
+17
-6
@@ -15,13 +15,13 @@ import {
|
||||
} from 'test/integration/graphql/utils/view-data-factory.util';
|
||||
import { createTestViewWithGraphQL } from 'test/integration/graphql/utils/view-graphql.util';
|
||||
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
|
||||
import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';
|
||||
import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
|
||||
import {
|
||||
assertViewFieldStructure,
|
||||
cleanupViewRecords,
|
||||
} from 'test/integration/utils/view-test.util';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';
|
||||
|
||||
import { ErrorCode } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
||||
import {
|
||||
@@ -201,8 +201,10 @@ describe('View Field Resolver', () => {
|
||||
size: 300,
|
||||
});
|
||||
const updateOperation = updateViewFieldOperationFactory({
|
||||
viewFieldId: viewField.id,
|
||||
data: updateInput,
|
||||
input: {
|
||||
id: viewField.id,
|
||||
update: updateInput,
|
||||
},
|
||||
});
|
||||
const response = await makeGraphqlAPIRequest(updateOperation);
|
||||
|
||||
@@ -217,7 +219,12 @@ describe('View Field Resolver', () => {
|
||||
|
||||
it('should throw an error when updating non-existent view field', async () => {
|
||||
const operation = updateViewFieldOperationFactory({
|
||||
viewFieldId: TEST_NOT_EXISTING_VIEW_FIELD_ID,
|
||||
input: {
|
||||
id: TEST_NOT_EXISTING_VIEW_FIELD_ID,
|
||||
update: {
|
||||
position: 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
const response = await makeGraphqlAPIRequest(operation);
|
||||
|
||||
@@ -249,7 +256,9 @@ describe('View Field Resolver', () => {
|
||||
const response = await makeGraphqlAPIRequest(deleteOperation);
|
||||
|
||||
assertGraphQLSuccessfulResponse(response);
|
||||
expect(response.body.data.deleteCoreViewField).toBe(true);
|
||||
expect(response.body.data.deleteCoreViewField).toMatchObject({
|
||||
id: viewField.id,
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error when deleting non-existent view field', async () => {
|
||||
@@ -286,7 +295,9 @@ describe('View Field Resolver', () => {
|
||||
const response = await makeGraphqlAPIRequest(destroyOperation);
|
||||
|
||||
assertGraphQLSuccessfulResponse(response);
|
||||
expect(response.body.data.destroyCoreViewField).toBe(true);
|
||||
expect(response.body.data.destroyCoreViewField).toMatchObject({
|
||||
id: viewField.id,
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error when destroying non-existent view field', async () => {
|
||||
|
||||
+8
-3
@@ -1,16 +1,21 @@
|
||||
import gql from 'graphql-tag';
|
||||
import { VIEW_FIELD_GQL_FIELDS } from 'test/integration/constants/view-gql-fields.constants';
|
||||
|
||||
export const deleteViewFieldOperationFactory = ({
|
||||
viewFieldId,
|
||||
gqlFields = VIEW_FIELD_GQL_FIELDS,
|
||||
}: {
|
||||
gqlFields?: string;
|
||||
viewFieldId: string;
|
||||
}) => ({
|
||||
query: gql`
|
||||
mutation DeleteCoreViewField($id: String!) {
|
||||
deleteCoreViewField(id: $id)
|
||||
mutation DeleteCoreViewField($input: DeleteViewFieldInput!) {
|
||||
deleteCoreViewField(input: $input) {
|
||||
${gqlFields}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
id: viewFieldId,
|
||||
input: { id: viewFieldId },
|
||||
},
|
||||
});
|
||||
|
||||
+8
-3
@@ -1,16 +1,21 @@
|
||||
import gql from 'graphql-tag';
|
||||
import { VIEW_FIELD_GQL_FIELDS } from 'test/integration/constants/view-gql-fields.constants';
|
||||
|
||||
export const destroyViewFieldOperationFactory = ({
|
||||
viewFieldId,
|
||||
gqlFields = VIEW_FIELD_GQL_FIELDS,
|
||||
}: {
|
||||
gqlFields?: string;
|
||||
viewFieldId: string;
|
||||
}) => ({
|
||||
query: gql`
|
||||
mutation DestroyCoreViewField($id: String!) {
|
||||
destroyCoreViewField(id: $id)
|
||||
mutation DestroyCoreViewField($input: DestroyViewFieldInput!) {
|
||||
destroyCoreViewField(input: $input){
|
||||
${gqlFields}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
id: viewFieldId,
|
||||
input: { id: viewFieldId },
|
||||
},
|
||||
});
|
||||
|
||||
+7
-8
@@ -1,24 +1,23 @@
|
||||
import gql from 'graphql-tag';
|
||||
import { VIEW_FIELD_GQL_FIELDS } from 'test/integration/constants/view-gql-fields.constants';
|
||||
|
||||
import { type UpdateViewFieldInput } from 'src/engine/core-modules/view/dtos/inputs/update-view-field.input';
|
||||
|
||||
export const updateViewFieldOperationFactory = ({
|
||||
gqlFields = VIEW_FIELD_GQL_FIELDS,
|
||||
viewFieldId,
|
||||
data = {},
|
||||
input,
|
||||
}: {
|
||||
gqlFields?: string;
|
||||
viewFieldId: string;
|
||||
data?: object;
|
||||
input: UpdateViewFieldInput;
|
||||
}) => ({
|
||||
query: gql`
|
||||
mutation UpdateCoreViewField($id: String!, $input: UpdateViewFieldInput!) {
|
||||
updateCoreViewField(id: $id, input: $input) {
|
||||
mutation UpdateCoreViewField($input: UpdateViewFieldInput!) {
|
||||
updateCoreViewField(input: $input) {
|
||||
${gqlFields}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
id: viewFieldId,
|
||||
input: data,
|
||||
input,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { type UpdateViewFieldInput } from 'src/engine/core-modules/view/dtos/inputs/update-view-field.input';
|
||||
import { type ViewFieldEntity } from 'src/engine/core-modules/view/entities/view-field.entity';
|
||||
import { type ViewFilterGroupEntity } from 'src/engine/core-modules/view/entities/view-filter-group.entity';
|
||||
import { type ViewFilterEntity } from 'src/engine/core-modules/view/entities/view-filter.entity';
|
||||
@@ -40,7 +41,7 @@ export const createViewFieldData = (
|
||||
});
|
||||
|
||||
export const updateViewFieldData = (
|
||||
overrides: Partial<ViewFieldEntity> = {},
|
||||
overrides: Partial<UpdateViewFieldInput['update']> = {},
|
||||
) => ({
|
||||
position: 5,
|
||||
isVisible: false,
|
||||
|
||||
Reference in New Issue
Block a user