How to use the contentful-graph.getContentTypesFromManagementApi function in contentful-graph

To help you get started, we’ve selected a few contentful-graph 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 lotas / contentful-graph-web / src / render-handler.js View on Github external
const renderHandler = async (req, res) => {
  const { spaceId, dlvrToken, mgmtToken, devMode = false, hideFields = false } = req.body

  if (!spaceId) {
    return res.json({ error: 'Missing spaceId' })
  }
  if (!dlvrToken && !mgmtToken) {
    return res.json({ error: 'Missing auth token' })
  }

  let contentTypes

  try {
    contentTypes = mgmtToken
      ? await convertApi.getContentTypesFromManagementApi(spaceId, mgmtToken)
      : await convertApi.getContentTypesFromDistributionApi(spaceId, dlvrToken)
  } catch (err) {
    return res.json({ error: err })
  }

  const modelsMap = convertApi.contentTypesToModelMap(contentTypes);
  const dotStr = convertApi.modelsMapToDot(modelsMap, {dev: devMode, hideEntityFields: hideFields});

  const fileName = `${spaceId}-${Date.now()}`

  if (dotStr && dotStr.length > 1) {
    // wait for the png
    await generateGraph(outFile(fileName, 'png'), dotStr, 'png')

    // but those are fine to be finished later
    setImmediate(() => generateGraph(outFile(fileName, 'svg'), dotStr, 'svg'))

contentful-graph

[![Build Status](https://travis-ci.org/lotas/contentful-graph.svg?branch=master)](https://travis-ci.org/lotas/contentful-graph) [![npm version](https://badge.fury.io/js/contentful-graph.svg)](https://badge.fury.io/js/contentful-graph)

MIT
Latest version published 4 years ago

Package Health Score

39 / 100
Full package analysis