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

File path infer problem #13267

Closed
suziwen opened this issue Apr 10, 2019 · 4 comments · Fixed by #13289
Closed

File path infer problem #13267

suziwen opened this issue Apr 10, 2019 · 4 comments · Fixed by #13289

Comments

@suziwen
Copy link

suziwen commented Apr 10, 2019

Assuming I have three node

A = {
internal: {type: "File"},
children: [B],
parent: null,
absolutePath: '/home/test/a'
}

B = {
internal: {type: "File"},
children: [C],
parent: A
absolutePath: '/home/test/b'
}
C = {
internal: {type: "Custom"}
children: [],
parent: B,
cover: './featured.png'
}

I hope C's property (cover) will be inferred to /home/test/b/featured.png, but not /home/test/a/featured.png.

Is it possible get the /home/test/b/featured.png cover?
or
have any custom condition function to stop find root node?

@stefanprobst
Copy link
Contributor

Could you provide a small reproduction repo to investigate? This would be very helpful, thanks!

@sidharthachatterjee sidharthachatterjee added the status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. label Apr 10, 2019
@suziwen
Copy link
Author

suziwen commented Apr 11, 2019

Reproduction link: https://github.com/suziwen/gatsby-file-path-infer-problem


{
  allCustomJson{
    edges{
      node{
        id
        parent{
          id
        }
        cover{
          absolutePath
        }
      }
    }
  }
  allFile{
    edges{
      node{
        id
        children{
          id
        }
        absolutePath
        parent{
          id
        }
      }
    }
  }
}

image

@stefanprobst stefanprobst removed the status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. label Apr 11, 2019
@stefanprobst
Copy link
Contributor

Thanks for the reproduction, this should be fixed with #13289

pieh pushed a commit that referenced this issue Apr 11, 2019
In the `fileByPath` resolver, we need a node's parent `File` node to resolve relative to absolute paths. For this we use `findRootNodeAncestor`, which will return a node's root node. This can be problematic for (unusual) scenarios like in #13267 where a node has more than one `File` node ancestor. We should just use the closest `File` parent.

Fixes #13267
@pieh
Copy link
Contributor

pieh commented Apr 11, 2019

Published gatsby@2.3.19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants