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

feat(gatsby): allow schema customization #11480

Merged
merged 111 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
9926e2d
Schema refactor WIP
freiksenet Feb 1, 2019
d9e6873
Oops
freiksenet Feb 1, 2019
08ab5c2
First working version
freiksenet Feb 4, 2019
1aef564
First working version
freiksenet Feb 4, 2019
ac49f5b
Almost working site
freiksenet Feb 4, 2019
f369296
progress
freiksenet Feb 5, 2019
6add8d9
WWW working
freiksenet Feb 6, 2019
2e25030
Working add type defs
freiksenet Feb 7, 2019
b532d1b
addResolvers
freiksenet Feb 8, 2019
69162b6
Add node model
stefanprobst Feb 8, 2019
b9af766
Handle NonNull and pass context and info in runQuery
stefanprobst Feb 9, 2019
a5b0d55
Don't fetch resolved id again
stefanprobst Feb 9, 2019
f7d80f0
Minor fixes
stefanprobst Feb 9, 2019
23423db
Make www build with Loki
stefanprobst Feb 9, 2019
6e11926
Fix tests
stefanprobst Feb 10, 2019
ed9314b
Pull out resolving nodes
stefanprobst Feb 10, 2019
79754e6
Fix getExampleValue
stefanprobst Feb 10, 2019
6f1e715
Port exampleValue tests
stefanprobst Feb 10, 2019
12a9819
Fixes for type inference
stefanprobst Feb 10, 2019
0ca1294
Infer errors and stuff
freiksenet Feb 11, 2019
b8d0d6f
Merge remote-tracking branch 'stefanprobst/schema-refactor-new-sp' in…
freiksenet Feb 11, 2019
15df9e3
Lint
freiksenet Feb 11, 2019
9a59b47
More changes
freiksenet Feb 12, 2019
7878818
Fix issue with default resolvers
freiksenet Feb 12, 2019
779cb39
Fix tests
freiksenet Feb 12, 2019
d45c97c
Port more tests
freiksenet Feb 12, 2019
10f1405
Move schema composer creation to separate location
freiksenet Feb 13, 2019
c7b1177
Most tests pass
freiksenet Feb 13, 2019
8dbc6e7
Move tests to better location
freiksenet Feb 13, 2019
bf02578
Readd list sorting option
freiksenet Feb 13, 2019
b6ec46f
Node model as a class
freiksenet Feb 13, 2019
add0666
Model layer tests
freiksenet Feb 13, 2019
da8469d
Fix flow type
freiksenet Feb 14, 2019
e7bb44b
Merge remote-tracking branch 'origin/master' into schema-refactor-new
freiksenet Feb 14, 2019
d002f9c
Restore prepare-nodes improvements
freiksenet Feb 14, 2019
73a1f2d
Fixes
freiksenet Feb 14, 2019
448bcfe
Port more tests (#11757)
stefanprobst Feb 14, 2019
2c0b2cf
Merge remote-tracking branch 'origin/master' into schema-refactor-new
freiksenet Feb 14, 2019
292200f
WIP kitchen sink
freiksenet Feb 14, 2019
1cb0aab
Fix tests for Loki, and minor changes (#11765)
stefanprobst Feb 15, 2019
e512743
Satisfy linter
freiksenet Feb 15, 2019
017bfa1
Mix dates and strings behaviour
freiksenet Feb 15, 2019
ccb0bb6
Test more stuff with runQuery
freiksenet Feb 15, 2019
58297c7
Add resolvers test
freiksenet Feb 15, 2019
1d4272e
Updated API names to match gatsby
freiksenet Feb 18, 2019
7666727
3rd party schema tests
freiksenet Feb 18, 2019
7e0261f
More fixes
freiksenet Feb 18, 2019
7f661eb
Beter example in using-type-defs
freiksenet Feb 18, 2019
3ddcf99
More fixes
freiksenet Feb 18, 2019
ff85e86
Add NodeModel tests (#11880)
stefanprobst Feb 19, 2019
31b11f3
[schema] Better example (#11892)
stefanprobst Feb 19, 2019
0c5e13a
Fix conflicting field issue
freiksenet Feb 19, 2019
a440e8e
Handle multiple return values from setFieldsOnGraphQLNodeType (#12048)
stefanprobst Feb 25, 2019
c310140
Fix conflicting fields priority on nested type (#11900)
stefanprobst Feb 25, 2019
c6a7826
Merge remote-tracking branch 'upstream/master' into schema-refactor-new
stefanprobst Feb 26, 2019
4dfc057
Allow field type on third-party type (#11970)
stefanprobst Feb 27, 2019
879cd7b
Make original field resolver available on info (#12159)
stefanprobst Feb 28, 2019
fbfa6b4
[schema] Make output fields non-null (#12097)
stefanprobst Feb 28, 2019
a1c01a6
[schema] Add schema query tests, inference fixes (#12190)
stefanprobst Mar 1, 2019
e344292
[schema] Add default page dependency path (#12220)
stefanprobst Mar 1, 2019
5db668a
Merge remote-tracking branch 'origin/master' into schema-refactor-new
freiksenet Mar 4, 2019
9992c12
chore(release): Publish
freiksenet Mar 4, 2019
ab9ffac
More tests and some fixes
freiksenet Mar 4, 2019
6cc1992
Revert "chore(release): Publish"
freiksenet Mar 4, 2019
b90b05f
Allow custom resolveType (#12309)
stefanprobst Mar 5, 2019
238cc2b
v2.2.0-alpha.0
freiksenet Mar 4, 2019
b706829
More fixes and tests
freiksenet Mar 5, 2019
9269305
More tests, refine infer logic
freiksenet Mar 5, 2019
52d6012
[schema] Make id field on InputObjectType type String (#12335)
stefanprobst Mar 6, 2019
1e58b54
v2.2.0-alpha.1
freiksenet Mar 5, 2019
7eda0b2
Upgrade schema composer
freiksenet Mar 6, 2019
222f3da
v2.2.0-alpha.2
freiksenet Mar 6, 2019
e76e7e8
Fix loxi test issue
freiksenet Mar 6, 2019
fe5fe1d
Add type builders internally
freiksenet Mar 6, 2019
081fa15
Add type builders internally
freiksenet Mar 6, 2019
f3a7cf6
Added type builders to the API
freiksenet Mar 6, 2019
5522c28
v2.2.0-alpha.3
freiksenet Mar 6, 2019
67ee427
[schema] Add NodeModel docs (#12354)
stefanprobst Mar 7, 2019
8628a48
Check for type names reserved for internal use (#12373)
stefanprobst Mar 7, 2019
4e09a7d
Allow custom scalars in input filter (#12375)
stefanprobst Mar 7, 2019
3e06835
Correctly camelcase connections (#12378)
stefanprobst Mar 7, 2019
587e9ef
v2.2.0-alpha.4
freiksenet Mar 7, 2019
16dab78
v2.2.0-alpha.5
freiksenet Mar 7, 2019
5a9a5f0
[schema] Remove empty input fields (#12380)
stefanprobst Mar 8, 2019
6c86d28
[schema] Add code frame to SDL parsing error (#12401)
stefanprobst Mar 8, 2019
ef567f0
Merge branch 'master' into schema-refactor-new
freiksenet Mar 8, 2019
582bd94
v2.2.0-alpha.6
freiksenet Mar 8, 2019
d61a776
Add blog post
freiksenet Mar 12, 2019
3f3e8fe
Don't use npx in example README
muescha Mar 16, 2019
71c391f
Update docs for new documentationjs version (#12615)
stefanprobst Mar 18, 2019
75da5e5
Merge remote-tracking branch 'origin/master' into schema-refactor-new
freiksenet Mar 18, 2019
1bc4013
v2.2.0-rc.1
freiksenet Mar 18, 2019
0a3a750
Revert "v2.2.0-rc.1"
freiksenet Mar 18, 2019
59a2dd2
Remove extra dep
freiksenet Mar 18, 2019
511abb3
Fix date
freiksenet Mar 18, 2019
f46154b
chore(blog): add schema customization blog post release (#12522)
DSchau Mar 18, 2019
582db20
Update blog as per review
freiksenet Mar 18, 2019
50ed38b
Docs
freiksenet Mar 18, 2019
4a6b108
Update docs/blog/2019-03-18-releasing-new-schema-customization/index.md
stefanprobst Mar 18, 2019
ecf5656
Add tweet
freiksenet Mar 18, 2019
0a48280
Update docs/blog/2019-03-18-releasing-new-schema-customization/index.md
stefanprobst Mar 18, 2019
3f2c4a0
Merge remote-tracking branch 'origin/master' into schema-refactor-new
freiksenet Mar 18, 2019
5c2b25a
Remove dep
stefanprobst Mar 18, 2019
c7c7ae0
Move tweet
freiksenet Mar 18, 2019
78cbab4
[schema] Ignore empty strings in example value creation (#12646)
stefanprobst Mar 19, 2019
7d48322
Add tests
freiksenet Mar 19, 2019
196ef58
Fix snapshot
freiksenet Mar 19, 2019
09f0d91
v2.2.0-rc.2
freiksenet Mar 19, 2019
4dcb431
Revert "v2.2.0-rc.2"
freiksenet Mar 19, 2019
54ff3b6
Change blog date
freiksenet Mar 19, 2019
04f7694
use <PROJECT_ROOT> in fixture (#12662)
pieh Mar 19, 2019
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
1 change: 1 addition & 0 deletions examples/gatsbygram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"gatsby-transformer-json": "^2.1.1",
"gatsby-transformer-sharp": "^2.1.1",
"glamor": "^2.20.40",
"graphql-compose": "^5.10.1",
"instagram-screen-scrape": "^2.0.0",
"lodash": "^4.17.10",
"mkdirp": "^0.5.1",
Expand Down
72 changes: 25 additions & 47 deletions packages/gatsby-transformer-remark/src/__tests__/extend-node.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
const {
graphql,
GraphQLObjectType,
GraphQLList,
GraphQLSchema,
} = require(`gatsby/graphql`)
const { graphql } = require(`gatsby/graphql`)
const { onCreateNode } = require(`../gatsby-node`)
const {
inferObjectStructureFromNodes,
} = require(`../../../gatsby/src/schema/infer-graphql-type`)
const extendNodeType = require(`../extend-node-type`)

// given a set of nodes and a query, return the result of the query
async function queryResult(
nodes,
fragment,
{ types = [] } = {},
{ additionalParameters = {}, pluginOptions = {} }
) {
const inferredFields = inferObjectStructureFromNodes({
nodes,
types: [...types],
})
const extendNodeTypeFields = await extendNodeType(
{
type: { name: `MarkdownRemark` },
Expand All @@ -37,32 +24,27 @@ async function queryResult(
}
)

const markdownRemarkFields = {
...inferredFields,
...extendNodeTypeFields,
}

const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: `RootQueryType`,
fields: () => {
return {
listNode: {
name: `LISTNODE`,
type: new GraphQLList(
new GraphQLObjectType({
name: `MarkdownRemark`,
fields: markdownRemarkFields,
})
),
resolve() {
return nodes
},
},
}
},
}),
const { SchemaComposer } = require(`graphql-compose`)
const {
addInferredFields,
} = require(`../../../gatsby/src/schema/infer/infer`)
const {
getExampleValue,
} = require(`../../../gatsby/src/schema/infer/example-value`)

const sc = new SchemaComposer()
const typeName = `MarkdownRemark`
const tc = sc.createTC(typeName)
addInferredFields({
schemaComposer: sc,
typeComposer: tc,
exampleValue: getExampleValue({ nodes, typeName }),
})
tc.addFields(extendNodeTypeFields)
sc.Query.addFields({
listNode: { type: [tc], resolve: () => nodes },
})
const schema = sc.buildSchema()

const result = await graphql(
schema,
Expand Down Expand Up @@ -97,14 +79,10 @@ const bootstrapTest = (
it(label, async done => {
node.content = content
const createNode = markdownNode => {
queryResult(
[markdownNode],
query,
{
types: [{ name: `MarkdownRemark` }],
},
{ additionalParameters, pluginOptions }
).then(result => {
queryResult([markdownNode], query, {
additionalParameters,
pluginOptions,
}).then(result => {
try {
test(result.data.listNode[0])
done()
Expand Down
62 changes: 23 additions & 39 deletions packages/gatsby-transformer-remark/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
const Promise = require(`bluebird`)
const _ = require(`lodash`)
const { graphql } = require(`gatsby/graphql`)

const { onCreateNode } = require(`../gatsby-node`)

const {
graphql,
GraphQLObjectType,
GraphQLList,
GraphQLSchema,
} = require(`gatsby/graphql`)
const {
inferObjectStructureFromNodes,
} = require(`../../../gatsby/src/schema/infer-graphql-type`)

describe(`Process markdown content correctly`, () => {
const node = {
id: `whatever`,
Expand Down Expand Up @@ -105,31 +95,27 @@ Sed bibendum sem iaculis, pellentesque leo sed, imperdiet ante. Sed consequat ma

describe(`process graphql correctly`, () => {
// given a set of nodes and a query, return the result of the query
async function queryResult(nodes, fragment, { types = [] } = {}) {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: `RootQueryType`,
fields: () => {
return {
listNode: {
name: `LISTNODE`,
type: new GraphQLList(
new GraphQLObjectType({
name: `MarkdownRemark`,
fields: inferObjectStructureFromNodes({
nodes,
types: [...types],
}),
})
),
resolve() {
return nodes
},
},
}
},
}),
async function queryResult(nodes, fragment) {
const { SchemaComposer } = require(`graphql-compose`)
const {
addInferredFields,
} = require(`../../../gatsby/src/schema/infer/infer`)
const {
getExampleValue,
} = require(`../../../gatsby/src/schema/infer/example-value`)

const sc = new SchemaComposer()
const typeName = `MarkdownRemark`
const tc = sc.createTC(typeName)
addInferredFields({
schemaComposer: sc,
typeComposer: tc,
exampleValue: getExampleValue({ nodes, typeName }),
})
sc.Query.addFields({
listNode: { type: [tc], resolve: () => nodes },
})
const schema = sc.buildSchema()

const result = await graphql(
schema,
Expand Down Expand Up @@ -172,8 +158,7 @@ Sed bibendum sem iaculis, pellentesque leo sed, imperdiet ante. Sed consequat ma
frontmatter {
title
}
`,
{ types: [{ name: `MarkdownRemark` }] }
`
).then(result => {
try {
createdNode = result.data.listNode[0]
Expand Down Expand Up @@ -233,8 +218,7 @@ Sed bibendum sem iaculis, pellentesque leo sed, imperdiet ante. Sed consequat ma
frontmatter {
title
}
`,
{ types: [{ name: `MarkdownRemark` }] }
`
).then(result => {
try {
createdNode = result.data.listNode[0]
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"graphql-playground-middleware-express": "^1.7.10",
"graphql-relay": "^0.6.0",
"graphql-skip-limit": "^2.0.5",
"graphql-compose": "^5.7.0",
"graphql-compose": "^5.10.1",
"graphql-tools": "^3.0.4",
"graphql-type-json": "^0.2.1",
"hash-mod": "^0.0.5",
Expand Down
7 changes: 2 additions & 5 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getConfigFile = require(`./get-config-file`)
const tracer = require(`opentracing`).globalTracer()
const preferDefault = require(`./prefer-default`)
const nodeTracking = require(`../db/node-tracking`)
const nodeStore = require(`../db/nodes`)
const withResolverContext = require(`../schema/context`)
require(`../db`).startAutosave()

// Show stack trace on unhandled promises.
Expand Down Expand Up @@ -390,10 +390,7 @@ module.exports = async (args: BootstrapArgs) => {
schema,
query,
context,
{
...context,
nodeModel: nodeStore,
},
withResolverContext(context),
context
)
}
Expand Down
6 changes: 2 additions & 4 deletions packages/gatsby/src/commands/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const launchEditor = require(`react-dev-utils/launchEditor`)
const formatWebpackMessages = require(`react-dev-utils/formatWebpackMessages`)
const chalk = require(`chalk`)
const address = require(`address`)
const nodeStore = require(`../db/nodes`)
const withResolverContext = require(`../schema/context`)
const sourceNodes = require(`../utils/source-nodes`)
const websocketManager = require(`../utils/websocket-manager`)
const getSslCert = require(`../utils/get-ssl-cert`)
Expand Down Expand Up @@ -109,9 +109,7 @@ async function startServer(program) {
graphqlHTTP({
schema: store.getState().schema,
graphiql: process.env.GATSBY_GRAPHQL_IDE === `playground` ? false : true,
context: {
nodeModel: nodeStore,
},
context: withResolverContext(),
})
)

Expand Down
19 changes: 15 additions & 4 deletions packages/gatsby/src/db/__tests__/node-tracking-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const {
} = require(`../../redux/actions`)
const { getNode } = require(`../../db/nodes`)
const { findRootNodeAncestor, trackDbNodes } = require(`../node-tracking`)
const nodeTypes = require(`../../schema/build-node-types`)
const { run: runQuery } = require(`../nodes-query`)
require(`./fixtures/ensure-loki`)()

Expand All @@ -18,7 +17,7 @@ function makeNode() {
},
inlineArray: [1, 2, 3],
internal: {
type: `TestNode`,
type: `Test`,
contentDigest: `digest1`,
owner: `test`,
},
Expand All @@ -43,7 +42,7 @@ describe(`track root nodes`, () => {
},
inlineArray: [1, 2, 3],
internal: {
type: `TestNode`,
type: `Test`,
contentDigest: `digest2`,
},
},
Expand Down Expand Up @@ -89,7 +88,19 @@ describe(`track root nodes`, () => {
let type

beforeAll(async () => {
type = (await nodeTypes.buildAll({})).testNode.nodeObjectType
const { SchemaComposer } = require(`graphql-compose`)
const { addInferredFields } = require(`../../schema/infer/infer`)
const { getExampleValue } = require(`../../schema/infer/example-value`)

const sc = new SchemaComposer()
const typeName = `Test`
const tc = sc.createTC(typeName)
addInferredFields({
schemaComposer: sc,
typeComposer: tc,
exampleValue: getExampleValue({ nodes: [makeNode()], typeName }),
})
type = tc.getType()
})

it(`Tracks objects when running query without filter`, async () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/gatsby/src/db/loki/__tests__/nodes-query-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (process.env.GATSBY_DB_NODES === `loki`) {
const _ = require(`lodash`)
const nodeTypes = require(`../../../schema/build-node-types`)
const { GraphQLObjectType } = require(`graphql`)
const { store } = require(`../../../redux`)
const runQuery = require(`../nodes-query`)
const { getNodeTypeCollection } = require(`../nodes`)
Expand All @@ -21,11 +21,11 @@ if (process.env.GATSBY_DB_NODES === `loki`) {
for (const node of nodes) {
store.dispatch({ type: `CREATE_NODE`, payload: node })
}
const gqlType = nodeTypes.buildNodeObjectType({
typeName: `Test`,
nodes,
pluginFields: [],
processedTypes: {},
const gqlType = new GraphQLObjectType({
name: `Test`,
fields: {
foo: { type: `String` },
},
})
const queryArgs = { filter: { foo: { eq: `bar` } } }
const args = { gqlType, queryArgs }
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/db/loki/nodes-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function ensureFieldIndexes(coll, lokiArgs) {
* @returns {promise} A promise that will eventually be resolved with
* a collection of matching objects (even if `firstOnly` is true)
*/
async function runQuery({ gqlType, queryArgs, context = {}, firstOnly }) {
async function runQuery({ gqlType, queryArgs, firstOnly }) {
// Clone args as for some reason graphql-js removes the constructor
// from nested objects which breaks a check in sift.js.
const gqlArgs = JSON.parse(JSON.stringify(queryArgs))
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/db/loki/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function getNodesByType(typeName) {
*/
function getNodes() {
const nodeTypes = getTypes()
return _.flatMap(nodeTypes, nodeType => getNodesByType(nodeType.type))
return _.flatMap(nodeTypes, nodeType => getNodesByType(nodeType))
}

/**
Expand Down
Loading