-
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
Using @link with a union type #24290
Comments
Contentful uses foreign key reference mechanism. Which means that the raw node data looks like this: {
id: `whatever`,
featuredMedia___NODE: `someFileId`,
// ...other node fields
} So what happens when you write the following type definition? type ContentfulHomePage implements Node {
featuredMedia: [MediaGroup] @link
} It searches for Try this: type ContentfulHomePage implements Node {
featuredMedia: [MediaGroup] @link(from: "featuredMedia___NODE")
} This is mentioned in the schema customization docs:
I hope it helps! 🤞 |
That does indeed fix my issue, thank you so much! I never would have figured that out from the docs though to be honest. Several questions I still have that aren't very clear from the docs that contribute to this:
As a note, I had read the source of type ContentfulHomePage implements Node {
featuredMedia___NODE: [MediaGroup]
} Which of course just left me with a Again, thanks so much for your help, was exactly what I needed! |
Hey @thekevinbrown We are going to update/improve documentation related to GraphQL in the near future so your feedback is very valuable, thank you! I'll label this issue as documentation and we'll get back to it when working on updated GraphQL docs. Thanks for using Gatsby 💜 |
It is documented now in this tutorial: https://www.gatsbyjs.com/tutorial/source-plugin-tutorial/#create-foreign-key-relationships-between-data So closing this issue. Thanks for reporting! 💜 |
Summary
Relevant information
We're using contentful to host our content. On our home page we have a single field called
featuredMedia
that can hold Articles, Reports, and Videos.When I allow gatsby-source-contentful to infer the content types we get the ability to do this:
Which is exactly what we want. However, then the user goes and removes all of the ArticleResources from Contentful and our query breaks.
No worries, off to
createSchemaCustomisation
!:This starts successfully, but then the same query as above returns
null
. I can tell I need@link
somewhere so I can get a resolver for the relationship, but I can't for the life of me figure out how to get@link
to work with the union. I tried this:and this
and this
None work. How do I get this to work? I'd be happy to supply a resolver function, but I also cannot for the life of me find the default one to base a new one off of.
It's clear Gatsby has this built in and I just need to activate that behaviour again, but I can't figure out how, particularly with unions, as all the examples I find just keep showing me how to relate one type to precisely one other type.
#21852 would really help here I think.
Environment (if relevant)
Not relevant.
File contents (if changed)
(I can provide these if needed, but I think mostly it's noise. It'd be easier for me to create a reproduction I think if needed.)
The text was updated successfully, but these errors were encountered: