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(gatsby-source-drupal): add typePrefix option #37967

Merged
merged 7 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/using-drupal/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
options: {
baseUrl: `https://live-contentacms.pantheonsite.io/`,
apiBase: `api`,
typePrefix: "Drupal",
},
},
{
Expand Down
12 changes: 6 additions & 6 deletions examples/using-drupal/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ export default IndexPage

export const pageQuery = graphql`
{
topRecipe: allRecipes(sort: { createdAt: ASC }, limit: 1) {
topRecipe: allDrupalRecipes(sort: { createdAt: ASC }, limit: 1) {
edges {
node {
title
gatsbyPath(filePath: "/{Recipes.title}")
gatsbyPath(filePath: "/{DrupalRecipes.title}")
relationships {
image {
relationships {
Expand All @@ -243,15 +243,15 @@ export const pageQuery = graphql`
}
}
}
nextTwoPromotedRecipes: allRecipes(
nextTwoPromotedRecipes: allDrupalRecipes(
sort: { createdAt: ASC }
limit: 2
skip: 1
) {
edges {
node {
title
gatsbyPath(filePath: "/{Recipes.title}")
gatsbyPath(filePath: "/{DrupalRecipes.title}")
relationships {
category {
name
Expand All @@ -273,7 +273,7 @@ export const pageQuery = graphql`
}
}
}
nextFourPromotedRecipes: allRecipes(
nextFourPromotedRecipes: allDrupalRecipes(
sort: { createdAt: ASC }
limit: 4
skip: 3
Expand All @@ -282,7 +282,7 @@ export const pageQuery = graphql`
node {
id
title
gatsbyPath(filePath: "/{Recipes.title}")
gatsbyPath(filePath: "/{DrupalRecipes.title}")
relationships {
category {
name
Expand Down
4 changes: 2 additions & 2 deletions examples/using-drupal/src/pages/recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export default Recipes

export const query = graphql`
query {
recipes: allRecipes(limit: 1000) {
recipes: allDrupalRecipes(limit: 1000) {
edges {
node {
title
gatsbyPath(filePath: "/{Recipes.title}")
gatsbyPath(filePath: "/{DrupalRecipes.title}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ const RecipeTemplate = ({ data }) => (
export default RecipeTemplate

export const query = graphql`
query($id: String!) {
recipe: recipes(id: { eq: $id }) {
query ($id: String!) {
recipe: drupalRecipes(id: { eq: $id }) {
title
preparationTime
difficulty
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-gatsby-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"scripts": {
"build": "",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir dist/ --ignore \"**/__tests__\" --extensions \".ts,.js\""
"watch": ""
TylerBarnes marked this conversation as resolved.
Show resolved Hide resolved
}
}
31 changes: 31 additions & 0 deletions packages/gatsby-source-drupal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,37 @@ module.exports = {

Some entities are not translatable like Drupal files and will return null result when language code from parent entity doesn't match up. These items can be specified as nonTranslatableEntities and receive the defaultLanguage as fallback.

## Type prefix

By default, types are created with names that match the types in Drupal. However you can use the `typePrefix` option to add a prefix to all types. This is useful if you have multiple Drupal sources and want to differentiate between them, or if you have Drupal types that conflict with other types in your site.

```javascript
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-drupal`,
options: {
baseUrl: `https://live-contentacms.pantheonsite.io/`,
typePrefix: `Drupal`,
},
},
],
}
```

You would then query for `allDrupalArticle` instead of `allArticle`.

```graphql
{
allDrupalArticle {
nodes {
title
}
}
}
```

## Gatsby Preview (experimental)

You will need to have the Drupal module installed, more information on that here: https://www.drupal.org/project/gatsby
Expand Down
25 changes: 13 additions & 12 deletions packages/gatsby-source-drupal/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ import {
imageCDNState,
} from "./normalize"

const {
import {
handleReferences,
handleWebhookUpdate,
createNodeIfItDoesNotExist,
handleDeletedNode,
drupalCreateNodeManifest,
getExtendedFileNodeData,
} = require(`./utils`)

} from "./utils"
const imageCdnDocs = `https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-drupal#readme`

const agent = {
Expand Down Expand Up @@ -243,6 +242,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
createNodeId,
createContentDigest,
entityReferenceRevisions,
pluginOptions,
})
reporter.log(`Deleted node: ${deletedNode.id}`)
}
Expand All @@ -264,6 +264,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
createContentDigest,
getNode,
reporter,
pluginOptions,
})
}

Expand All @@ -278,8 +279,6 @@ ${JSON.stringify(webhookBody, null, 4)}`
getCache,
getNode,
reporter,
store,
languageConfig,
},
pluginOptions
)
Expand Down Expand Up @@ -402,6 +401,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
createContentDigest,
getNode,
reporter,
pluginOptions,
TylerBarnes marked this conversation as resolved.
Show resolved Hide resolved
})
}
}
Expand All @@ -416,6 +416,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
createNodeId,
createContentDigest,
entityReferenceRevisions,
pluginOptions,
})
} else {
// The data could be a single Drupal entity or an array of Drupal
Expand All @@ -436,8 +437,6 @@ ${JSON.stringify(webhookBody, null, 4)}`
getCache,
getNode,
reporter,
store,
languageConfig,
},
pluginOptions
)
Expand Down Expand Up @@ -773,6 +772,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
createNodeId,
cache,
entityReferenceRevisions,
pluginOptions,
})
}

Expand All @@ -782,7 +782,9 @@ ${JSON.stringify(webhookBody, null, 4)}`
reporter.info(`Downloading remote files from Drupal`)

// Download all files (await for each pool to complete to fix concurrency issues)
const fileNodes = [...nodes.values()].filter(isFileNode)
const fileNodes = [...nodes.values()].filter(node =>
isFileNode(node, pluginOptions.typePrefix)
)

if (fileNodes.length) {
const downloadingFilesActivity = reporter.activityTimer(
Expand All @@ -795,12 +797,10 @@ ${JSON.stringify(webhookBody, null, 4)}`
await downloadFile(
{
node,
store,
cache,
createNode,
createNodeId,
getCache,
reporter,
Comment on lines -798 to -803
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These aren't valid props

},
pluginOptions
)
Expand Down Expand Up @@ -833,7 +833,6 @@ exports.onCreateDevServer = (
createNodeId,
getNode,
actions,
store,
cache,
createContentDigest,
getCache,
Expand Down Expand Up @@ -873,7 +872,6 @@ exports.onCreateDevServer = (
getCache,
getNode,
reporter,
store,
},
pluginOptions
)
Expand Down Expand Up @@ -913,6 +911,9 @@ exports.pluginOptionsSchema = ({ Joi }) =>
disallowedLinkTypes: Joi.array().items(Joi.string()),
skipFileDownloads: Joi.boolean(),
imageCDN: Joi.boolean().default(true),
typePrefix: Joi.string()
.description(`Prefix for Drupal node types`)
.default(``),
fastBuilds: Joi.boolean(),
entityReferenceRevisions: Joi.array().items(Joi.string()),
secret: Joi.string().description(
Expand Down