Skip to content

Commit e28dd81

Browse files
authored
fix(gatsby-transformer-remark): Revert/remark sources from different 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
1 parent cfc5126 commit e28dd81

File tree

8 files changed

+86
-221
lines changed

8 files changed

+86
-221
lines changed

packages/gatsby-transformer-remark/README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ plugins: [
1414
{
1515
resolve: `gatsby-transformer-remark`,
1616
options: {
17-
18-
// Defaults to `() => true`
19-
filter: node => node.sourceInstanceName === `blog`,
20-
// Defaults to `MarkdownRemark`
21-
type: `BlogPost`,
2217
// CommonMark mode (default: true)
2318
commonmark: true,
2419
// Footnotes mode (default: true)

packages/gatsby-transformer-remark/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"dependencies": {
1010
"@babel/runtime": "^7.0.0",
11+
"bluebird": "^3.5.0",
1112
"gray-matter": "^4.0.0",
1213
"hast-util-raw": "^4.0.0",
1314
"hast-util-to-html": "^4.0.0",

packages/gatsby-transformer-remark/src/__tests__/extend-node.js

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {
44
GraphQLList,
55
GraphQLSchema,
66
} = require(`gatsby/graphql`)
7-
const { onCreateNode, setFieldsOnGraphQLNodeType } = require(`../gatsby-node`)
7+
const { onCreateNode } = require(`../gatsby-node`)
88
const {
99
inferObjectStructureFromNodes,
1010
} = require(`../../../gatsby/src/schema/infer-graphql-type`)
@@ -14,7 +14,7 @@ const extendNodeType = require(`../extend-node-type`)
1414
async function queryResult(
1515
nodes,
1616
fragment,
17-
{ typeName = `MarkdownRemark`, types = [] } = {},
17+
{ types = [] } = {},
1818
{ additionalParameters = {}, pluginOptions = {} }
1919
) {
2020
const inferredFields = inferObjectStructureFromNodes({
@@ -51,7 +51,7 @@ async function queryResult(
5151
name: `LISTNODE`,
5252
type: new GraphQLList(
5353
new GraphQLObjectType({
54-
name: typeName,
54+
name: `MarkdownRemark`,
5555
fields: markdownRemarkFields,
5656
})
5757
),
@@ -835,47 +835,3 @@ describe(`Headings are generated correctly from schema`, () => {
835835
}
836836
)
837837
})
838-
839-
describe(`Adding fields to the GraphQL schema`, () => {
840-
it(`only adds fields when the GraphQL type matches the provided type`, async () => {
841-
const getNode = jest.fn()
842-
const getNodesByType = jest.fn()
843-
844-
expect(
845-
setFieldsOnGraphQLNodeType({
846-
type: { name: `MarkdownRemark` },
847-
getNode,
848-
getNodesByType,
849-
})
850-
).toBeInstanceOf(Promise)
851-
852-
expect(
853-
setFieldsOnGraphQLNodeType(
854-
{ type: { name: `MarkdownRemark` }, getNode, getNodesByType },
855-
{ type: `MarkdownRemark` }
856-
)
857-
).toBeInstanceOf(Promise)
858-
859-
expect(
860-
setFieldsOnGraphQLNodeType(
861-
{ type: { name: `MarkdownRemark` }, getNode, getNodesByType },
862-
{ type: `GatsbyTestType` }
863-
)
864-
).toEqual({})
865-
866-
expect(
867-
setFieldsOnGraphQLNodeType(
868-
{ type: { name: `GatsbyTestType` }, getNode, getNodesByType },
869-
{ type: `GatsbyTestType` }
870-
)
871-
).toBeInstanceOf(Promise)
872-
873-
expect(
874-
setFieldsOnGraphQLNodeType({
875-
type: { name: `GatsbyTestType` },
876-
getNode,
877-
getNodesByType,
878-
})
879-
).toEqual({})
880-
})
881-
})

packages/gatsby-transformer-remark/src/__tests__/on-node-create.js

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const Promise = require(`bluebird`)
12
const _ = require(`lodash`)
23

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

120121
expect(parsed.frontmatter.date).toEqual(new Date(date).toJSON())
121122
})
122-
123-
it(`Filters nodes with the given filter function, if provided`, async () => {
124-
const content = ``
125-
126-
node.content = content
127-
node.sourceInstanceName = `gatsby-test-source`
128-
129-
const createNode = jest.fn()
130-
const createParentChildLink = jest.fn()
131-
const actions = { createNode, createParentChildLink }
132-
const createNodeId = jest.fn()
133-
createNodeId.mockReturnValue(`uuid-from-gatsby`)
134-
135-
await onCreateNode(
136-
{
137-
node,
138-
loadNodeContent,
139-
actions,
140-
createNodeId,
141-
},
142-
{
143-
filter: node =>
144-
node.sourceInstanceName === `gatsby-other-test-source`,
145-
}
146-
).then(() => {
147-
expect(createNode).toHaveBeenCalledTimes(0)
148-
expect(createParentChildLink).toHaveBeenCalledTimes(0)
149-
})
150-
151-
await onCreateNode(
152-
{
153-
node,
154-
loadNodeContent,
155-
actions,
156-
createNodeId,
157-
},
158-
{
159-
filter: node => node.sourceInstanceName === `gatsby-test-source`,
160-
}
161-
).then(() => {
162-
expect(createNode).toHaveBeenCalledTimes(1)
163-
expect(createParentChildLink).toHaveBeenCalledTimes(1)
164-
})
165-
})
166123
})
167124

168125
describe(`process graphql correctly`, () => {

packages/gatsby-transformer-remark/src/__tests__/utils.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)