jessestuart/gatsby-source-s3-image

View on GitHub
src/on-create-node.ts

Summary

Maintainability
A
0 mins
Test Coverage
import _ from 'lodash'
import fp from 'lodash/fp'

const onCreateNode = ({ node, actions, getNode }) => {
  const { createParentChildLink } = actions
  const type = _.get(node, 'internal.type')

  if (type === 'S3ImageAsset') {
    const parent = getNode(node.parent)
    const imageSharp = getNode(
      _.flow(
        fp.get('children'),
        fp.first
      )(parent)
    )
    createParentChildLink({ parent: node, child: imageSharp })
  }
}

export default onCreateNode