Skip to content
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

feat(contentful): add support for tags #31746

Merged
merged 6 commits into from
Jul 15, 2021
Merged

Conversation

axe312ger
Copy link
Collaborator

Implements the new metatags.tags property. See https://www.contentful.com/blog/2021/04/08/governance-tagging-metadata/

  • You can now filter single content types by tags
  • Every tag will be available as ContentfulTag
  • Structure is close to Contentful GraphQL API

Potentially breaking:

@axe312ger axe312ger added status: needs core review Currently awaiting review from Core team member topic: source-contentful Related to Gatsby's integration with Contentful labels Jun 3, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 3, 2021
@@ -24,7 +24,7 @@ const restrictedNodeFields = [
`parent`,
]

const restrictedContentTypes = [`entity`, `reference`]
const restrictedContentTypes = [`entity`, `reference`, `tag`, `asset`]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially breaking. Users having a tag contentType will no more be able to build their site. They might to be able to rewrite their queries and enable the useNameForId option.

Asset is probably problematic since forever.

All restrictions can be lifted with the rewrites in #31286

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how many people use this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asset probably nobody, as it am very certain it would break the build already.

Having a content type called tag might be used in very complex spaces. Still, it is much more likely its a field called tag(s).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put this behind a flag then?

@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 4, 2021
@axe312ger
Copy link
Collaborator Author

Contentful just updated the JS-SDK to cover the missing endpoint. Will refactor this PR asap.

https://github.com/contentful/contentful.js/releases/tag/v8.4.0

Copy link

@itwasmattgregg itwasmattgregg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had a chance to test this locally but code looks good.

@axe312ger
Copy link
Collaborator Author

Note: The code is updated, the SDK supports the metatag collection endpoint since the last update :)

@Graffiss
Copy link

Hey @axe312ger,
When do you think this PR could be merged? 🤔

itwasmattgregg
itwasmattgregg previously approved these changes Jun 24, 2021
@axe312ger
Copy link
Collaborator Author

axe312ger commented Jun 25, 2021

IMHO the code is ready. The e2e example demonstrates the usage and proofs that it works.

I restart the CI to get all ✅

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've added some questions and nits

packages/gatsby-source-contentful/src/normalize.js Outdated Show resolved Hide resolved
// Link tags
if (entryItem?.metadata?.tags) {
entryNode.metadata = {
tags___NODE: entryItem?.metadata?.tags.map(tag =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tags___NODE: entryItem?.metadata?.tags.map(tag =>
tags___NODE: entryItem.metadata?.tags.map(tag =>

@@ -24,7 +24,7 @@ const restrictedNodeFields = [
`parent`,
]

const restrictedContentTypes = [`entity`, `reference`]
const restrictedContentTypes = [`entity`, `reference`, `tag`, `asset`]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put this behind a flag then?

Comment on lines 368 to 378
createTypes(
schema.buildObjectType({
name: `ContentfulTag`,
fields: {
name: { type: `String!` },
contentful_id: { type: `String!` },
id: { type: `ID!` },
},
interfaces: [`Node`],
})
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this out of sourceNodes into schemaCustimization API.

A contentfulTag does not have sys fields? (please add a don't infer to it as well)

@axe312ger axe312ger force-pushed the feat/contentful-metadata-tags branch 2 times, most recently from b3beb26 to fb5a206 Compare July 6, 2021 15:32
@axe312ger axe312ger force-pushed the feat/contentful-metadata-tags branch from fb5a206 to 14857d6 Compare July 11, 2021 13:08
@axe312ger axe312ger added type: feature or enhancement Issue that is not a bug and requests the addition of a new feature or enhancement. and removed type: feature or enhancement Issue that is not a bug and requests the addition of a new feature or enhancement. labels Jul 13, 2021
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs core review Currently awaiting review from Core team member topic: source-contentful Related to Gatsby's integration with Contentful type: feature or enhancement Issue that is not a bug and requests the addition of a new feature or enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants