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-source-graphql): Destructure createContentDigest from first parameter #13214

Merged
merged 3 commits into from
Apr 8, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`validation throws on missing fieldName 1`] = `"gatsby-source-graphql requires option \`fieldName\` to be specified"`;

exports[`validation throws on missing typename 1`] = `"gatsby-source-graphql requires option \`typeName\` to be specified"`;

exports[`validation throws on missing url 1`] = `"gatsby-source-graphql requires either option \`url\` or \`createLink\` callback"`;
69 changes: 69 additions & 0 deletions packages/gatsby-source-graphql/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
jest.mock(`graphql-tools`, () => {
return {
makeRemoteExecutableSchema: jest.fn(),
transformSchema: jest.fn(),
introspectSchema: jest.fn(),
RenameTypes: jest.fn(),
}
})
jest.mock(`graphql`, () => {
const graphql = jest.requireActual(`graphql`)
return {
...graphql,
buildSchema: jest.fn(),
printSchema: jest.fn(),
}
})
const { sourceNodes } = require(`../gatsby-node`)

const getInternalGatsbyAPI = () => {
const actions = {
addThirdPartySchema: jest.fn(),
createPageDependency: jest.fn(),
createNode: jest.fn(),
}

return {
actions,
cache: {
get: jest.fn(),
set: jest.fn(),
},
createContentDigest: jest.fn(),
createNodeId: jest.fn(),
}
}

describe(`validation`, () => {
;[
[
`throws on missing typename`,
{ fieldName: `github`, url: `https://github.com` },
],
[
`throws on missing fieldName`,
{ typeName: `Github`, url: `https://github.com` },
],
[`throws on missing url`, { typeName: `Github`, fieldName: `github` }],
].forEach(([testName, pluginOptions]) => {
it(testName, () => {
expect(
sourceNodes(getInternalGatsbyAPI(), pluginOptions)
).rejects.toThrowErrorMatchingSnapshot()
})
})
})

describe(`createSchemaNode`, () => {
it(`invokes createContentDigest`, async () => {
const api = getInternalGatsbyAPI()
await sourceNodes(api, {
typeName: `Github`,
fieldName: `github`,
url: `https://github.com`,
})

expect(api.createContentDigest).toHaveBeenCalledWith(expect.any(String))
expect(api.createContentDigest).toHaveBeenCalledTimes(1)
})
})
4 changes: 2 additions & 2 deletions packages/gatsby-source-graphql/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ const {
const { createHttpLink } = require(`apollo-link-http`)
const fetch = require(`node-fetch`)
const invariant = require(`invariant`)

const {
NamespaceUnderFieldTransform,
StripNonQueryTransform,
} = require(`./transforms`)

exports.sourceNodes = async (
{ actions, createNodeId, cache, store },
{ actions, createNodeId, cache, createContentDigest },
options
) => {
const { addThirdPartySchema, createPageDependency, createNode } = actions
Expand All @@ -28,7 +29,6 @@ exports.sourceNodes = async (
createLink,
createSchema,
refetchInterval,
createContentDigest,
} = options

invariant(
Expand Down