Skip to content

Commit a88cb2c

Browse files
stefanprobstGatsbyJS Bot
authored andcommitted
chore(gatsby): Remove unnecessary checks (#17289)
1 parent 31c9cfa commit a88cb2c

File tree

3 files changed

+6
-51
lines changed

3 files changed

+6
-51
lines changed

packages/gatsby/src/schema/__tests__/node-model.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,6 @@ describe(`NodeModel`, () => {
117117
nodeModel.getNodeById({ id: `person4` }, { path: `/` })
118118
expect(createPageDependency).not.toHaveBeenCalled()
119119
})
120-
121-
it(`handles already resolved id`, () => {
122-
const result = nodeModel.getNodeById({
123-
id: { id: `person1`, name: `Person1` },
124-
})
125-
expect(result.id).toBe(`person1`)
126-
expect(result.name).toBe(`Person1`)
127-
})
128120
})
129121

130122
describe(`getNodesByIds`, () => {
@@ -203,23 +195,6 @@ describe(`NodeModel`, () => {
203195
nodeModel.getNodesByIds({ ids: [`person4`, `post4`] }, { path: `/` })
204196
expect(createPageDependency).not.toHaveBeenCalled()
205197
})
206-
207-
it(`handles already resolved ids`, () => {
208-
const result = nodeModel.getNodesByIds({
209-
ids: [
210-
{ id: `person1`, name: `Person1` },
211-
`person2`,
212-
{ id: `post1`, frontmatter: { published: false } },
213-
],
214-
})
215-
expect(result.length).toBe(3)
216-
expect(result[0].id).toBe(`person1`)
217-
expect(result[0].name).toBe(`Person1`)
218-
expect(result[1].id).toBe(`person2`)
219-
expect(result[1].name).toBe(`Person2`)
220-
expect(result[2].id).toBe(`post1`)
221-
expect(result[2].frontmatter.published).toBe(false)
222-
})
223198
})
224199

225200
describe(`getAllNodes`, () => {

packages/gatsby/src/schema/node-model.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const {
1313
const invariant = require(`invariant`)
1414
const reporter = require(`gatsby-cli/lib/reporter`)
1515

16-
type IDOrNode = string | { id: string }
1716
type TypeOrTypeName = string | GraphQLOutputType
1817

1918
/**
@@ -36,11 +35,11 @@ interface QueryArguments {
3635

3736
export interface NodeModel {
3837
getNodeById(
39-
{ id: IDOrNode, type?: TypeOrTypeName },
38+
{ id: string, type?: TypeOrTypeName },
4039
pageDependencies?: PageDependencies
4140
): any | null;
4241
getNodesByIds(
43-
{ ids: Array<IDOrNode>, type?: TypeOrTypeName },
42+
{ ids: Array<string>, type?: TypeOrTypeName },
4443
pageDependencies?: PageDependencies
4544
): Array<any>;
4645
getAllNodes(
@@ -458,15 +457,8 @@ class ContextualNodeModel {
458457
}
459458
}
460459

461-
const getNodeById = (nodeStore, id) => {
462-
// This is for cases when the `id` has already been resolved
463-
// to a full Node for the input filter, and is also in the selection
464-
// set. E.g. `{ foo(parent: { id: { eq: 1 } } ) { parent { id } } }`.
465-
if (_.isPlainObject(id) && id.id) {
466-
return id
467-
}
468-
return id != null ? nodeStore.getNode(id) : null
469-
}
460+
const getNodeById = (nodeStore, id) =>
461+
id != null ? nodeStore.getNode(id) : null
470462

471463
const toNodeTypeNames = (schema, gqlTypeName) => {
472464
const gqlType =

packages/gatsby/src/schema/resolvers.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,7 @@ const link = (options = {}, fieldConfig) => async (
126126
fromNode: options.from ? options.fromNode : info.fromNode,
127127
})
128128

129-
if (fieldValue == null || _.isPlainObject(fieldValue)) return fieldValue
130-
if (
131-
Array.isArray(fieldValue) &&
132-
(fieldValue[0] == null || _.isPlainObject(fieldValue[0]))
133-
) {
134-
return fieldValue
135-
}
129+
if (fieldValue == null) return null
136130

137131
const returnType = getNullableType(options.type || info.returnType)
138132
const type = getNamedType(returnType)
@@ -194,13 +188,7 @@ const fileByPath = (options = {}, fieldConfig) => async (
194188
fromNode: options.from ? options.fromNode : info.fromNode,
195189
})
196190

197-
if (fieldValue == null || _.isPlainObject(fieldValue)) return fieldValue
198-
if (
199-
Array.isArray(fieldValue) &&
200-
(fieldValue[0] == null || _.isPlainObject(fieldValue[0]))
201-
) {
202-
return fieldValue
203-
}
191+
if (fieldValue == null) return null
204192

205193
const findLinkedFileNode = relativePath => {
206194
// Use the parent File node to create the absolute path to

0 commit comments

Comments
 (0)