-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Document createRemoteFileNode #4302
Comments
@m-allanson Thanks for providing all the references to look into and get to know about it. Referring to the example usage, I was able to understand what it does and where it can be used, but then how is this data later queried in GraphQL and used in the react components and so on? |
Downloaded files are created as File nodes so you can query them e.g. via |
@KyleAMathews Okay that makes sense. |
@ajayns As @KyleAMathews mentioned - plugin first creates You can definitely skip this intermediate wrapper object if you don't need it or this is just not how you handle files/attachments/images in source of your data. If you have data like this: const data = {
title: "foobar",
picture: "http://placehold.it/600/24f355"
} You can do: if (data.picture) {
const remoteFileNode = createRemoteFileNode({
url: data.picture,
store,
cache,
createNode,
})
if (remoteFileNode) {
// gatsby convention - add `___NODE` to name of the field to let gatsby know
// that we reference node here (important part is to assign `id` of node and not entire node).
// `___NODE` part will be removed leaving just `picture` as field name with `File` type
data.picture___NODE = remoteFileNode.id
}
// we need to delete original url string as this would cause ambiguity as both
// `picture___NODE` and `picture` would construct same field. Alternatively you can
// name your linked field with other name - that will work too
data.picture___NODE
} |
@pieh I didn't quite understand that. Let's take the case of soucre-drupal which seems to bit more clearer to understand. There, remote nodes are created for all files and then this seems to be done: if (fileNode) {
node.localFile___NODE = fileNode.id
} Is |
no - it adds You can name it however you like - apart from few required fields ( |
@pieh Okay that makes sense! Thank you! |
@m-allanson This issue can be closed now yeah? |
@ajayns yes it can, thanks for your work on this! |
The docs for
gatsby-source-filesystem
'screateRemoteFileNode
are the word TODO. We should write up some documentation so it's DONE.It's implemented here.
And there are example usages in:
Refs #3132
The text was updated successfully, but these errors were encountered: