UNPKG

38.9 kBTypeScriptView Raw
1import * as React from "react"
2import { EventEmitter } from "events"
3import { WindowLocation, NavigateFn } from "@reach/router"
4import { createContentDigest } from "gatsby-core-utils"
5import {
6 ComposeEnumTypeConfig,
7 ComposeInputObjectTypeConfig,
8 ComposeInterfaceTypeConfig,
9 ComposeObjectTypeConfig,
10 ComposeScalarTypeConfig,
11 ComposeUnionTypeConfig,
12} from "graphql-compose"
13import { GraphQLOutputType } from "graphql"
14
15export {
16 default as Link,
17 GatsbyLinkProps,
18 navigate,
19 navigateTo,
20 push,
21 replace,
22 withPrefix,
23 withAssetPrefix,
24} from "gatsby-link"
25
26export const useStaticQuery: <TData = any>(query: any) => TData
27
28export const parsePath: (path: string) => WindowLocation
29
30export const prefetchPathname: (path: string) => void
31
32export interface PageRendererProps {
33 location: WindowLocation
34}
35
36/**
37 * PageRenderer's constructor [loads the page resources](https://www.gatsbyjs.org/docs/production-app/#load-page-resources) for the path.
38 *
39 * On first load though, these will have already been requested from the server by `<link rel="preload" ... />` in the page's original HTML (see [Link Preloads](https://www.gatsbyjs.org/docs/how-code-splitting-works/#construct-link-and-script-tags-for-current-page) in HTML Generation Docs).
40 * The loaded page resources includes the imported component, with which we create the actual page component using [React.createElement()](https://reactjs.org/docs/react-api.html). This element is returned to our RouteHandler which hands it off to Reach Router for rendering.
41 *
42 * @see https://www.gatsbyjs.org/docs/production-app/#page-rendering
43 */
44export class PageRenderer extends React.Component<PageRendererProps> {}
45
46type RenderCallback<T = any> = (data: T) => React.ReactNode
47
48export interface StaticQueryProps<T = any> {
49 query: any
50 render?: RenderCallback<T>
51 children?: RenderCallback<T>
52}
53
54/**
55 * StaticQuery can do most of the things that page query can, including fragments. The main differences are:
56 *
57 * - page queries can accept variables (via `pageContext`) but can only be added to _page_ components
58 * - StaticQuery does not accept variables (hence the name "static"), but can be used in _any_ component, including pages
59 * - StaticQuery does not work with raw React.createElement calls; please use JSX, e.g. `<StaticQuery />`
60 *
61 * @see https://www.gatsbyjs.org/docs/static-query/
62 */
63
64export class StaticQuery<T = any> extends React.Component<
65 StaticQueryProps<T>
66> {}
67
68/**
69 * graphql is a tag function. Behind the scenes Gatsby handles these tags in a particular way
70 *
71 * During the Gatsby build process, GraphQL queries are pulled out of the original source for parsing.
72 *
73 * @see https://www.gatsbyjs.org/docs/page-query#how-does-the-graphql-tag-work
74 */
75export const graphql: (query: TemplateStringsArray) => void
76
77/**
78 * Gatsby configuration API.
79 *
80 * @see https://www.gatsbyjs.org/docs/gatsby-config/
81 */
82export interface GatsbyConfig {
83 /** When you want to reuse common pieces of data across the site (for example, your site title), you can store that here. */
84 siteMetadata?: Record<string, unknown>
85 /** Plugins are Node.js packages that implement Gatsby APIs. The config file accepts an array of plugins. Some plugins may need only to be listed by name, while others may take options. */
86 plugins?: Array<
87 | string
88 | {
89 resolve: string
90 options: Record<string, unknown>
91 }
92 >
93 /** It’s common for sites to be hosted somewhere other than the root of their domain. Say we have a Gatsby site at `example.com/blog/`. In this case, we would need a prefix (`/blog`) added to all paths on the site. */
94 pathPrefix?: string
95 /** Gatsby uses the ES6 Promise API. Because some browsers don't support this, Gatsby includes a Promise polyfill by default. If you'd like to provide your own Promise polyfill, you can set `polyfill` to false.*/
96 polyfill?: boolean
97 mapping?: Record<string, string>
98 /**
99 * Setting the proxy config option will tell the develop server to proxy any unknown requests to your specified server.
100 * @see https://www.gatsbyjs.org/docs/api-proxy/
101 * */
102 proxy?: {
103 prefix: string
104 url: string
105 }
106 /** Sometimes you need more granular/flexible access to the development server. Gatsby exposes the Express.js development server to your site’s gatsby-config.js where you can add Express middleware as needed. */
107 developMiddleware?(app: any): void
108}
109
110/**
111 * Gatsby API for Node.js.
112 *
113 * @see https://www.gatsbyjs.org/docs/node-apis/
114 */
115export interface GatsbyNode {
116 /**
117 * Tell plugins to add pages. This extension point is called only after the initial
118 * sourcing and transformation of nodes plus creation of the GraphQL schema are
119 * complete so you can query your data in order to create pages.
120 *
121 * @see https://www.gatsbyjs.org/docs/node-apis/#createPages
122 */
123 createPages?(
124 args: CreatePagesArgs & {
125 traceId: "initial-createPages"
126 },
127 options?: PluginOptions,
128 callback?: PluginCallback
129 ): void
130
131 /**
132 * Like `createPages` but for plugins who want to manage creating and removing
133 * pages themselves in response to changes in data *not* managed by Gatsby.
134 * Plugins implementing `createPages` will get called regularly to recompute
135 * page information as Gatsby's data changes but those implementing
136 * `createPagesStatefully` will not.
137 *
138 * An example of a plugin that uses this extension point is the plugin
139 * [gatsby-plugin-page-creator](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-page-creator)
140 * which monitors the `src/pages` directory for the adding and removal of JS
141 * pages. As its source of truth, files in the pages directory, is not known by
142 * Gatsby, it needs to keep its own state about its world to know when to
143 * add and remove pages.
144 */
145 createPagesStatefully?(
146 args: CreatePagesArgs & {
147 traceId: "initial-createPagesStatefully"
148 },
149 options?: PluginOptions,
150 callback?: PluginCallback
151 ): void
152
153 /**
154 * Let plugins extend/mutate the site's Babel configuration.
155 * This API will change before 2.0 as it needs still to be converted to use
156 * Redux actions.
157 */
158 onCreateBabelConfig?(
159 args: CreateBabelConfigArgs,
160 options?: PluginOptions,
161 callback?: PluginCallback
162 ): void
163
164 /**
165 * Run when gatsby develop server is started, its useful to add proxy and middleware
166 * to the dev server app
167 * @param {object} $0
168 * @param {Express} $0.app The [Express app](https://expressjs.com/en/4x/api.html#app) used to run the dev server
169 *
170 * @example
171 *
172 * exports.onCreateDevServer = ({ app }) => {
173 * app.get('/hello', function (req, res) {
174 * res.send('hello world')
175 * })
176 * }
177 */
178 onCreateDevServer?(
179 args: CreateDevServerArgs,
180 options?: PluginOptions,
181 callback?: PluginCallback
182 ): void
183
184 /**
185 * Called when a new node is created. Plugins wishing to extend or
186 * transform nodes created by other plugins should implement this API.
187 *
188 * See also the documentation for `createNode`
189 * and [`createNodeField`](https://www.gatsbyjs.org/docs/actions/#createNodeField)
190 * @example
191 * exports.onCreateNode = ({ node, actions }) => {
192 * const { createNode, createNodeField } = actions
193 * // Transform the new node here and create a new node or
194 * // create a new node field.
195 * }
196 */
197 onCreateNode?<TNode extends object = {}>(
198 args: CreateNodeArgs<TNode>,
199 options?: PluginOptions,
200 callback?: PluginCallback
201 ): void
202
203 /**
204 * Called when a new page is created. This extension API is useful
205 * for programmatically manipulating pages created by other plugins e.g.
206 * if you want paths without trailing slashes.
207 *
208 * See the guide [Creating and Modifying Pages](https://www.gatsbyjs.org/docs/creating-and-modifying-pages/)
209 * for more on this API.
210 */
211 onCreatePage?<TNode extends object = {}>(
212 args: CreatePageArgs<TNode>,
213 options?: PluginOptions,
214 callback?: PluginCallback
215 ): void
216
217 /**
218 * Let plugins extend/mutate the site's webpack configuration.
219 * @see https://www.gatsbyjs.org/docs/node-apis/#onCreateWebpackConfig
220 */
221 onCreateWebpackConfig?(
222 args: CreateWebpackConfigArgs,
223 options?: PluginOptions,
224 callback?: PluginCallback
225 ): void
226
227 /** Called at the end of the bootstrap process after all other extension APIs have been called. */
228 onPostBootstrap?(
229 args: ParentSpanPluginArgs,
230 options?: PluginOptions,
231 callback?: PluginCallback
232 ): void
233
234 /** The last extension point called after all other parts of the build process are complete. */
235 onPostBuild?(
236 args: BuildArgs,
237 options?: PluginOptions,
238 callback?: PluginCallback
239 ): void
240
241 /** Called at the end of the bootstrap process after all other extension APIs have been called. */
242 onPreBootstrap?(
243 args: ParentSpanPluginArgs,
244 options?: PluginOptions,
245 callback?: PluginCallback
246 ): void
247
248 /** The first extension point called during the build process. Called after the bootstrap has completed but before the build steps start. */
249 onPreBuild?(
250 args: BuildArgs,
251 options?: PluginOptions,
252 callback?: PluginCallback
253 ): void
254
255 /** Called once Gatsby has initialized itself and is ready to bootstrap your site. */
256 onPreExtractQueries?(
257 args: ParentSpanPluginArgs,
258 options?: PluginOptions,
259 callback?: PluginCallback
260 ): void
261
262 /** The first API called during Gatsby execution, runs as soon as plugins are loaded, before cache initialization and bootstrap preparation. */
263 onPreInit?(
264 args: ParentSpanPluginArgs,
265 options?: PluginOptions,
266 callback?: PluginCallback
267 ): void
268
269 /**
270 * Ask compile-to-js plugins to process source to JavaScript so the query
271 * runner can extract out GraphQL queries for running.
272 */
273 preprocessSource?(
274 args: PreprocessSourceArgs,
275 options?: PluginOptions,
276 callback?: PluginCallback
277 ): void
278
279 /**
280 * Lets plugins implementing support for other compile-to-js add to the list of "resolvable" file extensions. Gatsby supports `.js` and `.jsx` by default.
281 */
282 resolvableExtensions?(
283 args: ResolvableExtensionsArgs,
284 options: PluginOptions,
285 callback: PluginCallback
286 ): any[] | Promise<any[]>
287
288 /**
289 * Called during the creation of the GraphQL schema. Allows plugins
290 * to add new fields to the types created from data nodes. It will be called
291 * separately for each type.
292 *
293 * This function should return an object in the shape of
294 * [GraphQLFieldConfigMap](https://graphql.org/graphql-js/type/#graphqlobjecttype)
295 * which will be appended to fields inferred by Gatsby from data nodes.
296 *
297 * *Note:* Import GraphQL types from `gatsby/graphql` and don't add the `graphql`
298 * package to your project/plugin dependencies to avoid Schema must
299 * contain unique named types but contains multiple types named errors.
300 * `gatsby/graphql` exports all builtin GraphQL types as well as the `graphQLJSON`
301 * type.
302 *
303 * Many transformer plugins use this to add fields that take arguments.
304 *
305 * @see https://www.gatsbyjs.org/docs/node-apis/#setFieldsOnGraphQLNodeType
306 */
307 setFieldsOnGraphQLNodeType?(
308 args: SetFieldsOnGraphQLNodeTypeArgs,
309 options: PluginOptions
310 ): any
311 setFieldsOnGraphQLNodeType?(
312 args: SetFieldsOnGraphQLNodeTypeArgs,
313 options: PluginOptions
314 ): Promise<any>
315 setFieldsOnGraphQLNodeType?(
316 args: SetFieldsOnGraphQLNodeTypeArgs,
317 options: PluginOptions,
318 callback: PluginCallback
319 ): void
320
321 /**
322 * Extension point to tell plugins to source nodes. This API is called during
323 * the Gatsby bootstrap sequence. Source plugins use this hook to create nodes.
324 * This API is called exactly once per plugin (and once for your site's
325 * `gatsby-config.js` file). If you define this hook in `gatsby-node.js` it
326 * will be called exactly once after all of your source plugins have finished
327 * creating nodes.
328 *
329 * @see https://www.gatsbyjs.org/docs/node-apis/#sourceNodes
330 */
331 sourceNodes?(args: SourceNodesArgs, options: PluginOptions): any
332 sourceNodes?(args: SourceNodesArgs, options: PluginOptions): Promise<any>
333 sourceNodes?(
334 args: SourceNodesArgs,
335 options: PluginOptions,
336 callback: PluginCallback
337 ): void
338
339 /**
340 * Add custom field resolvers to the GraphQL schema.
341 *
342 * Allows adding new fields to types by providing field configs, or adding resolver
343 * functions to existing fields.
344 *
345 * Things to note:
346 * * Overriding field types is disallowed, instead use the `createTypes`
347 * action. In case of types added from third-party schemas, where this is not
348 * possible, overriding field types is allowed.
349 * * New fields will not be available on `filter` and `sort` input types. Extend
350 * types defined with `createTypes` if you need this.
351 * * In field configs, types can be referenced as strings.
352 * * When extending a field with an existing field resolver, the original
353 * resolver function is available from `info.originalResolver`.
354 * * The `createResolvers` API is called as the last step in schema generation.
355 * Thus, an intermediate schema is made available on the `schema` property.
356 * In resolver functions themselves, it is recommended to access the final
357 * built schema from `info.schema`.
358 * * Gatsby's data layer, including all internal query capabilities, is
359 * exposed on [`context.nodeModel`](/docs/node-model/). The node store can be
360 * queried directly with `getAllNodes`, `getNodeById` and `getNodesByIds`,
361 * while more advanced queries can be composed with `runQuery`. Note that
362 * `runQuery` will call field resolvers before querying, so e.g. foreign-key
363 * fields will be expanded to full nodes. The other methods on `nodeModel`
364 * don't do this.
365 * * It is possible to add fields to the root `Query` type.
366 * * When using the first resolver argument (`source` in the example below,
367 * often also called `parent` or `root`), take care of the fact that field
368 * resolvers can be called more than once in a query, e.g. when the field is
369 * present both in the input filter and in the selection set. This means that
370 * foreign-key fields on `source` can be either resolved or not-resolved.
371 *
372 * For fuller examples, see [`using-type-definitions`](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-type-definitions).
373 *
374 * @see https://www.gatsbyjs.org/docs/node-apis/#createResolvers
375 */
376 createResolvers?(args: CreateResolversArgs, options: PluginOptions): any
377 createResolvers?(
378 args: CreateResolversArgs,
379 options: PluginOptions
380 ): Promise<any>
381 createResolvers?(
382 args: CreateResolversArgs,
383 options: PluginOptions,
384 callback: PluginCallback
385 ): void
386
387 /**
388 * Customize Gatsby’s GraphQL schema by creating type definitions, field extensions or adding third-party schemas.
389 * The createTypes, createFieldExtension and addThirdPartySchema actions are only available in this API.
390 *
391 * For details on their usage please refer to the actions documentation.
392 *
393 * This API runs immediately before schema generation. For modifications of the generated schema, e.g.
394 * to customize added third-party types, use the createResolvers API.
395 * @see https://www.gatsbyjs.org/docs/node-apis/#createSchemaCustomization
396 */
397 createSchemaCustomization?(
398 args: CreateSchemaCustomizationArgs,
399 options: PluginOptions
400 ): any
401 createSchemaCustomization?(
402 args: CreateSchemaCustomizationArgs,
403 options: PluginOptions
404 ): Promise<any>
405 createSchemaCustomization?(
406 args: CreateSchemaCustomizationArgs,
407 options: PluginOptions,
408 callback: PluginCallback
409 ): void
410}
411
412/**
413 * Gatsby browser API.
414 *
415 * @see https://www.gatsbyjs.org/docs/browser-apis/
416 */
417export interface GatsbyBrowser {
418 disableCorePrefetching?(args: BrowserPluginArgs, options: PluginOptions): any
419 onClientEntry?(args: BrowserPluginArgs, options: PluginOptions): any
420 onInitialClientRender?(args: BrowserPluginArgs, options: PluginOptions): any
421 onPostPrefetchPathname?(
422 args: PrefetchPathnameArgs,
423 options: PluginOptions
424 ): any
425 onPreRouteUpdate?(args: RouteUpdateArgs, options: PluginOptions): any
426 onPrefetchPathname?(args: PrefetchPathnameArgs, options: PluginOptions): any
427 onRouteUpdate?(args: RouteUpdateArgs, options: PluginOptions): any
428 onRouteUpdateDelayed?(
429 args: RouteUpdateDelayedArgs,
430 options: PluginOptions
431 ): any
432 onServiceWorkerActive?(args: ServiceWorkerArgs, options: PluginOptions): any
433 onServiceWorkerInstalled?(
434 args: ServiceWorkerArgs,
435 options: PluginOptions
436 ): any
437 onServiceWorkerRedundant?(
438 args: ServiceWorkerArgs,
439 options: PluginOptions
440 ): any
441 onServiceWorkerUpdateFound?(
442 args: ServiceWorkerArgs,
443 options: PluginOptions
444 ): any
445 registerServiceWorker?(args: BrowserPluginArgs, options: PluginOptions): any
446 replaceComponentRenderer?(
447 args: ReplaceComponentRendererArgs,
448 options: PluginOptions
449 ): any
450 replaceHydrateFunction?(args: BrowserPluginArgs, options: PluginOptions): any
451 shouldUpdateScroll?(args: ShouldUpdateScrollArgs, options: PluginOptions): any
452 wrapPageElement?(
453 args: WrapPageElementBrowserArgs,
454 options: PluginOptions
455 ): any
456 wrapRootElement?(
457 args: WrapRootElementBrowserArgs,
458 options: PluginOptions
459 ): any
460}
461
462/**
463 * Gatsby server-side rendering API.
464 *
465 * @see https://www.gatsbyjs.org/docs/ssr-apis/
466 */
467export interface GatsbySSR {
468 /**
469 * Called after every page Gatsby server renders while building HTML so you can
470 * replace head components to be rendered in your `html.js`. This is useful if
471 * you need to reorder scripts or styles added by other plugins.
472 * @example
473 * // Move Typography.js styles to the top of the head section so they're loaded first.
474 * exports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
475 * const headComponents = getHeadComponents()
476 * headComponents.sort((x, y) => {
477 * if (x.key === 'TypographyStyle') {
478 * return -1
479 * } else if (y.key === 'TypographyStyle') {
480 * return 1
481 * }
482 * return 0
483 * })
484 * replaceHeadComponents(headComponents)
485 * }
486 */
487 onPreRenderHTML?(args: PreRenderHTMLArgs, options: PluginOptions): any
488 onPreRenderHTML?(
489 args: PreRenderHTMLArgs,
490 options: PluginOptions
491 ): Promise<any>
492 onPreRenderHTML?(
493 args: PreRenderHTMLArgs,
494 options: PluginOptions,
495 callback: PluginCallback
496 ): void
497
498 /**
499 * Called after every page Gatsby server renders while building HTML so you can
500 * set head and body components to be rendered in your `html.js`.
501 *
502 * Gatsby does a two-pass render for HTML. It loops through your pages first
503 * rendering only the body and then takes the result body HTML string and
504 * passes it as the `body` prop to your `html.js` to complete the render.
505 *
506 * It's often handy to be able to send custom components to your `html.js`.
507 * For example, it's a very common pattern for React.js libraries that
508 * support server rendering to pull out data generated during the render to
509 * add to your HTML.
510 *
511 * Using this API over `replaceRenderer` is preferable as
512 * multiple plugins can implement this API where only one plugin can take
513 * over server rendering. However, if your plugin requires taking over server
514 * rendering then that's the one to use
515 * @example
516 * const { Helmet } = require("react-helmet")
517 *
518 * exports.onRenderBody = (
519 * { setHeadComponents, setHtmlAttributes, setBodyAttributes },
520 * pluginOptions
521 * ) => {
522 * const helmet = Helmet.renderStatic()
523 * setHtmlAttributes(helmet.htmlAttributes.toComponent())
524 * setBodyAttributes(helmet.bodyAttributes.toComponent())
525 * setHeadComponents([
526 * helmet.title.toComponent(),
527 * helmet.link.toComponent(),
528 * helmet.meta.toComponent(),
529 * helmet.noscript.toComponent(),
530 * helmet.script.toComponent(),
531 * helmet.style.toComponent(),
532 * ])
533 * }
534 */
535 onRenderBody?(args: RenderBodyArgs, options: PluginOptions): any
536 onRenderBody?(args: RenderBodyArgs, options: PluginOptions): Promise<any>
537 onRenderBody?(
538 args: RenderBodyArgs,
539 options: PluginOptions,
540 callback: PluginCallback
541 ): void
542
543 /**
544 * Replace the default server renderer. This is useful for integration with
545 * Redux, css-in-js libraries, etc. that need custom setups for server
546 * rendering.
547 * @example
548 * // From gatsby-plugin-glamor
549 * const { renderToString } = require("react-dom/server")
550 * const inline = require("glamor-inline")
551 *
552 * exports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
553 * const bodyHTML = renderToString(bodyComponent)
554 * const inlinedHTML = inline(bodyHTML)
555 *
556 * replaceBodyHTMLString(inlinedHTML)
557 * }
558 */
559 replaceRenderer?(args: ReplaceRendererArgs, options: PluginOptions): any
560 replaceRenderer?(
561 args: ReplaceRendererArgs,
562 options: PluginOptions
563 ): Promise<any>
564 replaceRenderer?(
565 args: ReplaceRendererArgs,
566 options: PluginOptions,
567 callback: PluginCallback
568 ): void
569
570 /**
571 * Allow a plugin to wrap the page element.
572 *
573 * This is useful for setting wrapper component around pages that won't get
574 * unmounted on page change. For setting Provider components use `wrapRootElement`.
575 *
576 * _Note:_ [There is equivalent hook in Browser API](https://www.gatsbyjs.org/docs/browser-apis/#wrapPageElement)
577 * @example
578 * const React = require("react")
579 * const Layout = require("./src/components/layout")
580 *
581 * exports.wrapPageElement = ({ element, props }) => {
582 * // props provide same data to Layout as Page element will get
583 * // including location, data, etc - you don't need to pass it
584 * return <Layout {...props}>{element}</Layout>
585 * }
586 */
587 wrapPageElement?(args: WrapPageElementNodeArgs, options: PluginOptions): any
588 wrapPageElement?(
589 args: WrapPageElementNodeArgs,
590 options: PluginOptions
591 ): Promise<any>
592 wrapPageElement?(
593 args: WrapPageElementNodeArgs,
594 options: PluginOptions,
595 callback: PluginCallback
596 ): void
597 /**
598 * Allow a plugin to wrap the root element.
599 *
600 * This is useful to setup any Providers component that will wrap your application.
601 * For setting persistent UI elements around pages use `wrapPageElement`.
602 *
603 * _Note:_ [There is equivalent hook in Browser API](https://www.gatsbyjs.org/docs/browser-apis/#wrapRootElement)
604 * @example
605 * const React = require("react")
606 * const { Provider } = require("react-redux")
607 *
608 * const createStore = require("./src/state/createStore")
609 * const store = createStore()
610 *
611 * exports.wrapRootElement = ({ element }) => {
612 * return (
613 * <Provider store={store}>
614 * {element}
615 * </Provider>
616 * )
617 * }
618 */
619 wrapRootElement?(args: WrapRootElementNodeArgs, options: PluginOptions): any
620 wrapRootElement?(
621 args: WrapRootElementNodeArgs,
622 options: PluginOptions
623 ): Promise<any>
624 wrapRootElement?(
625 args: WrapRootElementNodeArgs,
626 options: PluginOptions,
627 callback: PluginCallback
628 ): void
629}
630
631export interface PluginOptions {
632 plugins: unknown[]
633 [key: string]: unknown
634}
635
636export type PluginCallback = (err: Error | null, result?: any) => void
637
638export interface CreatePagesArgs extends ParentSpanPluginArgs {
639 graphql<TData, TVariables = any>(
640 query: string,
641 variables?: TVariables
642 ): Promise<{
643 errors?: any
644 data?: TData
645 }>
646 traceId: string
647 waitForCascadingActions: boolean
648}
649
650type GatsbyStages =
651 | "develop"
652 | "develop-html"
653 | "build-javascript"
654 | "build-html"
655
656export interface CreateBabelConfigArgs extends ParentSpanPluginArgs {
657 stage: GatsbyStages
658}
659
660export interface CreateDevServerArgs extends ParentSpanPluginArgs {
661 app: any
662}
663
664export interface CreateNodeArgs<TNode extends object = {}>
665 extends ParentSpanPluginArgs {
666 node: Node & TNode
667 traceId: string
668 traceTags: {
669 nodeId: string
670 nodeType: string
671 }
672}
673
674export interface CreatePageArgs<TNode extends object = {}>
675 extends ParentSpanPluginArgs {
676 page: Node & TNode
677 traceId: string
678}
679
680export interface CreateWebpackConfigArgs extends ParentSpanPluginArgs {
681 getConfig: Function
682 stage: GatsbyStages
683 rules: WebpackRules
684 loaders: WebpackLoaders
685 plugins: WebpackPlugins
686}
687
688export interface PreprocessSourceArgs extends ParentSpanPluginArgs {
689 filename: string
690 contents: string
691}
692
693export interface ResolvableExtensionsArgs extends ParentSpanPluginArgs {
694 traceId: "initial-resolvableExtensions"
695}
696
697export interface SetFieldsOnGraphQLNodeTypeArgs extends ParentSpanPluginArgs {
698 type: {
699 name: string
700 nodes: any[]
701 }
702 traceId: "initial-setFieldsOnGraphQLNodeType"
703}
704
705export interface GatsbyGraphQLObjectType {
706 kind: "OBJECT"
707 config: ComposeObjectTypeConfig<any, any>
708}
709
710interface GatsbyGraphQLInputObjectType {
711 kind: "INPUT_OBJECT"
712 config: ComposeInputObjectTypeConfig
713}
714
715interface GatsbyGraphQLUnionType {
716 kind: "UNION"
717 config: ComposeUnionTypeConfig<any, any>
718}
719
720interface GatsbyGraphQLInterfaceType {
721 kind: "INTERFACE"
722 config: ComposeInterfaceTypeConfig<any, any>
723}
724
725interface GatsbyGraphQLEnumType {
726 kind: "ENUM"
727 config: ComposeEnumTypeConfig
728}
729
730interface GatsbyGraphQLScalarType {
731 kind: "SCALAR"
732 config: ComposeScalarTypeConfig
733}
734
735export type GatsbyGraphQLType =
736 | GatsbyGraphQLObjectType
737 | GatsbyGraphQLInputObjectType
738 | GatsbyGraphQLUnionType
739 | GatsbyGraphQLInterfaceType
740 | GatsbyGraphQLEnumType
741 | GatsbyGraphQLScalarType
742
743export interface NodePluginSchema {
744 buildObjectType(
745 config: ComposeObjectTypeConfig<any, any>
746 ): GatsbyGraphQLObjectType
747 buildUnionType(
748 config: ComposeUnionTypeConfig<any, any>
749 ): GatsbyGraphQLUnionType
750 buildInterfaceType(
751 config: ComposeInterfaceTypeConfig<any, any>
752 ): GatsbyGraphQLInterfaceType
753 buildInputObjectType(
754 config: ComposeInputObjectTypeConfig
755 ): GatsbyGraphQLInputObjectType
756 buildEnumType(config: ComposeEnumTypeConfig): GatsbyGraphQLEnumType
757 buildScalarType(config: ComposeScalarTypeConfig): GatsbyGraphQLScalarType
758}
759
760export interface SourceNodesArgs extends ParentSpanPluginArgs {
761 traceId: "initial-sourceNodes"
762 waitForCascadingActions: boolean
763}
764
765export interface CreateResolversArgs extends ParentSpanPluginArgs {
766 intermediateSchema: object
767 createResolvers: Function
768 traceId: "initial-createResolvers"
769}
770
771export interface CreateSchemaCustomizationArgs extends ParentSpanPluginArgs {
772 traceId: "initial-createSchemaCustomization"
773}
774
775export interface PreRenderHTMLArgs extends NodePluginArgs {
776 getHeadComponents: () => React.ReactNode[]
777 replaceHeadComponents: (comp: React.ReactNode[]) => void
778 getPreBodyComponents: () => React.ReactNode[]
779 replacePreBodyComponents: (comp: React.ReactNode[]) => void
780 getPostBodyComponents: () => React.ReactNode[]
781 replacePostBodyComponents: (comp: React.ReactNode[]) => void
782}
783
784type ReactProps<T extends Element> = React.DetailedHTMLProps<
785 React.HTMLAttributes<T>,
786 T
787>
788export interface RenderBodyArgs extends NodePluginArgs {
789 pathname: string
790 setHeadComponents: (comp: React.ReactNode[]) => void
791 setHtmlAttributes: (attr: ReactProps<HTMLHtmlElement>) => void
792 setBodyAttributes: (attr: ReactProps<HTMLBodyElement>) => void
793 setPreBodyComponents: (comp: React.ReactNode[]) => void
794 setPostBodyComponents: (comp: React.ReactNode[]) => void
795 setBodyProps: Function
796}
797
798export interface ReplaceRendererArgs extends NodePluginArgs {
799 replaceBodyHTMLString: (str: string) => void
800 setHeadComponents: (comp: React.ReactNode[]) => void
801 setHtmlAttributes: (attr: ReactProps<HTMLHtmlElement>) => void
802 setBodyAttributes: (attr: ReactProps<HTMLBodyElement>) => void
803 setPreBodyComponents: (comp: React.ReactNode[]) => void
804 setPostBodyComponents: (comp: React.ReactNode[]) => void
805 setBodyProps: Function
806}
807
808export interface WrapPageElementNodeArgs extends NodePluginArgs {
809 element: object
810 props: object
811 pathname: string
812}
813
814export interface WrapRootElementNodeArgs extends NodePluginArgs {
815 element: object
816}
817
818export interface ParentSpanPluginArgs extends NodePluginArgs {
819 parentSpan: object
820}
821
822export interface NodePluginArgs {
823 pathPrefix: string
824 boundActionCreators: Actions
825 actions: Actions
826 loadNodeContent: Function
827 store: Store
828 emitter: EventEmitter
829 getNodes: Function
830 getNode: Function
831 getNodesByType: Function
832 hasNodeChanged: Function
833 reporter: Reporter
834 getNodeAndSavePathDependency: Function
835 cache: Cache["cache"]
836 createNodeId: Function
837 createContentDigest: typeof createContentDigest
838 tracing: Tracing
839 schema: NodePluginSchema
840 [key: string]: unknown
841}
842
843interface ActionPlugin {
844 name: string
845}
846
847interface DeleteNodeArgs {
848 node: Node
849}
850
851interface CreateNodeFieldArgs {
852 node: Node
853 name: string
854 value: string
855
856 /**
857 * @deprecated
858 */
859 fieldName?: string
860
861 /**
862 * @deprecated
863 */
864 fieldValue?: string
865}
866
867interface ActionOptions {
868 [key: string]: unknown
869}
870
871export interface BuildArgs extends ParentSpanPluginArgs {
872 graphql: Function
873}
874
875export interface Actions {
876 /** @see https://www.gatsbyjs.org/docs/actions/#deletePage */
877 deletePage(args: { path: string; component: string }): void
878
879 /** @see https://www.gatsbyjs.org/docs/actions/#createPage */
880 createPage<TContext = Record<string, unknown>>(
881 args: {
882 path: string
883 matchPath?: string
884 component: string
885 context: TContext
886 },
887 plugin?: ActionPlugin,
888 option?: ActionOptions
889 ): void
890
891 /** @see https://www.gatsbyjs.org/docs/actions/#deletePage */
892 deleteNode(
893 options: { node: Node },
894 plugin?: ActionPlugin,
895 option?: ActionOptions
896 ): void
897
898 /**
899 * @deprecated
900 * @see https://www.gatsbyjs.org/docs/actions/#deleteNodes
901 */
902 deleteNodes(nodes: string[], plugin?: ActionPlugin): void
903
904 /** @see https://www.gatsbyjs.org/docs/actions/#createNode */
905 createNode(
906 node: NodeInput,
907 plugin?: ActionPlugin,
908 options?: ActionOptions
909 ): void
910
911 /** @see https://www.gatsbyjs.org/docs/actions/#touchNode */
912 touchNode(node: { nodeId: string }, plugin?: ActionPlugin): void
913
914 /** @see https://www.gatsbyjs.org/docs/actions/#createNodeField */
915 createNodeField(
916 args: {
917 node: Node
918 fieldName?: string
919 fieldValue?: string
920 name?: string
921 value: any
922 },
923 plugin?: ActionPlugin,
924 options?: ActionOptions
925 ): void
926
927 /** @see https://www.gatsbyjs.org/docs/actions/#createParentChildLink */
928 createParentChildLink(
929 args: { parent: Node; child: Node },
930 plugin?: ActionPlugin
931 ): void
932
933 /** @see https://www.gatsbyjs.org/docs/actions/#setWebpackConfig */
934 setWebpackConfig(config: object, plugin?: ActionPlugin): void
935
936 /** @see https://www.gatsbyjs.org/docs/actions/#replaceWebpackConfig */
937 replaceWebpackConfig(config: object, plugin?: ActionPlugin): void
938
939 /** @see https://www.gatsbyjs.org/docs/actions/#setBabelOptions */
940 setBabelOptions(options: object, plugin?: ActionPlugin): void
941
942 /** @see https://www.gatsbyjs.org/docs/actions/#setBabelPlugin */
943 setBabelPlugin(
944 config: { name: string; options: object },
945 plugin?: ActionPlugin
946 ): void
947
948 /** @see https://www.gatsbyjs.org/docs/actions/#setBabelPreset */
949 setBabelPreset(
950 config: { name: string; options: object },
951 plugin?: ActionPlugin
952 ): void
953
954 /** @see https://www.gatsbyjs.org/docs/actions/#createJob */
955 createJob(
956 job: Record<string, unknown> & { id: string },
957 plugin?: ActionPlugin
958 ): void
959
960 /** @see https://www.gatsbyjs.org/docs/actions/#createJobV2 */
961 createJobV2(
962 job: {
963 name: string
964 inputPaths: string[]
965 outputDir: string
966 args: Record<string, unknown>
967 },
968 plugin?: ActionPlugin
969 ): Promise<unknown>
970
971 /** @see https://www.gatsbyjs.org/docs/actions/#setJob */
972 setJob(
973 job: Record<string, unknown> & { id: string },
974 plugin?: ActionPlugin
975 ): void
976
977 /** @see https://www.gatsbyjs.org/docs/actions/#endJob */
978 endJob(job: { id: string }, plugin?: ActionPlugin): void
979
980 /** @see https://www.gatsbyjs.org/docs/actions/#setPluginStatus */
981 setPluginStatus(status: Record<string, unknown>, plugin?: ActionPlugin): void
982
983 /** @see https://www.gatsbyjs.org/docs/actions/#createRedirect */
984 createRedirect(
985 redirect: {
986 fromPath: string
987 isPermanent?: boolean
988 toPath: string
989 redirectInBrowser?: boolean
990 force?: boolean
991 statusCode?: number
992 [key: string]: unknown
993 },
994 plugin?: ActionPlugin
995 ): void
996
997 /** @see https://www.gatsbyjs.org/docs/actions/#addThirdPartySchema */
998 addThirdPartySchema(
999 args: { schema: object },
1000 plugin?: ActionPlugin,
1001 traceId?: string
1002 ): void
1003
1004 /** @see https://www.gatsbyjs.org/docs/actions/#createTypes */
1005 createTypes(
1006 types:
1007 | string
1008 | GraphQLOutputType
1009 | GatsbyGraphQLType
1010 | string[]
1011 | GraphQLOutputType[]
1012 | GatsbyGraphQLType[],
1013 plugin?: ActionPlugin,
1014 traceId?: string
1015 ): void
1016
1017 /** @see https://www.gatsbyjs.org/docs/actions/#createFieldExtension */
1018 createFieldExtension(
1019 extension: object,
1020 plugin: ActionPlugin,
1021 traceId?: string
1022 ): void
1023}
1024
1025export interface Store {
1026 dispatch: Function
1027 subscribe: Function
1028 getState: Function
1029 replaceReducer: Function
1030}
1031
1032type LogMessageType = (format: string) => void
1033type LogErrorType = (errorMeta: string | Object, error?: Object) => void
1034
1035export type ActivityTracker = {
1036 start(): () => void
1037 end(): () => void
1038 span: Object
1039 setStatus(status: string): void
1040 panic: LogErrorType
1041 panicOnBuild: LogErrorType
1042}
1043
1044export type ProgressActivityTracker = Omit<ActivityTracker, "end"> & {
1045 tick(increment?: number): void
1046 done(): void
1047 total: number
1048}
1049
1050export type ActivityArgs = {
1051 parentSpan?: Object
1052 id?: string
1053}
1054
1055export interface Reporter {
1056 stripIndent: (input: string) => string
1057 format: object
1058 setVerbose(isVerbose?: boolean): void
1059 setNoColor(isNoColor?: boolean): void
1060 panic: LogErrorType
1061 panicOnBuild: LogErrorType
1062 error: LogErrorType
1063 uptime(prefix: string): void
1064 success: LogMessageType
1065 verbose: LogMessageType
1066 info: LogMessageType
1067 warn: LogMessageType
1068 log: LogMessageType
1069 activityTimer(name: string, activityArgs?: ActivityArgs): ActivityTracker
1070 createProgress(
1071 text: string,
1072 total?: number,
1073 start?: number,
1074 activityArgs?: ActivityArgs
1075 ): ProgressActivityTracker
1076}
1077
1078export interface Cache {
1079 name: string
1080 store: {
1081 create: Function
1082 }
1083 cache: {
1084 getAndPassUp: Function
1085 wrap: Function
1086 set: Function
1087 mset: Function
1088 get: Function
1089 mget: Function
1090 del: Function
1091 reset: Function
1092 }
1093}
1094
1095export interface Tracing {
1096 tracer: object
1097 parentSpan: object
1098 startSpan: Function
1099}
1100
1101export interface PackageJson {
1102 name?: string
1103 description?: string
1104 version?: string
1105 main?: string
1106 author?:
1107 | string
1108 | {
1109 name: string
1110 email: string
1111 }
1112 license?: string
1113 dependencies?: Array<Record<string, string>>
1114 devDependencies?: Array<Record<string, string>>
1115 peerDependencies?: Array<Record<string, string>>
1116 optionalDependecies?: Array<Record<string, string>>
1117 bundledDependecies?: Array<Record<string, string>>
1118 keywords?: string[]
1119}
1120
1121export interface WebpackRules {
1122 js: Function
1123 mjs: Function
1124 eslint: Function
1125 yaml: Function
1126 fonts: Function
1127 images: Function
1128 media: Function
1129 miscAssets: Function
1130 css: Function
1131 cssModules: Function
1132 postcss: Function
1133 [key: string]: Function
1134}
1135
1136export interface WebpackLoaders {
1137 json: Function
1138 yaml: Function
1139 null: Function
1140 raw: Function
1141 style: Function
1142 miniCssExtract: Function
1143 css: Function
1144 postcss: Function
1145 file: Function
1146 url: Function
1147 js: Function
1148 eslint: Function
1149 imports: Function
1150 exports: Function
1151 [key: string]: Function
1152}
1153
1154export interface WebpackPlugins {
1155 normalModuleReplacement: Function
1156 contextReplacement: Function
1157 ignore: Function
1158 watchIgnore: Function
1159 banner: Function
1160 prefetch: Function
1161 automaticPrefetch: Function
1162 define: Function
1163 provide: Function
1164 hotModuleReplacement: Function
1165 sourceMapDevTool: Function
1166 evalSourceMapDevTool: Function
1167 evalDevToolModule: Function
1168 cache: Function
1169 extendedAPI: Function
1170 externals: Function
1171 jsonpTemplate: Function
1172 libraryTemplate: Function
1173 loaderTarget: Function
1174 memoryOutputFile: Function
1175 progress: Function
1176 setVarMainTemplate: Function
1177 umdMainTemplate: Function
1178 noErrors: Function
1179 noEmitOnErrors: Function
1180 newWatching: Function
1181 environment: Function
1182 dll: Function
1183 dllReference: Function
1184 loaderOptions: Function
1185 namedModules: Function
1186 namedChunks: Function
1187 hashedModuleIds: Function
1188 moduleFilenameH: Function
1189 aggressiveMerging: Function
1190 aggressiveSplitting: Function
1191 splitChunks: Function
1192 chunkModuleIdRange: Function
1193 dedupe: Function
1194 limitChunkCount: Function
1195 minChunkSize: Function
1196 occurrenceOrder: Function
1197 moduleConcatenation: Function
1198 minifyJs: Function
1199 minifyCss: Function
1200 extractText: Function
1201 moment: Function
1202 [key: string]: Function
1203}
1204
1205export interface PrefetchPathnameArgs extends BrowserPluginArgs {
1206 pathname: string
1207}
1208
1209export interface RouteUpdateArgs extends BrowserPluginArgs {
1210 location: Location
1211}
1212
1213export interface ReplaceComponentRendererArgs extends BrowserPluginArgs {
1214 props: {
1215 path: string
1216 "*": string
1217 uri: string
1218 location: Location
1219 navigate: NavigateFn
1220 children: undefined
1221 pageResources: object
1222 data: object
1223 pageContext: Record<string, unknown>
1224 pathContext: Record<string, unknown>
1225 }
1226 loader: object
1227}
1228
1229export interface ShouldUpdateScrollArgs extends BrowserPluginArgs {
1230 prevRouterProps?: {
1231 location: Location
1232 }
1233 pathname: string
1234 routerProps: {
1235 location: Location
1236 }
1237 getSavedScrollPosition: Function
1238}
1239
1240export interface WrapPageElementBrowserArgs extends BrowserPluginArgs {
1241 element: object
1242 props: object
1243}
1244
1245export interface WrapRootElementBrowserArgs extends BrowserPluginArgs {
1246 element: object
1247 pathname: string
1248}
1249
1250export interface BrowserPluginArgs {
1251 getResourcesForPathnameSync: Function
1252 getResourcesForPathname: Function
1253 getResourceURLsForPathname: Function
1254 [key: string]: unknown
1255}
1256
1257export interface RouteUpdateDelayedArgs extends BrowserPluginArgs {
1258 location: Location
1259}
1260
1261export interface ServiceWorkerArgs extends BrowserPluginArgs {
1262 serviceWorker: ServiceWorkerRegistration
1263}
1264
1265export interface NodeInput {
1266 id: string
1267 parent?: string
1268 children?: string[]
1269 internal: {
1270 type: string
1271 mediaType?: string
1272 content?: string
1273 contentDigest: string
1274 description?: string
1275 }
1276 [key: string]: unknown
1277}
1278
1279export interface Node extends NodeInput {
1280 parent: string
1281 children: string[]
1282 internal: NodeInput["internal"] & {
1283 owner: string
1284 }
1285 [key: string]: unknown
1286}