Skip to content

Commit

Permalink
feat(gatsby): use embedded remote schemas (#19504)
Browse files Browse the repository at this point in the history
avoids additional layer of delegation
  • Loading branch information
yaacovCR authored and GatsbyJS Bot committed Dec 9, 2019
1 parent 06e650d commit 588eaf7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-source-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@babel/runtime": "^7.7.4",
"apollo-link": "1.2.13",
"apollo-link-http": "^1.5.16",
"graphql-tools": "^3.1.1",
"graphql-tools-fork": "^7.1.4",
"invariant": "^2.2.4",
"node-fetch": "^1.7.3",
"uuid": "^3.3.3"
Expand Down
3 changes: 1 addition & 2 deletions packages/gatsby-source-graphql/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
jest.mock(`graphql-tools`, () => {
jest.mock(`graphql-tools-fork`, () => {
return {
makeRemoteExecutableSchema: jest.fn(),
transformSchema: jest.fn(),
introspectSchema: jest.fn(),
RenameTypes: jest.fn(),
Expand Down
32 changes: 16 additions & 16 deletions packages/gatsby-source-graphql/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const uuidv4 = require(`uuid/v4`)
const { buildSchema, printSchema } = require(`gatsby/graphql`)
const {
makeRemoteExecutableSchema,
transformSchema,
introspectSchema,
RenameTypes,
} = require(`graphql-tools`)
} = require(`graphql-tools-fork`)
const { createHttpLink } = require(`apollo-link-http`)
const nodeFetch = require(`node-fetch`)
const invariant = require(`invariant`)
Expand Down Expand Up @@ -75,11 +74,6 @@ exports.sourceNodes = async (
await cache.set(cacheKey, sdl)
}

const remoteSchema = makeRemoteExecutableSchema({
schema: introspectionSchema,
link,
})

const nodeId = createNodeId(`gatsby-source-graphql-${typeName}`)
const node = createSchemaNode({
id: nodeId,
Expand All @@ -97,15 +91,21 @@ exports.sourceNodes = async (
return {}
}

const schema = transformSchema(remoteSchema, [
new StripNonQueryTransform(),
new RenameTypes(name => `${typeName}_${name}`),
new NamespaceUnderFieldTransform({
typeName,
fieldName,
resolver,
}),
])
const schema = transformSchema(
{
schema: introspectionSchema,
link,
},
[
new StripNonQueryTransform(),
new RenameTypes(name => `${typeName}_${name}`),
new NamespaceUnderFieldTransform({
typeName,
fieldName,
resolver,
}),
]
)

addThirdPartySchema({ schema })

Expand Down
7 changes: 2 additions & 5 deletions packages/gatsby-source-graphql/src/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ const {
GraphQLNonNull,
GraphQLSchema,
} = require(`gatsby/graphql`)
const {
visitSchema,
VisitSchemaKind,
} = require(`graphql-tools/dist/transforms/visitSchema`)
const { visitSchema, VisitSchemaKind } = require(`graphql-tools-fork`)
const {
createResolveType,
fieldMapToFieldConfigMap,
} = require(`graphql-tools/dist/stitching/schemaRecreation`)
} = require(`graphql-tools-fork`)

class NamespaceUnderFieldTransform {
constructor({ typeName, fieldName, resolver }) {
Expand Down
23 changes: 12 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4544,7 +4544,7 @@ apollo-link-http@^1.5.16:
apollo-link-http-common "^0.2.15"
tslib "^1.9.3"

apollo-link@1.2.13, apollo-link@^1.2.13, apollo-link@^1.2.2:
apollo-link@1.2.13, apollo-link@^1.2.13:
version "1.2.13"
resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.13.tgz#dff00fbf19dfcd90fddbc14b6a3f9a771acac6c4"
integrity sha512-+iBMcYeevMm1JpYgwDEIDt/y0BB7VWyvlm/7x+TIPNLHCTCMgcEgDuW5kH86iQZWo0I7mNwQiTOz+/3ShPFmBw==
Expand All @@ -4554,7 +4554,7 @@ apollo-link@1.2.13, apollo-link@^1.2.13, apollo-link@^1.2.2:
tslib "^1.9.3"
zen-observable-ts "^0.8.20"

apollo-utilities@^1.0.1, apollo-utilities@^1.3.0:
apollo-utilities@^1.3.0, apollo-utilities@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/apollo-utilities/-/apollo-utilities-1.3.2.tgz#8cbdcf8b012f664cd6cb5767f6130f5aed9115c9"
integrity sha512-JWNHj8XChz7S4OZghV6yc9FNnzEXj285QYp/nLNh943iObycI5GTDO3NGR9Dth12LRrSFMeDOConPfPln+WGfg==
Expand Down Expand Up @@ -8016,6 +8016,7 @@ depd@~1.1.2:
deprecated-decorator@^0.1.6:
version "0.1.6"
resolved "https://registry.yarnpkg.com/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz#00966317b7a12fe92f3cc831f7583af329b86c37"
integrity sha1-AJZjF7ehL+kvPMgx91g68ym4bDc=

deprecation@^2.0.0:
version "2.3.1"
Expand Down Expand Up @@ -10933,16 +10934,16 @@ graphql-request@^1.5.0, graphql-request@^1.8.2:
dependencies:
cross-fetch "2.2.2"

graphql-tools@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/graphql-tools/-/graphql-tools-3.1.1.tgz#d593358f01e7c8b1671a17b70ddb034dea9dbc50"
integrity sha512-yHvPkweUB0+Q/GWH5wIG60bpt8CTwBklCSzQdEHmRUgAdEQKxw+9B7zB3dG7wB3Ym7M7lfrS4Ej+jtDZfA2UXg==
graphql-tools-fork@^7.1.4:
version "7.1.4"
resolved "https://registry.yarnpkg.com/graphql-tools-fork/-/graphql-tools-fork-7.1.4.tgz#a3a6c2ab06add2a6fdaec0a976237ac49e05c85a"
integrity sha512-WabbxnfId5j5HTDFEYPXuelw4OUDqHY4pwRClTT74o1VOtGarilkgK96ubPqAszIpxYKjlYntqe7+0Y889z+zA==
dependencies:
apollo-link "^1.2.2"
apollo-utilities "^1.0.1"
apollo-link "^1.2.13"
apollo-utilities "^1.3.2"
deprecated-decorator "^0.1.6"
iterall "^1.1.3"
uuid "^3.1.0"
iterall "^1.2.2"
uuid "^3.3.3"

graphql-type-json@^0.2.4:
version "0.2.4"
Expand Down Expand Up @@ -12797,7 +12798,7 @@ isurl@^1.0.0-alpha5:
has-to-string-tag-x "^1.2.0"
is-object "^1.0.1"

iterall@^1.1.3, iterall@^1.2.2:
iterall@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7"

Expand Down

0 comments on commit 588eaf7

Please sign in to comment.