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

fix(gatsby-transformer-remark): Revert/remark sources from different sources #12639

Merged
merged 3 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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