Repository: gatsbyjs/gatsby
File: packages/gatsby-plugin-mdx/gatsby/source-nodes.js (JavaScript)

Code before:
      rawBody: { type: `String!` },
      fileAbsolutePath: { type: `String!` },
      frontmatter: { type: `MdxFrontmatter` },
      slug: {
        type: `String`,
        async resolve(mdxNode, args, context) {
          try {
            const nodeWithContext = context.nodeModel.findRootNodeAncestor(
              mdxNode,
              node => node.internal && node.internal.type === `File`
            )
            const fileRelativePath = nodeWithContext.relativePath

            const parsedPath = path.parse(fileRelativePath)

            let relevantPath
            if (parsedPath.name === `index`) {
              relevantPath = fileRelativePath.replace(parsedPath.base, ``)
            } else {
              relevantPath = fileRelativePath.replace(parsedPath.ext, ``)
            }
            return slugify(relevantPath, {
              remove: /[^\w\s$*_+~.()'"!\-:@/]/g,
            })
          } catch {
            reporter.warn(`gatsby-plugin-mdx: Your MDX files are not sourced from your local file system.
            \nAs a result there will be no slug available.`)
            return null
          }
        },
      },
      body: {
        type: `String!`,
        async resolve(mdxNode) {
          const { body } = await processMDX({ node: mdxNode })
          return body
        },
      },
      excerpt: {
        type: `String!`,
        args: {
          pruneLength: {
            type: `Int`,
            defaultValue: 140,
          },
          truncate: {
            type: GraphQLBoolean,
            defaultValue: false,
          },
        },
        async resolve(mdxNode, { pruneLength, truncate }) {

Review comment (suggestion):
Wondering if we should warn here since there are valid reasons for a file node not being associated (like a remote source).

Also, if the node isn't associated with a file maybe we should shortcircuit rather than depending on a `try`/`catch`? Will be more explicit to short circuit IMO.

```js
const nodeWithContext = context.nodeModel.findRootNodeAncestor(
  mdxNode,
  node => node.internal && node.internal.type === `File`
)

if (!nodeWithContext) {
  return null
}
```

Code after:
      rawBody: { type: `String!` },
      fileAbsolutePath: { type: `String!` },
      frontmatter: { type: `MdxFrontmatter` },
      slug: {
        type: `String`,
        async resolve(mdxNode, args, context) {
          const nodeWithContext = context.nodeModel.findRootNodeAncestor(
            mdxNode,
            node => node.internal && node.internal.type === `File`
          )

          if (!nodeWithContext) {
            return null
          }
          const fileRelativePath = nodeWithContext.relativePath

          const parsedPath = path.parse(fileRelativePath)

          let relevantPath
          if (parsedPath.name === `index`) {
            relevantPath = fileRelativePath.replace(parsedPath.base, ``)
          } else {
            relevantPath = fileRelativePath.replace(parsedPath.ext, ``)
          }
          return slugify(relevantPath, {
            remove: /[^\w\s$*_+~.()'"!\-:@/]/g, // this is the set of allowable characters
          })
        },
      },
      body: {
        type: `String!`,
        async resolve(mdxNode) {
          const { body } = await processMDX({ node: mdxNode })
          return body
        },
      },
      excerpt: {
        type: `String!`,
        args: {
          pruneLength: {
            type: `Int`,
            defaultValue: 140,
          },
          truncate: {
            type: GraphQLBoolean,
            defaultValue: false,
          },
        },
        async resolve(mdxNode, { pruneLength, truncate }) {
          if (mdxNode.excerpt) {
            return Promise.resolve(mdxNode.excerpt)