diff --git a/packages/hoppscotch-selfhost-web/src/api/mutations/UpdateUserCollection.graphql b/packages/hoppscotch-selfhost-web/src/api/mutations/UpdateUserCollection.graphql new file mode 100644 index 000000000..c5e89d22c --- /dev/null +++ b/packages/hoppscotch-selfhost-web/src/api/mutations/UpdateUserCollection.graphql @@ -0,0 +1,15 @@ +mutation UpdateUserCollection( + $userCollectionID: ID! + $newTitle: String + $data: String +) { + updateUserCollection( + userCollectionID: $userCollectionID + newTitle: $newTitle + data: $data + ) { + id + title + data + } +} diff --git a/packages/hoppscotch-selfhost-web/src/api/queries/GetUserRootCollections.graphql b/packages/hoppscotch-selfhost-web/src/api/queries/GetUserRootCollections.graphql index 0b6842339..9d72c1ffe 100644 --- a/packages/hoppscotch-selfhost-web/src/api/queries/GetUserRootCollections.graphql +++ b/packages/hoppscotch-selfhost-web/src/api/queries/GetUserRootCollections.graphql @@ -4,10 +4,12 @@ query GetUserRootCollections { id title type + data childrenREST { id title type + data } } } diff --git a/packages/hoppscotch-selfhost-web/src/api/subscriptions/UserCollectionCreated.graphql b/packages/hoppscotch-selfhost-web/src/api/subscriptions/UserCollectionCreated.graphql index 99870281c..1accfec11 100644 --- a/packages/hoppscotch-selfhost-web/src/api/subscriptions/UserCollectionCreated.graphql +++ b/packages/hoppscotch-selfhost-web/src/api/subscriptions/UserCollectionCreated.graphql @@ -6,5 +6,6 @@ subscription UserCollectionCreated { id title type + data } } diff --git a/packages/hoppscotch-selfhost-web/src/api/subscriptions/UserCollectionUpdated.graphql b/packages/hoppscotch-selfhost-web/src/api/subscriptions/UserCollectionUpdated.graphql index 3fd8487d0..8b52b69f7 100644 --- a/packages/hoppscotch-selfhost-web/src/api/subscriptions/UserCollectionUpdated.graphql +++ b/packages/hoppscotch-selfhost-web/src/api/subscriptions/UserCollectionUpdated.graphql @@ -3,6 +3,7 @@ subscription userCollectionUpdated { id title type + data parent { id } diff --git a/packages/hoppscotch-selfhost-web/src/platform/collections/collections.api.ts b/packages/hoppscotch-selfhost-web/src/platform/collections/collections.api.ts index 2373d7d06..3faecbda7 100644 --- a/packages/hoppscotch-selfhost-web/src/platform/collections/collections.api.ts +++ b/packages/hoppscotch-selfhost-web/src/platform/collections/collections.api.ts @@ -65,6 +65,9 @@ import { GetGqlRootUserCollectionsQueryVariables, GetGqlRootUserCollectionsDocument, ReqType, + UpdateUserCollectionMutation, + UpdateUserCollectionMutationVariables, + UpdateUserCollectionDocument, } from "../../api/generated/graphql" export const createRESTRootUserCollection = (title: string) => @@ -160,6 +163,17 @@ export const renameUserCollection = ( "" >(RenameUserCollectionDocument, { userCollectionID, newTitle })() +export const updateUserCollection = ( + userCollectionID: string, + newTitle?: string, + data?: string +) => + runMutation< + UpdateUserCollectionMutation, + UpdateUserCollectionMutationVariables, + "" + >(UpdateUserCollectionDocument, { userCollectionID, newTitle, data })() + export const moveUserCollection = ( sourceCollectionID: string, destinationCollectionID?: string diff --git a/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts b/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts index 0572eabcf..dcb028c87 100644 --- a/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts +++ b/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts @@ -89,8 +89,7 @@ type ExportedUserCollectionREST = { folders: ExportedUserCollectionREST[] requests: Array name: string - auth: HoppRESTRequest["auth"] - headers: HoppRESTRequest["headers"] + data: string } type ExportedUserCollectionGQL = { @@ -98,8 +97,7 @@ type ExportedUserCollectionGQL = { folders: ExportedUserCollectionGQL[] requests: Array name: string - auth: HoppGQLRequest["auth"] - headers: HoppGQLRequest["headers"] + data: string } function exportedCollectionToHoppCollection( @@ -108,6 +106,8 @@ function exportedCollectionToHoppCollection( ): HoppCollection { if (collectionType == "REST") { const restCollection = collection as ExportedUserCollectionREST + const data = restCollection.data ? JSON.parse(restCollection.data) : null + return { id: restCollection.id, v: 1, @@ -142,11 +142,12 @@ function exportedCollectionToHoppCollection( testScript, }) ), - auth: restCollection.auth, - headers: restCollection.headers, + auth: data.auth ?? { authType: "inherit", authActive: false }, + headers: data.headers ?? [], } } else { const gqlCollection = collection as ExportedUserCollectionGQL + const data = gqlCollection.data ? JSON.parse(gqlCollection.data) : null return { id: gqlCollection.id, @@ -164,8 +165,8 @@ function exportedCollectionToHoppCollection( name, }) ) as HoppGQLRequest[], - auth: gqlCollection.auth, - headers: gqlCollection.headers, + auth: data.auth, + headers: data.headers, } } } @@ -297,6 +298,9 @@ function setupUserCollectionCreatedSubscription() { }) } else { // root collections won't have parentCollectionID + const data = res.right.userCollectionCreated.data + ? JSON.parse(res.right.userCollectionCreated.data) + : null runDispatchWithOutSyncing(() => { collectionType == "GQL" ? addGraphqlCollection({ @@ -304,22 +308,19 @@ function setupUserCollectionCreatedSubscription() { folders: [], requests: [], v: 1, - auth: { - authType: "none", - authActive: false, - }, - headers: [], + auth: data?.auth ?? { authType: "inherit", authActive: false }, + headers: data?.headers ?? [], }) : addRESTCollection({ name: res.right.userCollectionCreated.title, folders: [], requests: [], v: 1, - auth: { - authType: "none", + auth: data?.auth ?? { + authType: "inherit", authActive: false, }, - headers: [], + headers: data?.headers ?? [], }) const localIndex = collectionStore.value.state.length - 1 diff --git a/packages/hoppscotch-selfhost-web/src/platform/collections/collections.sync.ts b/packages/hoppscotch-selfhost-web/src/platform/collections/collections.sync.ts index 218cb2251..f4fab70f4 100644 --- a/packages/hoppscotch-selfhost-web/src/platform/collections/collections.sync.ts +++ b/packages/hoppscotch-selfhost-web/src/platform/collections/collections.sync.ts @@ -24,7 +24,7 @@ import { editUserRequest, moveUserCollection, moveUserRequest, - renameUserCollection, + updateUserCollection, updateUserCollectionOrder, } from "./collections.api" @@ -155,8 +155,13 @@ export const storeSyncDefinition: StoreSyncDefinitionOf< [collectionIndex] )?.id - if (collectionID && collection.name) { - renameUserCollection(collectionID, collection.name) + const data = { + auth: collection.auth, + headers: collection.headers, + } + + if (collectionID) { + updateUserCollection(collectionID, collection.name, JSON.stringify(data)) } }, async addFolder({ name, path }) { @@ -195,9 +200,12 @@ export const storeSyncDefinition: StoreSyncDefinitionOf< )?.id const folderName = folder.name - - if (folderID && folderName) { - renameUserCollection(folderID, folderName) + const data = { + auth: folder.auth, + headers: folder.headers, + } + if (folderID) { + updateUserCollection(folderID, folderName, JSON.stringify(data)) } }, async removeFolder({ folderID }) {