Skip to content

Commit

Permalink
fix(gatsby-transformer-remark): Revert/remark sources from different …
Browse files Browse the repository at this point in the history
…sources (#12639)

## Description
This change should happen in core and not in remark itself. I didn't think this through.

I should have read @m-allanson more carefully:
> Thanks @alexkirsz 👍 this is a really useful feature - so much so, that something like it should be added to Gatsby core instead of this being implemented separately across different plugins.

> It'll be particularly useful for the new Gatsby themes functionality that @ChristopherBiscardi is working on. As part of the themes work there's going to be an issue or rfc soon™️ (next week or after) to figure out exactly how this could be added to Gatsby core. Once the rfc has been written I'll add a link here.

> You can check out more info on Gatsby themes here and here.

## Related Issues
#7512
  • Loading branch information
wardpeet authored Mar 18, 2019
1 parent cfc5126 commit e28dd81
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 221 deletions.
5 changes: 0 additions & 5 deletions packages/gatsby-transformer-remark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ plugins: [
{
resolve: `gatsby-transformer-remark`,
options: {

// Defaults to `() => true`
filter: node => node.sourceInstanceName === `blog`,
// Defaults to `MarkdownRemark`
type: `BlogPost`,
// CommonMark mode (default: true)
commonmark: true,
// Footnotes mode (default: true)
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-transformer-remark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"bluebird": "^3.5.0",
"gray-matter": "^4.0.0",
"hast-util-raw": "^4.0.0",
"hast-util-to-html": "^4.0.0",
Expand Down
50 changes: 3 additions & 47 deletions packages/gatsby-transformer-remark/src/__tests__/extend-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
GraphQLList,
GraphQLSchema,
} = require(`gatsby/graphql`)
const { onCreateNode, setFieldsOnGraphQLNodeType } = require(`../gatsby-node`)
const { onCreateNode } = require(`../gatsby-node`)
const {
inferObjectStructureFromNodes,
} = require(`../../../gatsby/src/schema/infer-graphql-type`)
Expand All @@ -14,7 +14,7 @@ const extendNodeType = require(`../extend-node-type`)
async function queryResult(
nodes,
fragment,
{ typeName = `MarkdownRemark`, types = [] } = {},
{ types = [] } = {},
{ additionalParameters = {}, pluginOptions = {} }
) {
const inferredFields = inferObjectStructureFromNodes({
Expand Down Expand Up @@ -51,7 +51,7 @@ async function queryResult(
name: `LISTNODE`,
type: new GraphQLList(
new GraphQLObjectType({
name: typeName,
name: `MarkdownRemark`,
fields: markdownRemarkFields,
})
),
Expand Down Expand Up @@ -835,47 +835,3 @@ describe(`Headings are generated correctly from schema`, () => {
}
)
})

describe(`Adding fields to the GraphQL schema`, () => {
it(`only adds fields when the GraphQL type matches the provided type`, async () => {
const getNode = jest.fn()
const getNodesByType = jest.fn()

expect(
setFieldsOnGraphQLNodeType({
type: { name: `MarkdownRemark` },
getNode,
getNodesByType,
})
).toBeInstanceOf(Promise)

expect(
setFieldsOnGraphQLNodeType(
{ type: { name: `MarkdownRemark` }, getNode, getNodesByType },
{ type: `MarkdownRemark` }
)
).toBeInstanceOf(Promise)

expect(
setFieldsOnGraphQLNodeType(
{ type: { name: `MarkdownRemark` }, getNode, getNodesByType },
{ type: `GatsbyTestType` }
)
).toEqual({})

expect(
setFieldsOnGraphQLNodeType(
{ type: { name: `GatsbyTestType` }, getNode, getNodesByType },
{ type: `GatsbyTestType` }
)
).toBeInstanceOf(Promise)

expect(
setFieldsOnGraphQLNodeType({
type: { name: `GatsbyTestType` },
getNode,
getNodesByType,
})
).toEqual({})
})
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Promise = require(`bluebird`)
const _ = require(`lodash`)

const onCreateNode = require(`../on-node-create`)
Expand Down Expand Up @@ -119,50 +120,6 @@ yadda yadda

expect(parsed.frontmatter.date).toEqual(new Date(date).toJSON())
})

it(`Filters nodes with the given filter function, if provided`, async () => {
const content = ``

node.content = content
node.sourceInstanceName = `gatsby-test-source`

const createNode = jest.fn()
const createParentChildLink = jest.fn()
const actions = { createNode, createParentChildLink }
const createNodeId = jest.fn()
createNodeId.mockReturnValue(`uuid-from-gatsby`)

await onCreateNode(
{
node,
loadNodeContent,
actions,
createNodeId,
},
{
filter: node =>
node.sourceInstanceName === `gatsby-other-test-source`,
}
).then(() => {
expect(createNode).toHaveBeenCalledTimes(0)
expect(createParentChildLink).toHaveBeenCalledTimes(0)
})

await onCreateNode(
{
node,
loadNodeContent,
actions,
createNodeId,
},
{
filter: node => node.sourceInstanceName === `gatsby-test-source`,
}
).then(() => {
expect(createNode).toHaveBeenCalledTimes(1)
expect(createParentChildLink).toHaveBeenCalledTimes(1)
})
})
})

describe(`process graphql correctly`, () => {
Expand Down
24 changes: 0 additions & 24 deletions packages/gatsby-transformer-remark/src/__tests__/utils.js

This file was deleted.

Loading

0 comments on commit e28dd81

Please # to comment.