How to use openneuro-client - 10 common examples

To help you get started, we’ve selected a few openneuro-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OpenNeuroOrg / openneuro / packages / openneuro-cli / src / upload.js View on Github external
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 {
github OpenNeuroOrg / openneuro / packages / openneuro-cli / src / datasets.js View on Github external
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
    })
}
github OpenNeuroOrg / openneuro / packages / openneuro-app / src / scripts / dataset / dataset.dataset-loader.jsx View on Github external
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))
github OpenNeuroOrg / openneuro / packages / openneuro-app / src / scripts / uploader / uploader.jsx View on Github external
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 })
github OpenNeuroOrg / openneuro / packages / openneuro-app / src / scripts / uploader / upload-mutation.js View on Github external
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',
  })
}
github OpenNeuroOrg / openneuro / packages / openneuro-app / src / scripts / uploader / upload-mutation.js View on Github external
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',
  })
}
github OpenNeuroOrg / openneuro / packages / openneuro-app / src / scripts / utils / datalad.js View on Github external
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)
github OpenNeuroOrg / openneuro / packages / openneuro-app / src / scripts / utils / datalad.js View on Github external
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)
github OpenNeuroOrg / openneuro / packages / openneuro-app / src / scripts / utils / datalad.js View on Github external
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)
        })
github OpenNeuroOrg / openneuro / packages / openneuro-app / src / scripts / utils / datalad.js View on Github external
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)