Skip to content

Commit

Permalink
move new tags feature behind a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Jul 6, 2021
1 parent 19947fb commit f059c04
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
34 changes: 20 additions & 14 deletions packages/gatsby-source-contentful/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const restrictedNodeFields = [
`parent`,
]

const restrictedContentTypes = [`entity`, `reference`, `tag`, `asset`]

exports.setFieldsOnGraphQLNodeType = require(`./extend-node-type`).extendNodeType

const validateContentfulAccess = async pluginOptions => {
Expand Down Expand Up @@ -318,6 +316,11 @@ exports.sourceNodes = async (

// Check for restricted content type names
const useNameForId = pluginConfig.get(`useNameForId`)
const restrictedContentTypes = [`entity`, `reference`, `asset`]

if (pluginConfig.get(`enableTags`)) {
restrictedContentTypes.push(`tags`)
}

contentTypeItems.forEach(contentTypeItem => {
// Establish identifier for content type
Expand Down Expand Up @@ -365,17 +368,20 @@ exports.sourceNodes = async (
})
}

createTypes(
schema.buildObjectType({
name: `ContentfulTag`,
fields: {
name: { type: `String!` },
contentful_id: { type: `String!` },
id: { type: `ID!` },
},
interfaces: [`Node`],
})
)
if (pluginConfig.get(`enableTags`)) {
createTypes(
schema.buildObjectType({
name: `ContentfulTag`,
fields: {
name: { type: `String!` },
contentful_id: { type: `String!` },
id: { type: `ID!` },
},
interfaces: [`Node`],
extensions: { dontInfer: {} },
})
)
}

createTypes(`
interface ContentfulEntry implements Node {
Expand Down Expand Up @@ -652,7 +658,6 @@ exports.sourceNodes = async (
await Promise.all(
normalize.createNodesForContentType({
contentTypeItem,
contentTypeItems,
restrictedNodeFields,
conflictFieldPrefix,
entries: entryList[i],
Expand All @@ -665,6 +670,7 @@ exports.sourceNodes = async (
locales,
space,
useNameForId: pluginConfig.get(`useNameForId`),
pluginConfig,
})
)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-source-contentful/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ function prepareJSONNode(id, node, key, content) {

exports.createNodesForContentType = ({
contentTypeItem,
contentTypeItems,
restrictedNodeFields,
conflictFieldPrefix,
entries,
Expand All @@ -241,6 +240,7 @@ exports.createNodesForContentType = ({
locales,
space,
useNameForId,
pluginConfig,
}) => {
// Establish identifier for content type
// Use `name` if specified, otherwise, use internal id (usually a natural-language constant,
Expand Down Expand Up @@ -590,9 +590,9 @@ exports.createNodesForContentType = ({
entryNode.internal.contentDigest = entryItem.sys.updatedAt

// Link tags
if (entryItem?.metadata?.tags) {
if (pluginConfig.get(`enableTags`)) {
entryNode.metadata = {
tags___NODE: entryItem?.metadata?.tags.map(tag =>
tags___NODE: entryItem.metadata.tags.map(tag =>
createNodeId(`ContentfulTag__${space.sys.id}__${tag.sys.id}`)
),
}
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-source-contentful/src/plugin-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const defaultOptions = {
forceFullSync: false,
pageLimit: DEFAULT_PAGE_LIMIT,
useNameForId: true,
enableTags: false,
}

const createPluginConfig = pluginOptions => {
Expand Down

0 comments on commit f059c04

Please sign in to comment.