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(schema): Inference controls and improvements #13028

Merged
merged 35 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ff596b9
WIP inference changes
freiksenet Mar 29, 2019
a88165c
Fixed all inferrence issues
freiksenet Apr 2, 2019
494f2e5
Reorder adding fields so field name resolving happens first
freiksenet Apr 2, 2019
b1fff33
Warnings and addResolver directives
freiksenet Apr 2, 2019
0ded10d
Kitchen sink tests
freiksenet Apr 3, 2019
354f11e
More fixes
freiksenet Apr 4, 2019
774ada4
Mapping via extensions
freiksenet Apr 4, 2019
ffa3960
Remove unused code
freiksenet Apr 4, 2019
fd57bb5
Fix comment
freiksenet Apr 4, 2019
5a6320f
Simplify some code, make some other code very complicated
freiksenet Apr 5, 2019
d065cb6
v2.4.0-alpha.1
freiksenet Apr 5, 2019
978e22e
Fix review comments
freiksenet Apr 5, 2019
1c2a501
[schema] Simplify type merging (#13557)
stefanprobst Apr 23, 2019
ce07eb1
Merge remote-tracking branch 'origin/master' into infer-fixing
freiksenet Apr 23, 2019
9ca160e
v2.4.0-alpha.2
freiksenet Apr 23, 2019
17d7857
More consistent naming
freiksenet Apr 24, 2019
c18d1e9
Ensure link() default arg (#13591)
stefanprobst Apr 24, 2019
9b2be71
[schema] Clarify warning message (#13693)
stefanprobst Apr 29, 2019
e40f6d2
Allow registering field extensions (#13623)
stefanprobst Apr 30, 2019
0a53e22
Revert "Allow registering field extensions (#13623)" (#13735)
stefanprobst Apr 30, 2019
9bad5a4
v2.4.0-alpha.3
freiksenet Apr 29, 2019
06b612a
Add blog post
freiksenet May 2, 2019
446c60a
Update docs
freiksenet May 2, 2019
2bcdc40
Fix link
freiksenet May 2, 2019
f2e1986
Improve docs
freiksenet May 2, 2019
5bf9bb8
[schema] Allow registering custom field extensions (#13738)
stefanprobst May 14, 2019
b8b96f9
Merge remote-tracking branch 'origin/master' into infer-fixing
freiksenet May 14, 2019
aee5186
Fix all addResolver uses
freiksenet May 15, 2019
daa2af3
v2.5.0-rc.1
freiksenet May 15, 2019
65e7504
Fix blog post
freiksenet May 15, 2019
b6c61e5
Apply suggestions from code review
freiksenet May 15, 2019
e76784c
Update packages/gatsby/src/redux/actions.js
stefanprobst May 15, 2019
69f179a
Update packages/gatsby/src/redux/actions.js
stefanprobst May 15, 2019
f338bdd
More blog post improvements
freiksenet May 15, 2019
1af8600
Merge branch 'master' into infer-fixing
freiksenet May 16, 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
4 changes: 2 additions & 2 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby",
"description": "Blazing fast modern site generator for React",
"version": "2.3.5",
"version": "2.4.0-alpha.1",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"bin": {
"gatsby": "./dist/bin/gatsby.js"
Expand Down Expand Up @@ -71,7 +71,7 @@
"gatsby-telemetry": "^1.0.4",
"glob": "^7.1.1",
"graphql": "^14.1.1",
"graphql-compose": "^6.0.3",
"graphql-compose": "^6.1.4",
"graphql-playground-middleware-express": "^1.7.10",
"graphql-relay": "^0.6.0",
"graphql-tools": "^3.0.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Object {
"_3invalidKey": null,
"code": "BShF_8qhtEv",
"comment": 0,
"defaultTime": "05 huhtikuu",
"id": "1486495736706552111",
"idWithDecoration": "decoration-1486495736706552111",
"image": Object {
Expand All @@ -51,6 +52,8 @@ Object {
},
},
"likes": 8,
"localeFormat": "05 huhtikuu 2017",
"localeString": "05 апреля",
"time": "05.04.2017",
},
},
Expand All @@ -59,6 +62,7 @@ Object {
"_3invalidKey": null,
"code": "BY6B8z5lR1F",
"comment": 0,
"defaultTime": "11 syyskuu",
"id": "1601601194425654597",
"idWithDecoration": "decoration-1601601194425654597",
"image": Object {
Expand All @@ -67,6 +71,8 @@ Object {
},
},
"likes": 9,
"localeFormat": "11 syyskuu 2017",
"localeString": "11 сентября",
"time": "11.09.2017",
},
},
Expand Down
8 changes: 6 additions & 2 deletions packages/gatsby/src/schema/__tests__/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ describe(`Kichen sink schema test`, () => {
store.dispatch({
type: `CREATE_TYPES`,
payload: `
type PostsJson implements Node {
type PostsJson implements Node @infer {
id: String!
time: Date
time: Date @addResolver(type: "date", options: { defaultLocale: "fi", defaultFormat: "DD MMMM"})
code: String
image: File @addResolver(type: "relativeFile")
}
`,
})
Expand All @@ -72,6 +73,9 @@ describe(`Kichen sink schema test`, () => {
id
idWithDecoration
time(formatString: "DD.MM.YYYY")
localeString: time(locale: "ru")
localeFormat: time(formatString: "DD MMMM YYYY")
defaultTime: time
code
likes
comment
Expand Down
84 changes: 84 additions & 0 deletions packages/gatsby/src/schema/add-field-resolvers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const _ = require(`lodash`)
const { defaultFieldResolver } = require(`graphql`)
const { dateResolver } = require(`./types/date`)
const { link, fileByPath } = require(`./resolvers`)

export const addFieldResolvers = ({
schemaComposer,
typeComposer,
parentSpan,
}) => {
typeComposer.getFieldNames().forEach(fieldName => {
let field = typeComposer.getField(fieldName)

const extensions = typeComposer.getFieldExtensions(fieldName)
if (
!field.resolve &&
extensions.addResolver &&
_.isObject(extensions.addResolver)
) {
const options = extensions.addResolver.options || {}
switch (extensions.addResolver.type) {
case `date`: {
addDateResolver({
typeComposer,
fieldName,
options,
})
break
}
case `link`: {
typeComposer.extendField(fieldName, {
stefanprobst marked this conversation as resolved.
Show resolved Hide resolved
resolve: link({ from: options.from, by: options.by }),
})
break
}
case `relativeFile`: {
typeComposer.extendField(fieldName, {
resolve: fileByPath({ from: options.from }),
})
break
}
}
}

if (extensions.proxyFrom) {
// XXX(freiksenet): get field again cause it will be changed because of above
field = typeComposer.getField(fieldName)
const resolver = field.resolve || defaultFieldResolver
typeComposer.extendField(fieldName, {
resolve: (source, args, context, info) =>
resolver(source, args, context, {
...info,
fieldName: extensions.proxyFrom,
}),
})
}
})
return typeComposer
}

const addDateResolver = ({
typeComposer,
fieldName,
options: { defaultFormat, defaultLocale },
}) => {
const field = typeComposer.getField(fieldName)

let fieldConfig = {
resolve: dateResolver.resolve,
}
if (!field.args || _.isEmpty(field.args)) {
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
fieldConfig.args = {
...dateResolver.args,
}
if (defaultFormat) {
fieldConfig.args.formatString.defaultValue = defaultFormat
}
if (defaultLocale) {
fieldConfig.args.locale.defaultValue = defaultLocale
}
}

typeComposer.extendField(fieldName, fieldConfig)
}
Loading