Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

headless cms - Gatsby/graphql: How to reuse fragments on many different models

Using Gatsby & DatoCMS.

I have many (20) models that all contain links to other models.

For example, on the home page "hero", cms users may point to different models/pages:

fragment homeHeroFragment on DatoCmsCompanyHome {
   ctaLinkLabel
   ctaLinkObject {
        -- How to make this part reusable everywhere I have a "validated" Link: 
        ... on DatoCmsCaseOverview {
            type: __typename
            id
            locale
            company {
                slug
            }
        }
        ... on DatoCmsThemeOverview {
            type: __typename
            id
            locale
            company {
                slug
            }
        }
        ... -- x roughly 20
    }
}

Currently I have to explicitly reference each model that is allowed, as well as repeat this everywhere I have this kind of link which is ~ 20 places.

Does anyone know how to reuse this linkObject on multiple models so I have to write it only once? I can't simply interpolate, I can't write it as a reusable fragment as it needs to be mounted on many different files.

I'm considering writing a script for automatically generating these files. But I'm sure there's a better way.

Thanks!

question from:https://stackoverflow.com/questions/65682387/gatsby-graphql-how-to-reuse-fragments-on-many-different-models

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...