-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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): Move page component state & side effect handling to xstate #11897
Changes from 4 commits
d61316e
5db0b2c
2abcb2c
799391f
bbbd20b
5f53d33
d8fb163
97226e6
9347c2f
d242435
a124367
aaf8bf3
53eea1c
0e4d4df
df226de
6f60428
8631558
e5525b4
647b2dd
c3bb339
3e0ddcf
9343d8e
0e4c346
fd4edaa
50e9b0f
0066cad
10298a4
b98ea2a
836ef5e
3b2006f
4f994f6
2fb8794
1d3074f
cb23533
beebbea
17d34d9
37baf68
5100484
a8c32e1
9daeae2
c299ae6
36bda2e
1adc63d
7932e8e
f4bb7c2
20fcf49
03f4b37
8dfe393
cedc761
b3fd97b
83eedb2
76475f5
67ef857
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,21 +55,22 @@ function formatError(message: string, filePath: string, codeFrame: string) { | |
} | ||
|
||
function extractError(error: Error): { message: string, docName: string } { | ||
const docRegex = /Invariant Violation: (RelayParser|GraphQLParser): (.*). Source: document `(.*)` file:/g | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regex broke when we moved to Relay Compiler v2. |
||
const docRegex = /Error:.(RelayParser|GraphQLParser):(.*)Source: document.`(.*)`.file.*(GraphQL.request.*^\s*$)/gms | ||
let matches | ||
let message = ``, | ||
docName = `` | ||
let message = `` | ||
let docName = `` | ||
let codeBlock = `` | ||
while ((matches = docRegex.exec(error.toString())) !== null) { | ||
// This is necessary to avoid infinite loops with zero-width matches | ||
if (matches.index === docRegex.lastIndex) docRegex.lastIndex++ | ||
;[, , message, docName] = matches | ||
;[, , message, docName, codeBlock] = matches | ||
} | ||
|
||
if (!message) { | ||
message = error.toString() | ||
} | ||
|
||
return { message, docName } | ||
return { message, codeBlock, docName } | ||
} | ||
|
||
function findLocation(extractedMessage, def) { | ||
|
@@ -169,15 +170,12 @@ export function graphqlError( | |
nameDefMap: Map<string, any>, | ||
error: Error | RelayGraphQLError | ||
) { | ||
let { message, docName } = extractError(error) | ||
let { message, docName, codeBlock } = extractError(error) | ||
let filePath = namePathMap.get(docName) | ||
|
||
if (filePath && docName) { | ||
return formatError( | ||
message, | ||
filePath, | ||
getCodeFrameFromRelayError(nameDefMap.get(docName), message, error) | ||
) | ||
const formattedMessage = formatError(message, filePath, codeBlock) | ||
return { formattedMessage, docName, message, codeBlock } | ||
} | ||
|
||
let reportedMessage = `There was an error while compiling your site's GraphQL queries. | ||
|
@@ -194,5 +192,5 @@ export function graphqlError( | |
reportedMessage += `${error.message.slice(21)}\n` | ||
} | ||
|
||
return reportedMessage | ||
return { formattedMessage: reportedMessage, docName, message, codeBlock } | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1142,6 +1142,65 @@ actions.addThirdPartySchema = ( | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* | ||||||||||
* Report that a query has been extracted from a component. Used by | ||||||||||
* query-compilier.js. | ||||||||||
* | ||||||||||
* @param {Object} $0 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to use actions more for internal communication but don't want them all to show up here (https://www.gatsbyjs.org/docs/actions/) Thinking we could start marking actions as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm all for using actions more (and less event emitting). Can we move them to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hah, that's pretty much what we talked about yesterday. One idea is to have public-actions and private-actions files. Other could be, have extra export here: gatsby/packages/gatsby/src/redux/actions.js Lines 1186 to 1189 in 9e92a39
const boundActionCreators = bindActionCreators(actions, store.dispatch)
exports.boundActionCreators = boundActionCreators
/**
* This will be used in `api-runner-node.js`
*/
exports.publicBoundActionCreators = _.pick(boundActionCreators, [
`createNode`,
`createPage`,
// and all other actions that should be public
]) But it's not in scope for this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like just using pick :) |
||||||||||
* @param {componentPath} $0.componentPath The path to the component that just had | ||||||||||
* its query read. | ||||||||||
* @param {query} $0.query The GraphQL query that was extracted from the component. | ||||||||||
*/ | ||||||||||
actions.queryExtracted = ( | ||||||||||
{ componentPath, query }, | ||||||||||
plugin: Plugin, | ||||||||||
traceId?: string | ||||||||||
) => { | ||||||||||
return { | ||||||||||
type: `QUERY_EXTRACTED`, | ||||||||||
plugin, | ||||||||||
traceId, | ||||||||||
payload: { componentPath, query }, | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* | ||||||||||
* Report that the Relay Compilier found an error when extracting a query | ||||||||||
* | ||||||||||
* @param {Object} $0 | ||||||||||
* @param {componentPath} $0.componentPath The path to the component that just had | ||||||||||
* its query read. | ||||||||||
* @param {error} $0.query The GraphQL query that was extracted from the component. | ||||||||||
*/ | ||||||||||
actions.queryGraphQLError = ( | ||||||||||
{ componentPath, error }, | ||||||||||
plugin: Plugin, | ||||||||||
traceId?: string | ||||||||||
) => { | ||||||||||
return { | ||||||||||
type: `QUERY_GRAPHQL_ERROR`, | ||||||||||
plugin, | ||||||||||
traceId, | ||||||||||
payload: { componentPath, error }, | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Set overall program status. | ||||||||||
* | ||||||||||
* @param {string} Program status | ||||||||||
*/ | ||||||||||
actions.setProgramStatus = (status, plugin: Plugin, traceId?: string) => { | ||||||||||
return { | ||||||||||
type: `SET_PROGRAM_STATUS`, | ||||||||||
plugin, | ||||||||||
traceId, | ||||||||||
payload: status, | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* All action creators wrapped with a dispatch. | ||||||||||
*/ | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that'd make more sense 👍