refactor: update rest-gql import-export sync
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
mutation CreateGQLChildUserCollection(
|
||||
$title: String!
|
||||
$parentUserCollectionID: ID!
|
||||
$data: String
|
||||
) {
|
||||
createGQLChildUserCollection(
|
||||
title: $title
|
||||
parentUserCollectionID: $parentUserCollectionID
|
||||
data: $data
|
||||
) {
|
||||
id
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
mutation CreateGQLRootUserCollection($title: String!) {
|
||||
createGQLRootUserCollection(title: $title) {
|
||||
mutation CreateGQLRootUserCollection($title: String!, $data: String) {
|
||||
createGQLRootUserCollection(title: $title, data: $data) {
|
||||
id
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
mutation CreateRESTChildUserCollection(
|
||||
$title: String!
|
||||
$parentUserCollectionID: ID!
|
||||
$data: String
|
||||
) {
|
||||
createRESTChildUserCollection(
|
||||
title: $title
|
||||
parentUserCollectionID: $parentUserCollectionID
|
||||
data: $data
|
||||
) {
|
||||
id
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
mutation CreateRESTRootUserCollection($title: String!) {
|
||||
createRESTRootUserCollection(title: $title) {
|
||||
mutation CreateRESTRootUserCollection($title: String!, $data: String) {
|
||||
createRESTRootUserCollection(title: $title, data: $data) {
|
||||
id
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ query GetGQLRootUserCollections {
|
||||
id
|
||||
title
|
||||
type
|
||||
data
|
||||
childrenGQL {
|
||||
id
|
||||
title
|
||||
type
|
||||
data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,22 +70,24 @@ import {
|
||||
UpdateUserCollectionDocument,
|
||||
} from "../../api/generated/graphql"
|
||||
|
||||
export const createRESTRootUserCollection = (title: string) =>
|
||||
export const createRESTRootUserCollection = (title: string, data?: string) =>
|
||||
runMutation<
|
||||
CreateRestRootUserCollectionMutation,
|
||||
CreateRestRootUserCollectionMutationVariables,
|
||||
""
|
||||
>(CreateRestRootUserCollectionDocument, {
|
||||
title,
|
||||
data,
|
||||
})()
|
||||
|
||||
export const createGQLRootUserCollection = (title: string) =>
|
||||
export const createGQLRootUserCollection = (title: string, data?: string) =>
|
||||
runMutation<
|
||||
CreateGqlRootUserCollectionMutation,
|
||||
CreateGqlRootUserCollectionMutationVariables,
|
||||
""
|
||||
>(CreateGqlRootUserCollectionDocument, {
|
||||
title,
|
||||
data,
|
||||
})()
|
||||
|
||||
export const createRESTUserRequest = (
|
||||
@@ -120,7 +122,8 @@ export const createGQLUserRequest = (
|
||||
|
||||
export const createRESTChildUserCollection = (
|
||||
title: string,
|
||||
parentUserCollectionID: string
|
||||
parentUserCollectionID: string,
|
||||
data?: string
|
||||
) =>
|
||||
runMutation<
|
||||
CreateRestChildUserCollectionMutation,
|
||||
@@ -129,11 +132,13 @@ export const createRESTChildUserCollection = (
|
||||
>(CreateRestChildUserCollectionDocument, {
|
||||
title,
|
||||
parentUserCollectionID,
|
||||
data,
|
||||
})()
|
||||
|
||||
export const createGQLChildUserCollection = (
|
||||
title: string,
|
||||
parentUserCollectionID: string
|
||||
parentUserCollectionID: string,
|
||||
data?: string
|
||||
) =>
|
||||
runMutation<
|
||||
CreateGqlChildUserCollectionMutation,
|
||||
@@ -142,6 +147,7 @@ export const createGQLChildUserCollection = (
|
||||
>(CreateGqlChildUserCollectionDocument, {
|
||||
title,
|
||||
parentUserCollectionID,
|
||||
data,
|
||||
})()
|
||||
|
||||
export const deleteUserCollection = (userCollectionID: string) =>
|
||||
|
||||
@@ -47,27 +47,69 @@ const recursivelySyncCollections = async (
|
||||
|
||||
// if parentUserCollectionID does not exist, create the collection as a root collection
|
||||
if (!parentUserCollectionID) {
|
||||
const res = await createRESTRootUserCollection(collection.name)
|
||||
|
||||
const data = {
|
||||
auth: collection.auth ?? {
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
},
|
||||
headers: collection.headers ?? [],
|
||||
}
|
||||
const res = await createRESTRootUserCollection(
|
||||
collection.name,
|
||||
JSON.stringify(data)
|
||||
)
|
||||
if (E.isRight(res)) {
|
||||
parentCollectionID = res.right.createRESTRootUserCollection.id
|
||||
|
||||
const returnedData = res.right.createRESTRootUserCollection.data
|
||||
? JSON.parse(res.right.createRESTRootUserCollection.data)
|
||||
: {
|
||||
auth: {
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
},
|
||||
headers: [],
|
||||
}
|
||||
|
||||
collection.id = parentCollectionID
|
||||
collection.auth = returnedData.auth
|
||||
collection.headers = returnedData.headers
|
||||
removeDuplicateRESTCollectionOrFolder(parentCollectionID, collectionPath)
|
||||
} else {
|
||||
parentCollectionID = undefined
|
||||
}
|
||||
} else {
|
||||
// if parentUserCollectionID exists, create the collection as a child collection
|
||||
const data = {
|
||||
auth: collection.auth ?? {
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
},
|
||||
headers: collection.headers ?? [],
|
||||
}
|
||||
|
||||
const res = await createRESTChildUserCollection(
|
||||
collection.name,
|
||||
parentUserCollectionID
|
||||
parentUserCollectionID,
|
||||
JSON.stringify(data)
|
||||
)
|
||||
|
||||
if (E.isRight(res)) {
|
||||
const childCollectionId = res.right.createRESTChildUserCollection.id
|
||||
|
||||
const returnedData = res.right.createRESTChildUserCollection.data
|
||||
? JSON.parse(res.right.createRESTChildUserCollection.data)
|
||||
: {
|
||||
auth: {
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
},
|
||||
headers: [],
|
||||
}
|
||||
|
||||
collection.id = childCollectionId
|
||||
collection.auth = returnedData.auth
|
||||
collection.headers = returnedData.headers
|
||||
|
||||
removeDuplicateRESTCollectionOrFolder(
|
||||
childCollectionId,
|
||||
|
||||
@@ -44,12 +44,35 @@ const recursivelySyncCollections = async (
|
||||
|
||||
// if parentUserCollectionID does not exist, create the collection as a root collection
|
||||
if (!parentUserCollectionID) {
|
||||
const res = await createGQLRootUserCollection(collection.name)
|
||||
const data = {
|
||||
auth: collection.auth ?? {
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
},
|
||||
headers: collection.headers ?? [],
|
||||
}
|
||||
const res = await createGQLRootUserCollection(
|
||||
collection.name,
|
||||
JSON.stringify(data)
|
||||
)
|
||||
|
||||
if (E.isRight(res)) {
|
||||
parentCollectionID = res.right.createGQLRootUserCollection.id
|
||||
|
||||
const returnedData = res.right.createGQLRootUserCollection.data
|
||||
? JSON.parse(res.right.createGQLRootUserCollection.data)
|
||||
: {
|
||||
auth: {
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
},
|
||||
headers: [],
|
||||
}
|
||||
|
||||
collection.id = parentCollectionID
|
||||
collection.auth = returnedData.auth
|
||||
collection.headers = returnedData.headers
|
||||
|
||||
removeDuplicateGraphqlCollectionOrFolder(
|
||||
parentCollectionID,
|
||||
collectionPath
|
||||
@@ -59,15 +82,37 @@ const recursivelySyncCollections = async (
|
||||
}
|
||||
} else {
|
||||
// if parentUserCollectionID exists, create the collection as a child collection
|
||||
|
||||
const data = {
|
||||
auth: collection.auth ?? {
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
},
|
||||
headers: collection.headers ?? [],
|
||||
}
|
||||
|
||||
const res = await createGQLChildUserCollection(
|
||||
collection.name,
|
||||
parentUserCollectionID
|
||||
parentUserCollectionID,
|
||||
JSON.stringify(data)
|
||||
)
|
||||
|
||||
if (E.isRight(res)) {
|
||||
const childCollectionId = res.right.createGQLChildUserCollection.id
|
||||
|
||||
const returnedData = res.right.createGQLChildUserCollection.data
|
||||
? JSON.parse(res.right.createGQLChildUserCollection.data)
|
||||
: {
|
||||
auth: {
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
},
|
||||
headers: [],
|
||||
}
|
||||
|
||||
collection.id = childCollectionId
|
||||
collection.auth = returnedData.auth
|
||||
collection.headers = returnedData.headers
|
||||
|
||||
removeDuplicateGraphqlCollectionOrFolder(
|
||||
childCollectionId,
|
||||
|
||||
Reference in New Issue
Block a user