Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const uploadTree = (client, datasetId) => tree => {
return client
.mutate({
mutation: files.updateFiles,
variables: { datasetId, files: tree },
})
.catch(err => {
// Since the error response content type does not match the request
// we need some special error handling any requests with Upload scalars
if (
err.hasOwnProperty('networkError') &&
err.networkError &&
err.networkError.hasOwnProperty('result')
) {
for (const message of err.networkError.result.errors) {
// eslint-disable-next-line no-console
console.error(inspect(message))
}
process.exit(1)
} else {
export const createDataset = (client, dir) => {
const label = path.basename(dir)
return client
.mutate({
mutation: datasets.createDataset,
variables: { label },
})
.then(({ data }) => {
const dsId = data.createDataset.id
// eslint-disable-next-line no-console
console.log(`"${dsId}" created with label "${label}"`)
return dsId
})
}
const newestSnapshot = snapshots[0].tag
// Trim trailing slash if needed
const currentPath = this.props.location.pathname.replace(/\/$/, '')
const newestSnapshotUrl = `${currentPath}/versions/${newestSnapshot}`
return (
)
} else {
return null
}
}
}
export default graphql(datasets.getDataset, {
name: 'getDataset',
options: props => ({
variables: {
id: bids.decodeId(props.match.params.datasetId),
},
}),
})(withRouter(DatasetLoader))
upload() {
this.setState({
uploading: true,
location: locationFactory('/hidden'),
})
// This is an upload specific apollo client to record progress
// Uses XHR since Fetch does not provide the required interface
const uploadClient = getClient(
`${config.url}/crn/graphql`,
null,
xhrFetch(this),
)
if (this.state.resume) {
// Diff and add files
} else {
let client = this.props.client
// Create dataset and then add files
mutation
.createDataset(client)(this.state.name)
.then(datasetId => {
mutation
.updateFiles(uploadClient)(datasetId, this.state.files)
.then(() => {
this.setState({ datasetId })
export const updateFiles = client => (datasetId, fileList) => {
const tree = treeFromList(fileList)
// Upload dataset_description.json first
tree.files = files.sortFiles(tree.files)
return client.mutate({
mutation: files.updateFiles,
variables: { datasetId, files: tree },
errorPolicy: 'all',
})
}
export const updateFiles = client => (datasetId, fileList) => {
const tree = treeFromList(fileList)
// Upload dataset_description.json first
tree.files = files.sortFiles(tree.files)
return client.mutate({
mutation: files.updateFiles,
variables: { datasetId, files: tree },
errorPolicy: 'all',
})
}
queryDataset(datasetId, callback) {
console.log('datasetId in graphql query:', bids.decodeId(datasetId))
const query = datasets.getDataset
client.query({
query: query,
variables: {
id: bids.decodeId(datasetId)
}
})
.then(data => {
data = clone(data)
let snapshots = data.data.dataset.snapshots.slice(0)
for (let snapshot of snapshots) {
let splitId = snapshot.id.split(':')
snapshot._id = splitId[splitId.length -1]
snapshot.original = splitId[0]
}
data.data.dataset.files = data.data.dataset.draft ? data.data.dataset.draft.files : []
return callback(data)
updateFiles(datasetId, fileTree, options) {
let mutation = files.updateFiles
return new Promise((resolve, reject) => {
client.mutate({
mutation: mutation,
variables: {
datasetId: bids.decodeId(datasetId),
files: fileTree
}
})
.then(data => {
console.log('response from updateFiles:', data)
resolve(data)
})
.catch(err => {
console.log(err)
reject(err)
updatePublic(datasetId, publicFlag) {
console.log('calling updatePublic mutation with id:', datasetId, 'and publicFlag:', publicFlag)
const mutation = datasets.updatePublic
return new Promise((resolve, reject) => {
client.mutate({
mutation: mutation,
variables: {
id: bids.decodeId(datasetId),
publicFlag: publicFlag
}
})
.then(data => {
console.log('response from updatePublic:', data)
resolve(data)
})
.catch(err => {
console.log(err)
reject(err)
})
deleteFiles(datasetId, fileTree, options) {
let mutation = files.deleteFiles
return new Promise((resolve, reject) => {
client.mutate({
mutation: mutation,
variables: {
datasetId: bids.decodeId(datasetId),
files: fileTree
}
})
.then(data => {
console.log('response from deleteFiles:', data)
resolve(data)
})
.catch(err => {
console.log(err)
reject(err)