[gatsby-plugin-contentful] How to access fields from other spaces? #38345
Replies: 2 comments
-
Hi @mihaisavezi I've been battling with this too, and needed to create a schema customization to achieve it. Firstly, I'm assuming you have a second instance of In my case I have a content type exports.createSchemaCustomization = ({ actions, schema }) => {
const { createTypes } = actions
const typeDefs = [
schema.buildObjectType({
name: "ContentfulEntryLinkContentExternal",
fields: {
reference: { // Add a new field called "reference"
type: "ContentfulPressRelease", // the type of data I am resolving to
resolve: (source, args, context, info) => {
return context.nodeModel.findOne({
type: "ContentfulPressRelease",
query: {
filter: { contentful_id: { eq: source.sys.urn.slice(-22) } } // Slice the last 22 chars of the URN to get the contentful_id
}
})
},
},
},
}),
]
createTypes(typeDefs)
} Find more reading on the Customizing the GraphQL Schema page in the Gatsby Docs, in particular foreign-key fields. If it wasn't for having to extract the contentful ID from the URN, this could be done using the |
Beta Was this translation helpful? Give feedback.
-
This feature was not yet requested by Contentful to be implemented into Gatsby. Feel free to open a support ticket at Contentful and request the support for it. This will give weight on the implementation ticket (especially if you paying customer) |
Beta Was this translation helpful? Give feedback.
-
There is a new feature in contentful UI where you can reference fields from other spaces. But when querying for that, I don't get the data I need. Just an identifier.
Example response
map is a reference field to a different space
i'm trying to query for this in gatsby, at build time
Beta Was this translation helpful? Give feedback.
All reactions