Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-transformer-remark] File nodes in arrays/lists issue #2286

Closed
Seavenly opened this issue Sep 30, 2017 · 5 comments
Closed

[gatsby-transformer-remark] File nodes in arrays/lists issue #2286

Seavenly opened this issue Sep 30, 2017 · 5 comments
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@Seavenly
Copy link
Contributor

Seavenly commented Sep 30, 2017

I recently discovered Gatsby and have been attempting to transition my personal website over to it. My current site architecture uses markdown files with frontmatter use, and Gatsby seems like the easiest way to utilize Markdown data with React as the view layer. In some of my markdown files however, I have lists/arrays with image file references to them. Image file references work fine when not in a list. @amirhouieh posted (#950) a few days ago with the same issue it seems.

Here is my query:

query ModularQuery {
  allMarkdownRemark(filter: { fileAbsolutePath: { regex: "/home\/_tools/" } }) {
    edges {
      node {
        frontmatter {
          modular {
            tools {
              logo {
                id
              }
            }
          }
        }
      }
    }
  }
}

Here is the output (I modified GraphQL to show the stack trace):

{
  "errors": [
    {
      "message": "Path must be a string. Received undefined",
      "locations": [
        {
          "line": 8,
          "column": 15
        }
      ],
      "path": [
        "allMarkdownRemark",
        "edges",
        0,
        "node",
        "frontmatter",
        "modular",
        "tools",
        0,
        "logo"
      ],
      "stack": "TypeError: Path must be a string. Received undefined\n    at assertPath (path.js:7:11)\n    at Object.resolve (path.js:1153:7)\n    at resolve (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/gatsby/dist/schema/infer-graphql-type.js:418:49)\n    at resolveFieldValueOrError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:501:12)\n    at resolveField (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:465:16)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:314:18\n    at Array.reduce (native)\n    at executeFields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:311:42)\n    at collectAndExecuteSubfields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:749:10)\n    at completeObjectValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:731:10)\n    at completeValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:628:12)\n    at completeValueWithLocatedError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:546:21)\n    at completeValueCatchingError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:521:21)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:651:25\n    at Array.forEach (native)\n    at forEach (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/iterall/index.js:336:25)"
    },
    {
      "message": "Path must be a string. Received undefined",
      "locations": [
        {
          "line": 8,
          "column": 15
        }
      ],
      "path": [
        "allMarkdownRemark",
        "edges",
        0,
        "node",
        "frontmatter",
        "modular",
        "tools",
        1,
        "logo"
      ],
      "stack": "TypeError: Path must be a string. Received undefined\n    at assertPath (path.js:7:11)\n    at Object.resolve (path.js:1153:7)\n    at resolve (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/gatsby/dist/schema/infer-graphql-type.js:418:49)\n    at resolveFieldValueOrError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:501:12)\n    at resolveField (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:465:16)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:314:18\n    at Array.reduce (native)\n    at executeFields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:311:42)\n    at collectAndExecuteSubfields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:749:10)\n    at completeObjectValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:731:10)\n    at completeValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:628:12)\n    at completeValueWithLocatedError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:546:21)\n    at completeValueCatchingError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:521:21)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:651:25\n    at Array.forEach (native)\n    at forEach (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/iterall/index.js:336:25)"
    },
    {
      "message": "Path must be a string. Received undefined",
      "locations": [
        {
          "line": 8,
          "column": 15
        }
      ],
      "path": [
        "allMarkdownRemark",
        "edges",
        0,
        "node",
        "frontmatter",
        "modular",
        "tools",
        2,
        "logo"
      ],
      "stack": "TypeError: Path must be a string. Received undefined\n    at assertPath (path.js:7:11)\n    at Object.resolve (path.js:1153:7)\n    at resolve (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/gatsby/dist/schema/infer-graphql-type.js:418:49)\n    at resolveFieldValueOrError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:501:12)\n    at resolveField (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:465:16)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:314:18\n    at Array.reduce (native)\n    at executeFields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:311:42)\n    at collectAndExecuteSubfields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:749:10)\n    at completeObjectValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:731:10)\n    at completeValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:628:12)\n    at completeValueWithLocatedError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:546:21)\n    at completeValueCatchingError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:521:21)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:651:25\n    at Array.forEach (native)\n    at forEach (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/iterall/index.js:336:25)"
    },
    {
      "message": "Path must be a string. Received undefined",
      "locations": [
        {
          "line": 8,
          "column": 15
        }
      ],
      "path": [
        "allMarkdownRemark",
        "edges",
        0,
        "node",
        "frontmatter",
        "modular",
        "tools",
        3,
        "logo"
      ],
      "stack": "TypeError: Path must be a string. Received undefined\n    at assertPath (path.js:7:11)\n    at Object.resolve (path.js:1153:7)\n    at resolve (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/gatsby/dist/schema/infer-graphql-type.js:418:49)\n    at resolveFieldValueOrError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:501:12)\n    at resolveField (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:465:16)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:314:18\n    at Array.reduce (native)\n    at executeFields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:311:42)\n    at collectAndExecuteSubfields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:749:10)\n    at completeObjectValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:731:10)\n    at completeValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:628:12)\n    at completeValueWithLocatedError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:546:21)\n    at completeValueCatchingError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:521:21)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:651:25\n    at Array.forEach (native)\n    at forEach (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/iterall/index.js:336:25)"
    },
    {
      "message": "Path must be a string. Received undefined",
      "locations": [
        {
          "line": 8,
          "column": 15
        }
      ],
      "path": [
        "allMarkdownRemark",
        "edges",
        0,
        "node",
        "frontmatter",
        "modular",
        "tools",
        4,
        "logo"
      ],
      "stack": "TypeError: Path must be a string. Received undefined\n    at assertPath (path.js:7:11)\n    at Object.resolve (path.js:1153:7)\n    at resolve (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/gatsby/dist/schema/infer-graphql-type.js:418:49)\n    at resolveFieldValueOrError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:501:12)\n    at resolveField (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:465:16)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:314:18\n    at Array.reduce (native)\n    at executeFields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:311:42)\n    at collectAndExecuteSubfields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:749:10)\n    at completeObjectValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:731:10)\n    at completeValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:628:12)\n    at completeValueWithLocatedError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:546:21)\n    at completeValueCatchingError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:521:21)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:651:25\n    at Array.forEach (native)\n    at forEach (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/iterall/index.js:336:25)"
    },
    {
      "message": "Path must be a string. Received undefined",
      "locations": [
        {
          "line": 8,
          "column": 15
        }
      ],
      "path": [
        "allMarkdownRemark",
        "edges",
        0,
        "node",
        "frontmatter",
        "modular",
        "tools",
        5,
        "logo"
      ],
      "stack": "TypeError: Path must be a string. Received undefined\n    at assertPath (path.js:7:11)\n    at Object.resolve (path.js:1153:7)\n    at resolve (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/gatsby/dist/schema/infer-graphql-type.js:418:49)\n    at resolveFieldValueOrError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:501:12)\n    at resolveField (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:465:16)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:314:18\n    at Array.reduce (native)\n    at executeFields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:311:42)\n    at collectAndExecuteSubfields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:749:10)\n    at completeObjectValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:731:10)\n    at completeValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:628:12)\n    at completeValueWithLocatedError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:546:21)\n    at completeValueCatchingError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:521:21)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:651:25\n    at Array.forEach (native)\n    at forEach (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/iterall/index.js:336:25)"
    },
    {
      "message": "Path must be a string. Received undefined",
      "locations": [
        {
          "line": 8,
          "column": 15
        }
      ],
      "path": [
        "allMarkdownRemark",
        "edges",
        0,
        "node",
        "frontmatter",
        "modular",
        "tools",
        6,
        "logo"
      ],
      "stack": "TypeError: Path must be a string. Received undefined\n    at assertPath (path.js:7:11)\n    at Object.resolve (path.js:1153:7)\n    at resolve (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/gatsby/dist/schema/infer-graphql-type.js:418:49)\n    at resolveFieldValueOrError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:501:12)\n    at resolveField (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:465:16)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:314:18\n    at Array.reduce (native)\n    at executeFields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:311:42)\n    at collectAndExecuteSubfields (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:749:10)\n    at completeObjectValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:731:10)\n    at completeValue (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:628:12)\n    at completeValueWithLocatedError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:546:21)\n    at completeValueCatchingError (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:521:21)\n    at /mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/graphql/execution/execute.js:651:25\n    at Array.forEach (native)\n    at forEach (/mnt/c/Users/nscho/dev/wsl/projects/sandbox/gatsby-dev-site/node_modules/iterall/index.js:336:25)"
    }
  ],
  "data": {
    "allMarkdownRemark": {
      "edges": [
        {
          "node": {
            "frontmatter": {
              "modular": {
                "tools": [
                  {
                    "logo": null
                  },
                  {
                    "logo": null
                  },
                  {
                    "logo": null
                  },
                  {
                    "logo": null
                  },
                  {
                    "logo": null
                  },
                  {
                    "logo": null
                  },
                  {
                    "logo": null
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

I've poked around in the Gatsby code a bit to try and find the issue, but have been having a little trouble with the inner workings. The issue arises around line 480 in infer-graphql-type.js. The nodes inside of the array do not have a parent file node so the parent directory path resolves to undefined which is throwing the error. I'm not too sure where to look from there though.

@KyleAMathews
Copy link
Contributor

Could you create a small site reproducing this issue that I could play with? I think I can fix it fairly easily as I dealt with it the other day. Probably though all that needs done is making this fix I did the other night recursive https://github.com/gatsbyjs/gatsby/pull/2255/files#diff-37476cc0992c8d09852786ba4d4037ffR56

@Seavenly
Copy link
Contributor Author

Here's a zip file with the isolated files that should reproduce the issue.
gatsby-dev-site.zip

Here is the query I've been using to test grabbing the data in GraphiQL:

query ModularQuery {
  allMarkdownRemark(filter: {fileAbsolutePath: {regex: "/home/_tools/"}}) {
    edges {
      node {
        frontmatter {
          thumb {
            name
            absolutePath
          }
          modular {
            tools {
              name
              logo {
                name
                absolutePath
              }
            }
          }
        }
      }
    }
  }
}
@KyleAMathews
Copy link
Contributor

Could you push this to a working site in a GitHub repo that I can clone and install and start working on right away?

@Seavenly
Copy link
Contributor Author

Yea, sorry, that would be easiest. Here's my site repo with the source files in the source branch.

@sebastienfi sebastienfi changed the title File nodes in arrays/lists issue Oct 1, 2017
@sebastienfi sebastienfi added API/Plugins type: bug An issue or pull request relating to a bug in Gatsby labels Oct 1, 2017
@brycebigger
Copy link

Having the exact same issue- single files are fine, but when you add subobjects in markdown, something goes sideways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
4 participants