Skip to content

The open alternative to Salesforce, designed for AI.

Remove legacy graphql-upload mutations superseded by direct upload (#25348)

martmullb56554a73a63
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
index 18f225ca2cc..11291003b27 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
@@ -3735,12 +3735,8 @@ type Mutation {
refreshEnterpriseValidityToken: Boolean!
releaseEnterpriseServerBinding: EnterpriseLicenseInfoDTO!
setEnterpriseKey(enterpriseKey: String!): EnterpriseLicenseInfoDTO!
- uploadEmailAttachmentFile(file: Upload!): FileWithSignedUrl!
- uploadAiChatFile(file: Upload!): FileWithSignedUrl!
- uploadWorkflowFile(file: Upload!): FileWithSignedUrl!
uploadWorkspaceLogo(file: Upload!): FileWithSignedUrl!
uploadWorkspaceMemberProfilePicture(file: Upload!): FileWithSignedUrl!
- uploadFilesFieldFile(file: Upload!, fieldMetadataId: String!): FileWithSignedUrl!
uploadFilesFieldFileByUniversalIdentifier(file: Upload!, fieldMetadataUniversalIdentifier: String!): FileWithSignedUrl!
upsertUsageLimit(input: UpsertUsageLimitInput!): UsageLimit!
deleteUsageLimit(usageLimitId: UUID!): Boolean!
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.ts b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
index f3884850a91..72b29f84a83 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
@@ -3186,12 +3186,8 @@ export interface Mutation {
refreshEnterpriseValidityToken: Scalars['Boolean']
releaseEnterpriseServerBinding: EnterpriseLicenseInfoDTO
setEnterpriseKey: EnterpriseLicenseInfoDTO
- uploadEmailAttachmentFile: FileWithSignedUrl
- uploadAiChatFile: FileWithSignedUrl
- uploadWorkflowFile: FileWithSignedUrl
uploadWorkspaceLogo: FileWithSignedUrl
uploadWorkspaceMemberProfilePicture: FileWithSignedUrl
- uploadFilesFieldFile: FileWithSignedUrl
uploadFilesFieldFileByUniversalIdentifier: FileWithSignedUrl
upsertUsageLimit: UsageLimit
deleteUsageLimit: Scalars['Boolean']
@@ -6798,12 +6794,8 @@ export interface MutationGenqlSelection{
refreshEnterpriseValidityToken?: boolean | number
releaseEnterpriseServerBinding?: EnterpriseLicenseInfoDTOGenqlSelection
setEnterpriseKey?: (EnterpriseLicenseInfoDTOGenqlSelection & { __args: {enterpriseKey: Scalars['String']} })
- uploadEmailAttachmentFile?: (FileWithSignedUrlGenqlSelection & { __args: {file: Scalars['Upload']} })
- uploadAiChatFile?: (FileWithSignedUrlGenqlSelection & { __args: {file: Scalars['Upload']} })
- uploadWorkflowFile?: (FileWithSignedUrlGenqlSelection & { __args: {file: Scalars['Upload']} })
uploadWorkspaceLogo?: (FileWithSignedUrlGenqlSelection & { __args: {file: Scalars['Upload']} })
uploadWorkspaceMemberProfilePicture?: (FileWithSignedUrlGenqlSelection & { __args: {file: Scalars['Upload']} })
- uploadFilesFieldFile?: (FileWithSignedUrlGenqlSelection & { __args: {file: Scalars['Upload'], fieldMetadataId: Scalars['String']} })
uploadFilesFieldFileByUniversalIdentifier?: (FileWithSignedUrlGenqlSelection & { __args: {file: Scalars['Upload'], fieldMetadataUniversalIdentifier: Scalars['String']} })
upsertUsageLimit?: (UsageLimitGenqlSelection & { __args: {input: UpsertUsageLimitInput} })
deleteUsageLimit?: { __args: {usageLimitId: Scalars['UUID']} }
diff --git a/packages/twenty-client-sdk/src/metadata/generated/types.ts b/packages/twenty-client-sdk/src/metadata/generated/types.ts
index b852924cd4a..20a06122128 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/types.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/types.ts
@@ -8025,33 +8025,6 @@ export default {
]
}
],
- "uploadEmailAttachmentFile": [
- 148,
- {
- "file": [
- 409,
- "Upload!"
- ]
- }
- ],
- "uploadAiChatFile": [
- 148,
- {
- "file": [
- 409,
- "Upload!"
- ]
- }
- ],
- "uploadWorkflowFile": [
- 148,
- {
- "file": [
- 409,
- "Upload!"
- ]
- }
- ],
"uploadWorkspaceLogo": [
148,
{
@@ -8070,19 +8043,6 @@ export default {
]
}
],
- "uploadFilesFieldFile": [
- 148,
- {
- "file": [
- 409,
- "Upload!"
- ],
- "fieldMetadataId": [
- 1,
- "String!"
- ]
- }
- ],
"uploadFilesFieldFileByUniversalIdentifier": [
148,
{
diff --git a/packages/twenty-docs/user-guide/workflows/how-tos/connect-to-other-tools/generate-pdf-from-twenty.mdx b/packages/twenty-docs/user-guide/workflows/how-tos/connect-to-other-tools/generate-pdf-from-twenty.mdx
index 607abfad5bf..73882f06fe9 100644
--- a/packages/twenty-docs/user-guide/workflows/how-tos/connect-to-other-tools/generate-pdf-from-twenty.mdx
+++ b/packages/twenty-docs/user-guide/workflows/how-tos/connect-to-other-tools/generate-pdf-from-twenty.mdx
@@ -108,42 +108,99 @@ export const main = async (
const result = await response.json();
const uploadFileFieldMetadataId = result.data.objects.edges.find(object => object.node.nameSingular === 'attachment').node.fieldsList.find(field => field.name === 'file').id;
- // Step 3: Upload the file via GraphQL multipart upload
- const uploadMutation = `
- mutation UploadFilesFieldFile($file: Upload!, $fieldMetadataId: String!) {
- uploadFilesFieldFile(file: $file, fieldMetadataId: $fieldMetadataId) {
- id
+ // Step 3: Request an upload URL for the file
+ const createFileUploadMutation = `
+ mutation CreateFileUpload($filename: String!, $size: Float!, $fileFolder: FileFolder!, $fieldMetadataId: String) {
+ createFileUpload(filename: $filename, size: $size, fileFolder: $fileFolder, fieldMetadataId: $fieldMetadataId) {
+ fileId
+ uploadUrl
+ contentType
}
}
`;
- const uploadForm = new FormData();
- uploadForm.append('operations', JSON.stringify({
- query: uploadMutation,
- variables: { file: null, fieldMetadataId: uploadFileFieldMetadataId },
- }));
- uploadForm.append('map', JSON.stringify({ '0': ['variables.file'] }));
- uploadForm.append('0', pdfFile);
-
- const uploadResponse = await fetch(metadataGraphqlEndpoint, {
+ const createFileUploadResponse = await fetch(metadataGraphqlEndpoint, {
method: 'POST',
- headers: { Authorization: `Bearer ${authToken}` },
- body: uploadForm,
+ headers: {
+ Authorization: `Bearer ${authToken}`,
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ query: createFileUploadMutation,
+ variables: {
+ filename,
+ size: pdfFile.size,
+ fileFolder: 'FilesField',
+ fieldMetadataId: uploadFileFieldMetadataId,
+ },
+ }),
+ });
+
+ if (!createFileUploadResponse.ok) {
+ throw new Error(`Upload failed with status ${createFileUploadResponse.status}`);
+ }
+
+ const createFileUploadResult = await createFileUploadResponse.json();
+
+ if (createFileUploadResult.errors?.length) {
+ throw new Error(`Upload failed: ${createFileUploadResult.errors[0].message}`);
+ }
+
+ const uploadTarget = createFileUploadResult.data?.createFileUpload;
+
+ if (!uploadTarget) {
+ throw new Error('No upload target returned from createFileUpload');
+ }
+
+ const { fileId, uploadUrl, contentType } = uploadTarget;
+
+ // Step 4: Send the file bytes to the upload URL
+ const putResponse = await fetch(uploadUrl, {
+ method: 'PUT',
+ headers: { 'Content-Type': contentType },
+ body: pdfFile,
});
- const uploadResult = await uploadResponse.json();
+ if (!putResponse.ok) {
+ throw new Error(`Upload failed with status ${putResponse.status}`);
+ }
+
+ // Step 5: Confirm the upload so the file becomes usable
+ const completeFileUploadMutation = `
+ mutation CompleteFileUpload($fileId: String!) {
+ completeFileUpload(fileId: $fileId) {
+ id
+ }
+ }
+ `;
- if (uploadResult.errors?.length) {
- throw new Error(`Upload failed: ${uploadResult.errors[0].message}`);
+ const completeFileUploadResponse = await fetch(metadataGraphqlEndpoint, {
+ method: 'POST',
+ headers: {
+ Authorization: `Bearer ${authToken}`,
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ query: completeFileUploadMutation,
+ variables: { fileId },
+ }),
+ });
+
+ if (!completeFileUploadResponse.ok) {
+ throw new Error(`Upload failed with status ${completeFileUploadResponse.status}`);
}
- const fileId = uploadResult.data?.uploadFilesFieldFile?.id;
+ const completeFileUploadResult = await completeFileUploadResponse.json();
+
+ if (completeFileUploadResult.errors?.length) {
+ throw new Error(`Upload failed: ${completeFileUploadResult.errors[0].message}`);
+ }
- if (!fileId) {
- throw new Error('No file id returned from upload');
+ if (!completeFileUploadResult.data?.completeFileUpload?.id) {
+ throw new Error('No file id returned from completeFileUpload');
}
- // Step 4: Create the attachment linked to the company
+ // Step 6: Create the attachment linked to the company
const attachmentMutation = `
mutation CreateOneAttachment($data: AttachmentCreateInput!) {
createAttachment(data: $data) {
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts
index 76df0daf515..14a28d6143f 100644
--- a/packages/twenty-front/src/generated-metadata/graphql.ts
+++ b/packages/twenty-front/src/generated-metadata/graphql.ts
@@ -3018,14 +3018,10 @@ export type Mutation = {
updateWorkspaceMemberRole: WorkspaceMember;
updateWorkspaceMemberSettings: Scalars['Boolean']['output'];
upgradeApplication: Scalars['Boolean']['output'];
- uploadAiChatFile: FileWithSignedUrl;
uploadAppTarball: ApplicationRegistration;
uploadApplicationFile: File;
- uploadEmailAttachmentFile: FileWithSignedUrl;
- uploadFilesFieldFile: FileWithSignedUrl;
uploadFilesFieldFileByUniversalIdentifier: FileWithSignedUrl;
uploadNewWorkspaceLogo: FileWithSignedUrl;
- uploadWorkflowFile: FileWithSignedUrl;
uploadWorkspaceLogo: FileWithSignedUrl;
uploadWorkspaceMemberProfilePicture: FileWithSignedUrl;
upsertFieldPermissions: Array<FieldPermission>;
@@ -4178,11 +4174,6 @@ export type MutationUpgradeApplicationArgs = {
};
-export type MutationUploadAiChatFileArgs = {
- file: Scalars['Upload']['input'];
-};
-
-
export type MutationUploadAppTarballArgs = {
file: Scalars['Upload']['input'];
universalIdentifier?: InputMaybe<Scalars['String']['input']>;
@@ -4197,17 +4188,6 @@ export type MutationUploadApplicationFileArgs = {
};
-export type MutationUploadEmailAttachmentFileArgs = {
- file: Scalars['Upload']['input'];
-};
-
-
-export type MutationUploadFilesFieldFileArgs = {
- fieldMetadataId: Scalars['String']['input'];
- file: Scalars['Upload']['input'];
-};
-
-
export type MutationUploadFilesFieldFileByUniversalIdentifierArgs = {
fieldMetadataUniversalIdentifier: Scalars['String']['input'];
file: Scalars['Upload']['input'];
@@ -4220,11 +4200,6 @@ export type MutationUploadNewWorkspaceLogoArgs = {
};
-export type MutationUploadWorkflowFileArgs = {
- file: Scalars['Upload']['input'];
-};
-
-
export type MutationUploadWorkspaceLogoArgs = {
file: Scalars['Upload']['input'];
};
@@ -7410,13 +7385,6 @@ export type UpdateSkillMutationVariables = Exact<{
export type UpdateSkillMutation = { __typename?: 'Mutation', updateSkill: { __typename?: 'Skill', id: string, name: string, label: string, description?: string | null, icon?: string | null, content: string, isCustom: boolean, isActive: boolean, createdAt: string, updatedAt: string } };
-export type UploadAiChatFileMutationVariables = Exact<{
- file: Scalars['Upload']['input'];
-}>;
-
-
-export type UploadAiChatFileMutation = { __typename?: 'Mutation', uploadAiChatFile: { __typename?: 'FileWithSignedUrl', id: string, path: string, size: number, createdAt: string, url: string } };
-
export type FindManyAgentsQueryVariables = Exact<{ [key: string]: never; }>;
@@ -7969,28 +7937,6 @@ export type CreateFileUploadMutationVariables = Exact<{
export type CreateFileUploadMutation = { __typename?: 'Mutation', createFileUpload: { __typename?: 'FileUploadTarget', fileId: string, uploadUrl: string, contentType: string, expiresAt: string } };
-export type UploadEmailAttachmentFileMutationVariables = Exact<{
- file: Scalars['Upload']['input'];
-}>;
-
-
-export type UploadEmailAttachmentFileMutation = { __typename?: 'Mutation', uploadEmailAttachmentFile: { __typename?: 'FileWithSignedUrl', id: string, path: string, size: number, createdAt: string, url: string } };
-
-export type UploadFilesFieldFileMutationVariables = Exact<{
- file: Scalars['Upload']['input'];
- fieldMetadataId: Scalars['String']['input'];
-}>;
-
-
-export type UploadFilesFieldFileMutation = { __typename?: 'Mutation', uploadFilesFieldFile: { __typename?: 'FileWithSignedUrl', id: string, path: string, size: number, createdAt: string, url: string } };
-
-export type UploadWorkflowFileMutationVariables = Exact<{
- file: Scalars['Upload']['input'];
-}>;
-
-
-export type UploadWorkflowFileMutation = { __typename?: 'Mutation', uploadWorkflowFile: { __typename?: 'FileWithSignedUrl', id: string, path: string, size: number, createdAt: string, url: string } };
-
export type RenewApplicationTokenMutationVariables = Exact<{
applicationRefreshToken: Scalars['String']['input'];
}>;
@@ -9709,7 +9655,6 @@ export const StopAgentChatStreamDocument = {"kind":"Document","definitions":[{"k
export const UnarchiveChatThreadDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UnarchiveChatThread"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"unarchiveChatThread"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]}}]} as unknown as DocumentNode<UnarchiveChatThreadMutation, UnarchiveChatThreadMutationVariables>;
export const UpdateOneAgentDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateOneAgent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateAgentInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateOneAgent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AgentFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Agent"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"prompt"}},{"kind":"Field","name":{"kind":"Name","value":"modelId"}},{"kind":"Field","name":{"kind":"Name","value":"responseFormat"}},{"kind":"Field","name":{"kind":"Name","value":"roleId"}},{"kind":"Field","name":{"kind":"Name","value":"isCustom"}},{"kind":"Field","name":{"kind":"Name","value":"modelConfiguration"}},{"kind":"Field","name":{"kind":"Name","value":"evaluationInputs"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<UpdateOneAgentMutation, UpdateOneAgentMutationVariables>;
export const UpdateSkillDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateSkill"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateSkillInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateSkill"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SkillFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SkillFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Skill"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"isCustom"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<UpdateSkillMutation, UpdateSkillMutationVariables>;
-export const UploadAiChatFileDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"uploadAiChatFile"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"file"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Upload"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"uploadAiChatFile"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"file"},"value":{"kind":"Variable","name":{"kind":"Name","value":"file"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"path"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"url"}}]}}]}}]} as unknown as DocumentNode<UploadAiChatFileMutation, UploadAiChatFileMutationVariables>;
export const FindManyAgentsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindManyAgents"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"findManyAgents"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AgentFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Agent"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"prompt"}},{"kind":"Field","name":{"kind":"Name","value":"modelId"}},{"kind":"Field","name":{"kind":"Name","value":"responseFormat"}},{"kind":"Field","name":{"kind":"Name","value":"roleId"}},{"kind":"Field","name":{"kind":"Name","value":"isCustom"}},{"kind":"Field","name":{"kind":"Name","value":"modelConfiguration"}},{"kind":"Field","name":{"kind":"Name","value":"evaluationInputs"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<FindManyAgentsQuery, FindManyAgentsQueryVariables>;
export const FindManySkillsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindManySkills"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"skills"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SkillFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SkillFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Skill"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"isCustom"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<FindManySkillsQuery, FindManySkillsQueryVariables>;
export const FindOneAgentDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindOneAgent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"findOneAgent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AgentFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Agent"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"prompt"}},{"kind":"Field","name":{"kind":"Name","value":"modelId"}},{"kind":"Field","name":{"kind":"Name","value":"responseFormat"}},{"kind":"Field","name":{"kind":"Name","value":"roleId"}},{"kind":"Field","name":{"kind":"Name","value":"isCustom"}},{"kind":"Field","name":{"kind":"Name","value":"modelConfiguration"}},{"kind":"Field","name":{"kind":"Name","value":"evaluationInputs"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<FindOneAgentQuery, FindOneAgentQueryVariables>;
@@ -9768,9 +9713,6 @@ export const FindOnePageLayoutDocument = {"kind":"Document","definitions":[{"kin
export const FindOnePageLayoutTypeDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindOnePageLayoutType"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"getPageLayout"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"type"}}]}}]}}]} as unknown as DocumentNode<FindOnePageLayoutTypeQuery, FindOnePageLayoutTypeQueryVariables>;
export const CompleteFileUploadDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CompleteFileUpload"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"fileId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"completeFileUpload"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"fileId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"fileId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"path"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"url"}}]}}]}}]} as unknown as DocumentNode<CompleteFileUploadMutation, CompleteFileUploadMutationVariables>;
export const CreateFileUploadDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateFileUpload"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"filename"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"size"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"fileFolder"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"FileFolder"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"fieldMetadataId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createFileUpload"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filename"},"value":{"kind":"Variable","name":{"kind":"Name","value":"filename"}}},{"kind":"Argument","name":{"kind":"Name","value":"size"},"value":{"kind":"Variable","name":{"kind":"Name","value":"size"}}},{"kind":"Argument","name":{"kind":"Name","value":"fileFolder"},"value":{"kind":"Variable","name":{"kind":"Name","value":"fileFolder"}}},{"kind":"Argument","name":{"kind":"Name","value":"fieldMetadataId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"fieldMetadataId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"fileId"}},{"kind":"Field","name":{"kind":"Name","value":"uploadUrl"}},{"kind":"Field","name":{"kind":"Name","value":"contentType"}},{"kind":"Field","name":{"kind":"Name","value":"expiresAt"}}]}}]}}]} as unknown as DocumentNode<CreateFileUploadMutation, CreateFileUploadMutationVariables>;
-export const UploadEmailAttachmentFileDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UploadEmailAttachmentFile"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"file"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Upload"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"uploadEmailAttachmentFile"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"file"},"value":{"kind":"Variable","name":{"kind":"Name","value":"file"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"path"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"url"}}]}}]}}]} as unknown as DocumentNode<UploadEmailAttachmentFileMutation, UploadEmailAttachmentFileMutationVariables>;
-export const UploadFilesFieldFileDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UploadFilesFieldFile"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"file"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Upload"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"fieldMetadataId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"uploadFilesFieldFile"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"file"},"value":{"kind":"Variable","name":{"kind":"Name","value":"file"}}},{"kind":"Argument","name":{"kind":"Name","value":"fieldMetadataId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"fieldMetadataId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"path"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"url"}}]}}]}}]} as unknown as DocumentNode<UploadFilesFieldFileMutation, UploadFilesFieldFileMutationVariables>;
-export const UploadWorkflowFileDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UploadWorkflowFile"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"file"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Upload"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"uploadWorkflowFile"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"file"},"value":{"kind":"Variable","name":{"kind":"Name","value":"file"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"path"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"url"}}]}}]}}]} as unknown as DocumentNode<UploadWorkflowFileMutation, UploadWorkflowFileMutationVariables>;
export const RenewApplicationTokenDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"RenewApplicationToken"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"applicationRefreshToken"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"renewApplicationToken"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"applicationRefreshToken"},"value":{"kind":"Variable","name":{"kind":"Name","value":"applicationRefreshToken"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"applicationAccessToken"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"token"}},{"kind":"Field","name":{"kind":"Name","value":"expiresAt"}}]}},{"kind":"Field","name":{"kind":"Name","value":"applicationRefreshToken"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"token"}},{"kind":"Field","name":{"kind":"Name","value":"expiresAt"}}]}}]}}]}}]} as unknown as DocumentNode<RenewApplicationTokenMutation, RenewApplicationTokenMutationVariables>;
export const FindManyFrontComponentsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindManyFrontComponents"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"frontComponents"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"builtComponentChecksum"}},{"kind":"Field","name":{"kind":"Name","value":"builtComponentPath"}},{"kind":"Field","name":{"kind":"Name","value":"componentName"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"isHeadless"}},{"kind":"Field","name":{"kind":"Name","value":"sourceComponentPath"}},{"kind":"Field","name":{"kind":"Name","value":"universalIdentifier"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"usesSdkClient"}},{"kind":"Field","name":{"kind":"Name","value":"frontComponentSharedDependenciesChecksum"}}]}}]}}]} as unknown as DocumentNode<FindManyFrontComponentsQuery, FindManyFrontComponentsQueryVariables>;
export const FindOneFrontComponentDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindOneFrontComponent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"frontComponent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"builtComponentChecksum"}},{"kind":"Field","name":{"kind":"Name","value":"isHeadless"}},{"kind":"Field","name":{"kind":"Name","value":"usesSdkClient"}},{"kind":"Field","name":{"kind":"Name","value":"frontComponentSharedDependenciesChecksum"}},{"kind":"Field","name":{"kind":"Name","value":"applicationVariables"}},{"kind":"Field","name":{"kind":"Name","value":"applicationTokenPair"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"applicationAccessToken"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"token"}},{"kind":"Field","name":{"kind":"Name","value":"expiresAt"}}]}},{"kind":"Field","name":{"kind":"Name","value":"applicationRefreshToken"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"token"}},{"kind":"Field","name":{"kind":"Name","value":"expiresAt"}}]}}]}}]}}]}}]} as unknown as DocumentNode<FindOneFrontComponentQuery, FindOneFrontComponentQueryVariables>;
diff --git a/packages/twenty-front/src/modules/ai/graphql/mutations/uploadAiChatFile.ts b/packages/twenty-front/src/modules/ai/graphql/mutations/uploadAiChatFile.ts
deleted file mode 100644
index 6dc351e0031..00000000000
--- a/packages/twenty-front/src/modules/ai/graphql/mutations/uploadAiChatFile.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { gql } from '@apollo/client';
-
-export const UPLOAD_AI_CHAT_FILE = gql`
- mutation uploadAiChatFile($file: Upload!) {
- uploadAiChatFile(file: $file) {
- id
- path
- size
- createdAt
- url
- }
- }
-`;
diff --git a/packages/twenty-front/src/modules/file/graphql/mutations/uploadEmailAttachmentFile.ts b/packages/twenty-front/src/modules/file/graphql/mutations/uploadEmailAttachmentFile.ts
deleted file mode 100644
index f7e27a2617c..00000000000
--- a/packages/twenty-front/src/modules/file/graphql/mutations/uploadEmailAttachmentFile.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { gql } from '@apollo/client';
-
-export const UPLOAD_EMAIL_ATTACHMENT_FILE = gql`
- mutation UploadEmailAttachmentFile($file: Upload!) {
- uploadEmailAttachmentFile(file: $file) {
- id
- path
- size
- createdAt
- url
- }
- }
-`;
diff --git a/packages/twenty-front/src/modules/file/graphql/mutations/uploadFilesFieldFile.ts b/packages/twenty-front/src/modules/file/graphql/mutations/uploadFilesFieldFile.ts
deleted file mode 100644
index 22eeb6e08b8..00000000000
--- a/packages/twenty-front/src/modules/file/graphql/mutations/uploadFilesFieldFile.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { gql } from '@apollo/client';
-
-export const UPLOAD_FILES_FIELD_FILE = gql`
- mutation UploadFilesFieldFile($file: Upload!, $fieldMetadataId: String!) {
- uploadFilesFieldFile(file: $file, fieldMetadataId: $fieldMetadataId) {
- id
- path
- size
- createdAt
- url
- }
- }
-`;
diff --git a/packages/twenty-front/src/modules/file/graphql/mutations/uploadWorkflowFile.ts b/packages/twenty-front/src/modules/file/graphql/mutations/uploadWorkflowFile.ts
deleted file mode 100644
index c6e301edbf8..00000000000
--- a/packages/twenty-front/src/modules/file/graphql/mutations/uploadWorkflowFile.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { gql } from '@apollo/client';
-
-export const UPLOAD_WORKFLOW_FILE = gql`
- mutation UploadWorkflowFile($file: Upload!) {
- uploadWorkflowFile(file: $file) {
- id
- path
- size
- createdAt
- url
- }
- }
-`;
diff --git a/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordImageIdentifierUpload.ts b/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordImageIdentifierUpload.ts
index 468c0185a73..ff288f43e24 100644
--- a/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordImageIdentifierUpload.ts
+++ b/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordImageIdentifierUpload.ts
@@ -1,13 +1,10 @@
+import { useDirectFileUpload } from '@/file/hooks/useDirectFileUpload';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { getImageIdentifierFieldMetadataItem } from '@/object-metadata/utils/getImageIdentifierFieldMetadataItem';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { useIsRecordFieldReadOnly } from '@/object-record/read-only/hooks/useIsRecordFieldReadOnly';
-import { useApolloClient, useMutation } from '@apollo/client/react';
import { isDefined } from 'twenty-shared/utils';
-import {
- FieldMetadataType,
- UploadFilesFieldFileDocument,
-} from '~/generated-metadata/graphql';
+import { FieldMetadataType, FileFolder } from '~/generated-metadata/graphql';
type UseRecordImageIdentifierUploadParams = {
objectNameSingular: string;
@@ -18,10 +15,7 @@ export const useRecordImageIdentifierUpload = ({
objectNameSingular,
recordId,
}: UseRecordImageIdentifierUploadParams) => {
- const apolloClient = useApolloClient();
- const [uploadFilesFieldFile] = useMutation(UploadFilesFieldFileDocument, {
- client: apolloClient,
- });
+ const { uploadFile } = useDirectFileUpload();
const { updateOneRecord } = useUpdateOneRecord();
const { objectMetadataItem } = useObjectMetadataItem({ objectNameSingular });
@@ -49,19 +43,11 @@ export const useRecordImageIdentifierUpload = ({
return;
}
- const result = await uploadFilesFieldFile({
- variables: {
- file,
- fieldMetadataId: filesImageIdentifierFieldMetadataItem.id,
- },
+ const uploadedFile = await uploadFile(file, {
+ fileFolder: FileFolder.FilesField,
+ fieldMetadataId: filesImageIdentifierFieldMetadataItem.id,
});
- const uploadedFile = result?.data?.uploadFilesFieldFile;
-
- if (!isDefined(uploadedFile)) {
- return;
- }
-
await updateOneRecord({
objectNameSingular,
idToUpdate: recordId,
diff --git a/packages/twenty-server/src/engine/core-modules/file/file-ai-chat/file-ai-chat.module.ts b/packages/twenty-server/src/engine/core-modules/file/file-ai-chat/file-ai-chat.module.ts
deleted file mode 100644
index 82d68cfabc3..00000000000
--- a/packages/twenty-server/src/engine/core-modules/file/file-ai-chat/file-ai-chat.module.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { Module } from '@nestjs/common';
-
-import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
-import { FileAiChatResolver } from 'src/engine/core-modules/file/file-ai-chat/resolvers/file-ai-chat.resolver';
-import { FileAiChatService } from 'src/engine/core-modules/file/file-ai-chat/services/file-ai-chat.service';
-import { FileUrlModule } from 'src/engine/core-modules/file/file-url/file-url.module';
-import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permissions.module';
-
-@Module({
- imports: [FileUrlModule, ApplicationModule, PermissionsModule],
- providers: [FileAiChatService, FileAiChatResolver],
- exports: [FileAiChatService],
-})
-export class FileAiChatModule {}
diff --git a/packages/twenty-server/src/engine/core-modules/file/file-ai-chat/resolvers/file-ai-chat.resolver.ts b/packages/twenty-server/src/engine/core-modules/file/file-ai-chat/resolvers/file-ai-chat.resolver.ts
deleted file mode 100644
index a8a17ca2445..00000000000
--- a/packages/twenty-server/src/engine/core-modules/file/file-ai-chat/resolvers/file-ai-chat.resolver.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import { UseFilters, UseGuards, UsePipes } from '@nestjs/common';
-import { Args, Mutation } from '@nestjs/graphql';
-
-import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
-import { PermissionFlagType } from 'twenty-shared/constants';
-
-import type { FileUpload } from 'graphql-upload/processRequest.mjs';
-
-import { MetadataResolver } from 'src/engine/api/graphql/graphql-config/decorators/metadata-resolver.decorator';
-import { FileWithSignedUrlDTO } from 'src/engine/core-modules/file/dtos/file-with-sign-url.dto';
-import { FileAiChatService } from 'src/engine/core-modules/file/file-ai-chat/services/file-ai-chat.service';
-import { PreventNestToAutoLogGraphqlErrorsFilter } from 'src/engine/core-modules/graphql/filters/prevent-nest-to-auto-log-graphql-errors.filter';
-import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';
-import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
-import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
-import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
-import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
-import { streamToBuffer } from 'src/utils/stream-to-buffer';
-
-@UseGuards(WorkspaceAuthGuard)
-@UsePipes(ResolverValidationPipe)
-@UseFilters(PreventNestToAutoLogGraphqlErrorsFilter)
-@MetadataResolver()
-export class FileAiChatResolver {
- constructor(private readonly fileAiChatService: FileAiChatService) {}
-
- @Mutation(() => FileWithSignedUrlDTO)
- @UseGuards(SettingsPermissionGuard(PermissionFlagType.UPLOAD_FILE))
- async uploadAiChatFile(
- @AuthWorkspace()
- { id: workspaceId }: WorkspaceEntity,
- @Args({ name: 'file', type: () => GraphQLUpload })
- { createReadStream, filename }: FileUpload,
- ): Promise<FileWithSignedUrlDTO> {
- const stream = createReadStream();
- const buffer = await streamToBuffer(stream);
-
- return await this.fileAiChatService.uploadFile({
- file: buffer,
- filename,
- workspaceId,
- });
- }
-}
diff --git a/packages/twenty-server/src/engine/core-modules/file/file-ai-chat/services/file-ai-chat.service.ts b/packages/twenty-server/src/engine/core-modules/file/file-ai-chat/services/file-ai-chat.service.ts
deleted file mode 100644
index 9efa8c47ea5..00000000000
--- a/packages/twenty-server/src/engine/core-modules/file/file-ai-chat/services/file-ai-chat.service.ts
+++ /dev/null
@@ -1,68 +0,0 @@
-import { Injectable } from '@nestjs/common';
-
-import { isNonEmptyString } from '@sniptt/guards';
-import { FileFolder } from 'twenty-shared/types';
-import { v4 } from 'uuid';
-
-import { ApplicationService } from 'src/engine/core-modules/application/application.service';
-import { FileStorageService } from 'src/engine/core-modules/file-storage/services/file-storage.service';
-import { FileWithSignedUrlDTO } from 'src/engine/core-modules/file/dtos/file-with-sign-url.dto';
-import { FileUrlService } from 'src/engine/core-modules/file/file-url/file-url.service';
-import { extractFileInfoOrThrow } from 'src/engine/core-modules/file/utils/extract-file-info-or-throw.utils';
-
-@Injectable()
-export class FileAiChatService {
- constructor(
- private readonly fileStorageService: FileStorageService,
- private readonly applicationService: ApplicationService,
- private readonly fileUrlService: FileUrlService,
- ) {}
-
- async uploadFile({
- file,
- filename,
- workspaceId,
- }: {
- file: Buffer;
- filename: string;
- workspaceId: string;
- }): Promise<FileWithSignedUrlDTO> {
- const { ext } = await extractFileInfoOrThrow({
- file,
- filename,
- });
-
- const fileId = v4();
- const name = `${fileId}${isNonEmptyString(ext) ? `.${ext}` : ''}`;
-
- const { workspaceCustomFlatApplication } =
- await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(
- {
- workspaceId,
- },
- );
-
- const savedFile = await this.fileStorageService.writeFile({
- sourceFile: file,
- resourcePath: name,
- fileFolder: FileFolder.AgentChat,
- applicationUniversalIdentifier:
- workspaceCustomFlatApplication.universalIdentifier,
- workspaceId,
- fileId,
- settings: {
- isTemporaryFile: false,
- toDelete: false,
- },
- });
-
- return {
- ...savedFile,
- url: await this.fileUrlService.signFileByIdUrl({
- fileId,
- workspaceId,
- fileFolder: FileFolder.AgentChat,
- }),
- };
- }
-}
diff --git a/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/file-email-attachment.module.ts b/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/file-email-attachment.module.ts
index 76c7b9e936b..37b1f49a731 100644
--- a/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/file-email-attachment.module.ts
+++ b/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/file-email-attachment.module.ts
@@ -1,14 +1,9 @@
import { Module } from '@nestjs/common';
-import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
-import { FileEmailAttachmentResolver } from 'src/engine/core-modules/file/file-email-attachment/resolvers/file-email-attachment.resolver';
import { FileEmailAttachmentService } from 'src/engine/core-modules/file/file-email-attachment/services/file-email-attachment.service';
-import { FileUrlModule } from 'src/engine/core-modules/file/file-url/file-url.module';
-import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permissions.module';
@Module({
- imports: [FileUrlModule, ApplicationModule, PermissionsModule],
- providers: [FileEmailAttachmentService, FileEmailAttachmentResolver],
+ providers: [FileEmailAttachmentService],
exports: [FileEmailAttachmentService],
})
export class FileEmailAttachmentModule {}
diff --git a/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/resolvers/file-email-attachment.resolver.ts b/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/resolvers/file-email-attachment.resolver.ts
deleted file mode 100644
index 2bfa7ba322d..00000000000
--- a/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/resolvers/file-email-attachment.resolver.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-import { UseFilters, UseGuards, UsePipes } from '@nestjs/common';
-import { Args, Mutation } from '@nestjs/graphql';
-
-import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
-import { PermissionFlagType } from 'twenty-shared/constants';
-
-import type { FileUpload } from 'graphql-upload/processRequest.mjs';
-
-import { MetadataResolver } from 'src/engine/api/graphql/graphql-config/decorators/metadata-resolver.decorator';
-import { FileWithSignedUrlDTO } from 'src/engine/core-modules/file/dtos/file-with-sign-url.dto';
-import { FileEmailAttachmentService } from 'src/engine/core-modules/file/file-email-attachment/services/file-email-attachment.service';
-import { PreventNestToAutoLogGraphqlErrorsFilter } from 'src/engine/core-modules/graphql/filters/prevent-nest-to-auto-log-graphql-errors.filter';
-import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';
-import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
-import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
-import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
-import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
-import { streamToBuffer } from 'src/utils/stream-to-buffer';
-
-@UseGuards(WorkspaceAuthGuard)
-@UsePipes(ResolverValidationPipe)
-@UseFilters(PreventNestToAutoLogGraphqlErrorsFilter)
-@MetadataResolver()
-export class FileEmailAttachmentResolver {
- constructor(
- private readonly fileEmailAttachmentService: FileEmailAttachmentService,
- ) {}
-
- @Mutation(() => FileWithSignedUrlDTO)
- @UseGuards(SettingsPermissionGuard(PermissionFlagType.UPLOAD_FILE))
- async uploadEmailAttachmentFile(
- @AuthWorkspace()
- { id: workspaceId }: WorkspaceEntity,
- @Args({ name: 'file', type: () => GraphQLUpload })
- { createReadStream, filename }: FileUpload,
- ): Promise<FileWithSignedUrlDTO> {
- const stream = createReadStream();
- const buffer = await streamToBuffer(stream);
-
- return await this.fileEmailAttachmentService.uploadFile({
- file: buffer,
- filename,
- workspaceId,
- });
- }
-}
diff --git a/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/services/file-email-attachment.service.ts b/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/services/file-email-attachment.service.ts
index feaa869a87f..d3fa38fc54f 100644
--- a/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/services/file-email-attachment.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/file/file-email-attachment/services/file-email-attachment.service.ts
@@ -1,72 +1,14 @@
import { Injectable, Logger } from '@nestjs/common';
-import { isNonEmptyString } from '@sniptt/guards';
import { FileFolder } from 'twenty-shared/types';
-import { v4 } from 'uuid';
-import { ApplicationService } from 'src/engine/core-modules/application/application.service';
import { FileStorageService } from 'src/engine/core-modules/file-storage/services/file-storage.service';
-import { FileWithSignedUrlDTO } from 'src/engine/core-modules/file/dtos/file-with-sign-url.dto';
-import { FileUrlService } from 'src/engine/core-modules/file/file-url/file-url.service';
-import { extractFileInfoOrThrow } from 'src/engine/core-modules/file/utils/extract-file-info-or-throw.utils';
@Injectable()
export class FileEmailAttachmentService {
private readonly logger = new Logger(FileEmailAttachmentService.name);
- constructor(
- private readonly fileStorageService: FileStorageService,
- private readonly applicationService: ApplicationService,
- private readonly fileUrlService: FileUrlService,
- ) {}
-
- async uploadFile({
- file,
- filename,
- workspaceId,
- }: {
- file: Buffer;
- filename: string;
- workspaceId: string;
- }): Promise<FileWithSignedUrlDTO> {
- const { ext } = await extractFileInfoOrThrow({
- file,
- filename,
- });
-
- const fileId = v4();
- const name = `${fileId}${isNonEmptyString(ext) ? `.${ext}` : ''}`;
-
- const { workspaceCustomFlatApplication } =
- await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(
- {
- workspaceId,
- },
- );
-
- const savedFile = await this.fileStorageService.writeFile({
- sourceFile: file,
- resourcePath: name,
- fileFolder: FileFolder.EmailAttachment,
- applicationUniversalIdentifier:
- workspaceCustomFlatApplication.universalIdentifier,
- workspaceId,
- fileId,
- settings: {
- isTemporaryFile: true,
- toDelete: false,
- },
- });
-
- return {
- ...savedFile,
- url: await this.fileUrlService.signFileByIdUrl({
- fileId,
- workspaceId,
- fileFolder: FileFolder.EmailAttachment,
- }),
- };
- }
+ constructor(private readonly fileStorageService: FileStorageService) {}
async deleteFiles({
fileIds,
diff --git a/packages/twenty-server/src/engine/core-modules/file/file-workflow/file-workflow.module.ts b/packages/twenty-server/src/engine/core-modules/file/file-workflow/file-workflow.module.ts
deleted file mode 100644
index a3683e0a580..00000000000
--- a/packages/twenty-server/src/engine/core-modules/file/file-workflow/file-workflow.module.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { Module } from '@nestjs/common';
-
-import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
-import { FileUrlModule } from 'src/engine/core-modules/file/file-url/file-url.module';
-import { FileWorkflowResolver } from 'src/engine/core-modules/file/file-workflow/resolvers/file-workflow.resolver';
-import { FileWorkflowService } from 'src/engine/core-modules/file/file-workflow/services/file-workflow.service';
-import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permissions.module';
-
-@Module({
- imports: [FileUrlModule, ApplicationModule, PermissionsModule],
- providers: [FileWorkflowService, FileWorkflowResolver],
- exports: [FileWorkflowService],
-})
-export class FileWorkflowModule {}
diff --git a/packages/twenty-server/src/engine/core-modules/file/file-workflow/resolvers/file-workflow.resolver.ts b/packages/twenty-server/src/engine/core-modules/file/file-workflow/resolvers/file-workflow.resolver.ts
deleted file mode 100644
index d4e88ea66f0..00000000000
--- a/packages/twenty-server/src/engine/core-modules/file/file-workflow/resolvers/file-workflow.resolver.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import { UseFilters, UseGuards, UsePipes } from '@nestjs/common';
-import { Args, Mutation } from '@nestjs/graphql';
-
-import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
-import { PermissionFlagType } from 'twenty-shared/constants';
-
-import type { FileUpload } from 'graphql-upload/processRequest.mjs';
-
-import { MetadataResolver } from 'src/engine/api/graphql/graphql-config/decorators/metadata-resolver.decorator';
-import { FileWithSignedUrlDTO } from 'src/engine/core-modules/file/dtos/file-with-sign-url.dto';
-import { FileWorkflowService } from 'src/engine/core-modules/file/file-workflow/services/file-workflow.service';
-import { PreventNestToAutoLogGraphqlErrorsFilter } from 'src/engine/core-modules/graphql/filters/prevent-nest-to-auto-log-graphql-errors.filter';
-import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';
-import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
-import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
-import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
-import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
-import { streamToBuffer } from 'src/utils/stream-to-buffer';
-
-@UseGuards(WorkspaceAuthGuard)
-@UsePipes(ResolverValidationPipe)
-@UseFilters(PreventNestToAutoLogGraphqlErrorsFilter)
-@MetadataResolver()
-export class FileWorkflowResolver {
- constructor(private readonly fileWorkflowService: FileWorkflowService) {}
-
- @Mutation(() => FileWithSignedUrlDTO)
- @UseGuards(SettingsPermissionGuard(PermissionFlagType.UPLOAD_FILE))
- async uploadWorkflowFile(
- @AuthWorkspace()
- { id: workspaceId }: WorkspaceEntity,
- @Args({ name: 'file', type: () => GraphQLUpload })
- { createReadStream, filename }: FileUpload,
- ): Promise<FileWithSignedUrlDTO> {
- const stream = createReadStream();
- const buffer = await streamToBuffer(stream);
-
- return await this.fileWorkflowService.uploadFile({
- file: buffer,
- filename,
- workspaceId,
- });
- }
-}
diff --git a/packages/twenty-server/src/engine/core-modules/file/file-workflow/services/file-workflow.service.ts b/packages/twenty-server/src/engine/core-modules/file/file-workflow/services/file-workflow.service.ts
deleted file mode 100644
index 6ee7c2638d1..00000000000
--- a/packages/twenty-server/src/engine/core-modules/file/file-workflow/services/file-workflow.service.ts
+++ /dev/null
@@ -1,68 +0,0 @@
-import { Injectable } from '@nestjs/common';
-
-import { isNonEmptyString } from '@sniptt/guards';
-import { FileFolder } from 'twenty-shared/types';
-import { v4 } from 'uuid';
-
-import { ApplicationService } from 'src/engine/core-modules/application/application.service';
-import { FileStorageService } from 'src/engine/core-modules/file-storage/services/file-storage.service';
-import { FileWithSignedUrlDTO } from 'src/engine/core-modules/file/dtos/file-with-sign-url.dto';
-import { FileUrlService } from 'src/engine/core-modules/file/file-url/file-url.service';
-import { extractFileInfoOrThrow } from 'src/engine/core-modules/file/utils/extract-file-info-or-throw.utils';
-
-@Injectable()
-export class FileWorkflowService {
- constructor(
- private readonly fileStorageService: FileStorageService,
- private readonly applicationService: ApplicationService,
- private readonly fileUrlService: FileUrlService,
- ) {}
-
- async uploadFile({
- file,
- filename,
- workspaceId,
- }: {
- file: Buffer;
- filename: string;
- workspaceId: string;
- }): Promise<FileWithSignedUrlDTO> {
- const { ext } = await extractFileInfoOrThrow({
- file,
- filename,
- });
-
- const fileId = v4();
- const name = `${fileId}${isNonEmptyString(ext) ? `.${ext}` : ''}`;
-
- const { workspaceCustomFlatApplication } =
- await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(
- {
- workspaceId,
- },
- );
-
- const savedFile = await this.fileStorageService.writeFile({
- sourceFile: file,
- resourcePath: name,
- fileFolder: FileFolder.Workflow,
- applicationUniversalIdentifier:
- workspaceCustomFlatApplication.universalIdentifier,
- workspaceId,
- fileId,
- settings: {
- isTemporaryFile: true,
- toDelete: false,
- },
- });
-
- return {
- ...savedFile,
- url: await this.fileUrlService.signFileByIdUrl({
- fileId,
- workspaceId,
- fileFolder: FileFolder.Workflow,
- }),
- };
- }
-}
diff --git a/packages/twenty-server/src/engine/core-modules/file/file.module.ts b/packages/twenty-server/src/engine/core-modules/file/file.module.ts
index 3694e1b7d53..840fd69b22b 100644
--- a/packages/twenty-server/src/engine/core-modules/file/file.module.ts
+++ b/packages/twenty-server/src/engine/core-modules/file/file.module.ts
@@ -3,7 +3,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { ApplicationEntity } from 'src/engine/core-modules/application/application.entity';
import { FileStorageModule } from 'src/engine/core-modules/file-storage/file-storage.module';
-import { FileAiChatModule } from 'src/engine/core-modules/file/file-ai-chat/file-ai-chat.module';
import { FileDeletionJob } from 'src/engine/core-modules/file/jobs/file-deletion.job';
import { FileWorkspaceFolderDeletionJob } from 'src/engine/core-modules/file/jobs/file-workspace-folder-deletion.job';
import { JwtModule } from 'src/engine/core-modules/jwt/jwt.module';
@@ -17,7 +16,6 @@ import { FileCorePictureModule } from './file-core-picture/file-core-picture.mod
import { FileEmailAttachmentModule } from './file-email-attachment/file-email-attachment.module';
import { FileUploadModule } from './file-upload/file-upload.module';
import { FileUrlModule } from './file-url/file-url.module';
-import { FileWorkflowModule } from './file-workflow/file-workflow.module';
import { FilesFieldModule } from './files-field/files-field.module';
import { FileByIdGuard } from './guards/file-by-id.guard';
import { FileService } from './services/file.service';
@@ -31,8 +29,6 @@ import { FileService } from './services/file.service';
FileUrlModule,
FilesFieldModule,
FileCorePictureModule,
- FileWorkflowModule,
- FileAiChatModule,
FileEmailAttachmentModule,
FileUploadModule,
SecureHttpClientModule,
@@ -49,8 +45,6 @@ import { FileService } from './services/file.service';
FileUrlModule,
FilesFieldModule,
FileCorePictureModule,
- FileWorkflowModule,
- FileAiChatModule,
FileEmailAttachmentModule,
FileUploadModule,
],
diff --git a/packages/twenty-server/src/engine/core-modules/file/files-field/resolvers/files-field.resolver.ts b/packages/twenty-server/src/engine/core-modules/file/files-field/resolvers/files-field.resolver.ts
index 547d0d42b7a..b84fe779d22 100644
--- a/packages/twenty-server/src/engine/core-modules/file/files-field/resolvers/files-field.resolver.ts
+++ b/packages/twenty-server/src/engine/core-modules/file/files-field/resolvers/files-field.resolver.ts
@@ -24,31 +24,6 @@ import { streamToBuffer } from 'src/utils/stream-to-buffer';
export class FilesFieldResolver {
constructor(private readonly filesFieldService: FilesFieldService) {}
- @Mutation(() => FileWithSignedUrlDTO)
- @UseGuards(SettingsPermissionGuard(PermissionFlagType.UPLOAD_FILE))
- async uploadFilesFieldFile(
- @AuthWorkspace()
- { id: workspaceId }: WorkspaceEntity,
- @Args({ name: 'file', type: () => GraphQLUpload })
- { createReadStream, filename }: FileUpload,
- @Args({
- name: 'fieldMetadataId',
- type: () => String,
- nullable: false,
- })
- fieldMetadataId: string,
- ): Promise<FileWithSignedUrlDTO> {
- const stream = createReadStream();
- const buffer = await streamToBuffer(stream);
-
- return await this.filesFieldService.uploadFile({
- file: buffer,
- filename,
- workspaceId,
- fieldMetadataId,
- });
- }
-
@Mutation(() => FileWithSignedUrlDTO)
@UseGuards(SettingsPermissionGuard(PermissionFlagType.UPLOAD_FILE))
async uploadFilesFieldFileByUniversalIdentifier(
diff --git a/packages/twenty-server/test/integration/ai/suites/record-files-resolver.integration-spec.ts b/packages/twenty-server/test/integration/ai/suites/record-files-resolver.integration-spec.ts
index 2d1e56ba191..41aba3b252a 100644
--- a/packages/twenty-server/test/integration/ai/suites/record-files-resolver.integration-spec.ts
+++ b/packages/twenty-server/test/integration/ai/suites/record-files-resolver.integration-spec.ts
@@ -1,21 +1,11 @@
import { randomUUID } from 'node:crypto';
-import gql from 'graphql-tag';
import request from 'supertest';
-import { makeMetadataAPIRequestWithFileUpload } from 'test/integration/metadata/suites/utils/make-metadata-api-request-with-file-upload.util';
+import { uploadFileWithDirectUpload } from 'test/integration/graphql/utils/upload-file-with-direct-upload.util';
import { deleteRecordsByIds } from 'test/integration/utils/delete-records-by-ids';
const TEST_WORKSPACE_SCHEMA = 'workspace_1wgvd1injqtife6y4rvfbu3h5';
-const uploadAiChatFileMutation = gql`
- mutation UploadAiChatFile($file: Upload!) {
- uploadAiChatFile(file: $file) {
- id
- path
- }
- }
-`;
-
type McpToolCallResult = {
content?: Array<{ type: string; text: string }>;
isError?: boolean;
@@ -80,19 +70,15 @@ describe('agent chat files in record CRUD tools (integration)', () => {
beforeAll(async () => {
jest.useRealTimers();
- const response = await makeMetadataAPIRequestWithFileUpload(
- { query: uploadAiChatFileMutation, variables: { file: null } },
- {
- field: 'file',
- buffer: Buffer.from('%PDF-1.4 chat upload'),
- filename: 'chat-upload.pdf',
- contentType: 'application/pdf',
- },
- );
+ const uploadedFile = await uploadFileWithDirectUpload({
+ filename: 'chat-upload.pdf',
+ content: Buffer.from('%PDF-1.4 chat upload'),
+ fileFolder: 'AgentChat',
+ });
- chatFileId = response.body.data.uploadAiChatFile.id;
+ chatFileId = uploadedFile.id;
- expect(response.body.data.uploadAiChatFile.path).toContain('agent-chat/');
+ expect(uploadedFile.path).toContain('agent-chat/');
});
afterAll(async () => {
diff --git a/packages/twenty-server/test/integration/graphql/suites/files-field/files-field-download.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/files-field/files-field-download.integration-spec.ts
index fc8cc276551..1ddc5c11d03 100644
--- a/packages/twenty-server/test/integration/graphql/suites/files-field/files-field-download.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/files-field/files-field-download.integration-spec.ts
@@ -1,12 +1,11 @@
import gql from 'graphql-tag';
import request from 'supertest';
import { makeGraphqlAPIRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
-import { uploadFilesFieldFileMutation } from 'test/integration/graphql/utils/upload-files-field-file-mutation.util';
+import { uploadFileWithDirectUpload } from 'test/integration/graphql/utils/upload-file-with-direct-upload.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 { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';
-import { makeMetadataAPIRequestWithFileUpload } from 'test/integration/metadata/suites/utils/make-metadata-api-request-with-file-upload.util';
import { makeMetadataAPIRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';
import { FieldMetadataType } from 'twenty-shared/types';
@@ -67,23 +66,15 @@ describe('file-by-id.controller - GET /file/:fileFolder/:id', () => {
content: string,
contentType: string,
): Promise<UploadedFile> => {
- const response = await makeMetadataAPIRequestWithFileUpload(
- {
- query: uploadFilesFieldFileMutation,
- variables: { file: null, fieldMetadataId: createdFieldMetadataId },
- },
- {
- field: 'file',
- buffer: Buffer.from(content),
- filename,
- contentType,
- },
- );
-
- expect(response.body.errors).toBeUndefined();
+ const uploadedFile = await uploadFileWithDirectUpload({
+ filename,
+ content: Buffer.from(content),
+ fileFolder: 'FilesField',
+ fieldMetadataId: createdFieldMetadataId,
+ });
return {
- id: response.body.data.uploadFilesFieldFile.id,
+ id: uploadedFile.id,
contentType,
content,
};
diff --git a/packages/twenty-server/test/integration/graphql/suites/files-field/files-field-sync.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/files-field/files-field-sync.integration-spec.ts
index 2bc02410bfb..afc47c38a6c 100644
--- a/packages/twenty-server/test/integration/graphql/suites/files-field/files-field-sync.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/files-field/files-field-sync.integration-spec.ts
@@ -1,11 +1,10 @@
import gql from 'graphql-tag';
import { makeGraphqlAPIRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
-import { uploadFilesFieldFileMutation } from 'test/integration/graphql/utils/upload-files-field-file-mutation.util';
+import { uploadFileWithDirectUpload } from 'test/integration/graphql/utils/upload-file-with-direct-upload.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 { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';
-import { makeMetadataAPIRequestWithFileUpload } from 'test/integration/metadata/suites/utils/make-metadata-api-request-with-file-upload.util';
import { makeMetadataAPIRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';
import { FieldMetadataType } from 'twenty-shared/types';
@@ -83,23 +82,15 @@ describe('fileFieldSync - FILES field <> files sync', () => {
content: string,
contentType: string,
): Promise<UploadedFile> => {
- const response = await makeMetadataAPIRequestWithFileUpload(
- {
- query: uploadFilesFieldFileMutation,
- variables: { file: null, fieldMetadataId: createdFieldMetadataId },
- },
- {
- field: 'file',
- buffer: Buffer.from(content),
- filename,
- contentType,
- },
- );
-
- expect(response.body.errors).toBeUndefined();
+ const uploadedFile = await uploadFileWithDirectUpload({
+ filename,
+ content: Buffer.from(content),
+ fileFolder: 'FilesField',
+ fieldMetadataId: createdFieldMetadataId,
+ });
return {
- id: response.body.data.uploadFilesFieldFile.id,
+ id: uploadedFile.id,
contentType,
};
};
diff --git a/packages/twenty-server/test/integration/graphql/suites/files-field/upload-files-field-file.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/files-field/upload-files-field-file.integration-spec.ts
deleted file mode 100644
index a5e83c30ee4..00000000000
--- a/packages/twenty-server/test/integration/graphql/suites/files-field/upload-files-field-file.integration-spec.ts
+++ /dev/null
@@ -1,145 +0,0 @@
-import gql from 'graphql-tag';
-import { uploadFilesFieldFileMutation } from 'test/integration/graphql/utils/upload-files-field-file-mutation.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 { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';
-import { makeMetadataAPIRequestWithFileUpload } from 'test/integration/metadata/suites/utils/make-metadata-api-request-with-file-upload.util';
-import { makeMetadataAPIRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';
-import { FieldMetadataType, FileFolder } from 'twenty-shared/types';
-
-const deleteFileMutation = gql`
- mutation DeleteFile($fileId: UUID!) {
- deleteFile(fileId: $fileId) {
- id
- }
- }
-`;
-
-describe('uploadFilesFieldFile', () => {
- let createdObjectMetadataId: string;
- let createdFieldMetadataId: string;
- let uploadedFileId: string | null = null;
-
- const getFieldMetadataUniversalIdentifier = async (
- fieldMetadataId: string,
- ): Promise<string> => {
- const result = await global.testDataSource.query(
- 'SELECT "universalIdentifier" FROM core."fieldMetadata" WHERE id = $1',
- [fieldMetadataId],
- );
-
- return result[0].universalIdentifier;
- };
-
- beforeAll(async () => {
- jest.useRealTimers();
-
- const {
- data: {
- createOneObject: { id: objectMetadataId },
- },
- } = await createOneObjectMetadata({
- input: {
- nameSingular: 'uploadTestObject',
- namePlural: 'uploadTestObjects',
- labelSingular: 'Upload Test Object',
- labelPlural: 'Upload Test Objects',
- icon: 'IconFile',
- },
- });
-
- createdObjectMetadataId = objectMetadataId;
-
- const {
- data: {
- createOneField: { id: fieldMetadataId },
- },
- } = await createOneFieldMetadata({
- input: {
- name: 'filesField',
- label: 'Files Field',
- type: FieldMetadataType.FILES,
- objectMetadataId: createdObjectMetadataId,
- settings: { maxNumberOfValues: 5 },
- },
- gqlFields: `
- id
- name
- label
- type
- `,
- });
-
- createdFieldMetadataId = fieldMetadataId;
- });
-
- afterAll(async () => {
- if (uploadedFileId) {
- await makeMetadataAPIRequest({
- query: deleteFileMutation,
- variables: { fileId: uploadedFileId },
- });
- }
-
- await updateOneObjectMetadata({
- expectToFail: false,
- input: {
- idToUpdate: createdObjectMetadataId,
- updatePayload: {
- isActive: false,
- },
- },
- });
- await deleteOneObjectMetadata({
- input: { idToDelete: createdObjectMetadataId },
- });
-
- jest.useFakeTimers();
- });
-
- it('should upload a file and return file metadata', async () => {
- const testFileContent = 'Hello, this is a test file content';
- const testFileName = 'test-file.txt';
- const testMimeType = 'text/plain';
-
- const response = await makeMetadataAPIRequestWithFileUpload(
- {
- query: uploadFilesFieldFileMutation,
- variables: {
- file: null,
- fieldMetadataId: createdFieldMetadataId,
- },
- },
- {
- field: 'file',
- buffer: Buffer.from(testFileContent),
- filename: testFileName,
- contentType: testMimeType,
- },
- );
-
- expect(response.status).toBe(200);
- expect(response.body.errors).toBeUndefined();
- expect(response.body.data).toBeDefined();
-
- const fileResult = response.body.data.uploadFilesFieldFile;
-
- expect(fileResult).toBeDefined();
- expect(fileResult.id).toBeDefined();
- expect(typeof fileResult.id).toBe('string');
- expect(fileResult.path).toBeDefined();
- expect(typeof fileResult.path).toBe('string');
- expect(fileResult.path).toContain(FileFolder.FilesField);
-
- const fieldUniversalIdentifier = await getFieldMetadataUniversalIdentifier(
- createdFieldMetadataId,
- );
-
- expect(fileResult.path).toContain(fieldUniversalIdentifier);
- expect(fileResult.size).toBe(testFileContent.length);
- expect(fileResult.createdAt).toBeDefined();
-
- uploadedFileId = fileResult.id;
- });
-});
diff --git a/packages/twenty-server/test/integration/graphql/suites/inputs-validation/utils/setup-test-objects-with-all-field-types.util.ts b/packages/twenty-server/test/integration/graphql/suites/inputs-validation/utils/setup-test-objects-with-all-field-types.util.ts
index e5ef3e5935f..669525241df 100644
--- a/packages/twenty-server/test/integration/graphql/suites/inputs-validation/utils/setup-test-objects-with-all-field-types.util.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/inputs-validation/utils/setup-test-objects-with-all-field-types.util.ts
@@ -1,10 +1,9 @@
import { getFieldMetadataCreationInputs } from 'test/integration/graphql/suites/inputs-validation/utils/get-field-metadata-creation-inputs.util';
import { createManyOperationFactory } from 'test/integration/graphql/utils/create-many-operation-factory.util';
import { makeGraphqlAPIRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
-import { uploadFilesFieldFileMutation } from 'test/integration/graphql/utils/upload-files-field-file-mutation.util';
+import { uploadFileWithDirectUpload } from 'test/integration/graphql/utils/upload-file-with-direct-upload.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 { makeMetadataAPIRequestWithFileUpload } from 'test/integration/metadata/suites/utils/make-metadata-api-request-with-file-upload.util';
import { FieldMetadataType, RelationType } from 'twenty-shared/types';
import { v4 } from 'uuid';
@@ -116,26 +115,16 @@ export const setupTestObjectsWithAllFieldTypes = async (
throw new Error('FILES field metadata was not created');
}
- const testFileContent = 'Test document content';
- const testFileName = 'Document.txt';
- const testMimeType = 'text/plain';
-
- const uploadResponse = await makeMetadataAPIRequestWithFileUpload(
- {
- query: uploadFilesFieldFileMutation,
- variables: { file: null, fieldMetadataId: filesFieldMetadataId },
- },
- {
- field: 'file',
- buffer: Buffer.from(testFileContent),
- filename: testFileName,
- contentType: testMimeType,
- },
- );
+ const uploadedFile = await uploadFileWithDirectUpload({
+ filename: 'Document.txt',
+ content: Buffer.from('Test document content'),
+ fileFolder: 'FilesField',
+ fieldMetadataId: filesFieldMetadataId,
+ });
jest.useFakeTimers();
- uploadedFileId = uploadResponse.body.data.uploadFilesFieldFile.id;
+ uploadedFileId = uploadedFile.id;
}
await makeGraphqlAPIRequest(
diff --git a/packages/twenty-server/test/integration/graphql/utils/upload-file-with-direct-upload.util.ts b/packages/twenty-server/test/integration/graphql/utils/upload-file-with-direct-upload.util.ts
new file mode 100644
index 00000000000..9f0a044b193
--- /dev/null
+++ b/packages/twenty-server/test/integration/graphql/utils/upload-file-with-direct-upload.util.ts
@@ -0,0 +1,93 @@
+import gql from 'graphql-tag';
+import request from 'supertest';
+import { makeMetadataAPIRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';
+import { FileFolder } from 'twenty-shared/types';
+
+const createFileUploadMutation = gql`
+ mutation CreateFileUpload(
+ $filename: String!
+ $size: Float!
+ $fileFolder: FileFolder!
+ $fieldMetadataId: String
+ ) {
+ createFileUpload(
+ filename: $filename
+ size: $size
+ fileFolder: $fileFolder
+ fieldMetadataId: $fieldMetadataId
+ ) {
+ fileId
+ uploadUrl
+ contentType
+ }
+ }
+`;
+
+const completeFileUploadMutation = gql`
+ mutation CompleteFileUpload($fileId: String!) {
+ completeFileUpload(fileId: $fileId) {
+ id
+ path
+ size
+ createdAt
+ url
+ }
+ }
+`;
+
+type UploadFileWithDirectUploadArgs = {
+ filename: string;
+ content: Buffer;
+ fileFolder: keyof typeof FileFolder;
+ fieldMetadataId?: string;
+};
+
+type DirectUploadedFile = {
+ id: string;
+ path: string;
+ size: number;
+ createdAt: string;
+ url: string;
+};
+
+export const uploadFileWithDirectUpload = async ({
+ filename,
+ content,
+ fileFolder,
+ fieldMetadataId,
+}: UploadFileWithDirectUploadArgs): Promise<DirectUploadedFile> => {
+ const createResponse = await makeMetadataAPIRequest({
+ query: createFileUploadMutation,
+ variables: {
+ filename,
+ size: content.length,
+ fileFolder,
+ fieldMetadataId,
+ },
+ });
+
+ expect(createResponse.body.errors).toBeUndefined();
+
+ const { fileId, uploadUrl, contentType } =
+ createResponse.body.data.createFileUpload;
+
+ // Integration tests run on the local storage driver, so the upload url
+ // targets the server's streaming endpoint: replay it against the test app.
+ const { pathname, search } = new URL(uploadUrl);
+
+ const putResponse = await request(global.app.getHttpServer())
+ .put(`${pathname}${search}`)
+ .set('Content-Type', contentType)
+ .send(content);
+
+ expect(putResponse.status).toBe(204);
+
+ const completeResponse = await makeMetadataAPIRequest({
+ query: completeFileUploadMutation,
+ variables: { fileId },
+ });
+
+ expect(completeResponse.body.errors).toBeUndefined();
+
+ return completeResponse.body.data.completeFileUpload;
+};
diff --git a/packages/twenty-server/test/integration/graphql/utils/upload-files-field-file-mutation.util.ts b/packages/twenty-server/test/integration/graphql/utils/upload-files-field-file-mutation.util.ts
deleted file mode 100644
index 6ee1e02c27c..00000000000
--- a/packages/twenty-server/test/integration/graphql/utils/upload-files-field-file-mutation.util.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import gql from 'graphql-tag';
-
-export const uploadFilesFieldFileMutation = gql`
- mutation UploadFilesFieldFile($file: Upload!, $fieldMetadataId: String!) {
- uploadFilesFieldFile(file: $file, fieldMetadataId: $fieldMetadataId) {
- id
- path
- size
- createdAt
- }
- }
-`;