-
My company uses two sources for data. DatoCMS for page/product content (using The problems start when we need that same pricing in pages that are not programmatically created, like a page that listed all products. I run a page query to get the content and get the Shopify ids but, now I'm stuck. My first thought was to pass the ids to the static query component, but this feature will never happen from what I have read. My next idea was to stitch these two data sources together in Gatsby's schema into one entry or create a field on the DatCMS nodes and inject the Shopify data. I've never dug into Gatsby's internal APIs or seen an example of this to know if it's even possible. Am I going down a fruitless rabbit hole, or is there another solution I'm not seeing? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
@wildpow You can absolutely stitch types together. But that will require diving deep into schema customization API. See this blog post: https://www.gatsbyjs.com/blog/2019-03-18-releasing-new-schema-customization/ Maybe this example will be a good start: gatsby/examples/using-type-definitions/gatsby-node.js Lines 28 to 40 in 5bc84a9 |
Beta Was this translation helpful? Give feedback.
-
Here is my only success so far: exports.createResolvers = ({ createResolvers }) => {
createResolvers({
DatoCmsMattress: {
shopifyInfo: {
type: [`ShopifyProduct`],
resolve(source, args, context, info) {
const fieldValue =
source.entityPayload.attributes.shop_matt_connection;
const shopifyMatts = context.nodeModel.getAllNodes({
type: "ShopifyProduct",
});
return shopifyMatts.filter((matt) => matt.shopifyId === fieldValue);
},
},
},
});
}; Which adds the entire Shopify product to Dato's entry. Not exactly what I was looking for, but it works. I got the idea from the same file you posted. gatsby/examples/using-type-definitions/gatsby-node.js Lines 88 to 106 in 5bc84a9 Since my development build times are so long anyway, I'm not sure I could measure a negative impact if there were one. |
Beta Was this translation helpful? Give feedback.
-
@vladar This works: exports.createResolvers = ({ createResolvers }) => {
createResolvers({
DatoCmsMattress: {
shopifyInfo: {
type: [`ShopifyProduct`],
resolve(source, args, context, info) {
const fieldValue =
source.entityPayload.attributes.shop_matt_connection;
return context.nodeModel.runQuery({
query: { filter: { shopifyId: { eq: fieldValue } } },
type: `ShopifyProduct`,
// Not sure why removing this made it work?!?
// firstOnly: true,
});
},
},
},
});
}; |
Beta Was this translation helpful? Give feedback.
@vladar This works: