UNPKG

59.4 kBTypeScriptView Raw
1import * as React from "react"
2import { Renderer } from "react-dom"
3import { EventEmitter } from "events"
4import { WindowLocation, NavigateOptions } from "@reach/router" // These come from `@types/reach__router`
5import { Reporter } from "gatsby-cli/lib/reporter/reporter"
6import { Span } from "opentracing"
7export { Reporter }
8import {
9 EnumTypeComposerAsObjectDefinition as ComposeEnumTypeConfig,
10 InputTypeComposerAsObjectDefinition as ComposeInputObjectTypeConfig,
11 InterfaceTypeComposerAsObjectDefinition as ComposeInterfaceTypeConfig,
12 ObjectTypeComposerAsObjectDefinition as ComposeObjectTypeConfig,
13 ScalarTypeComposerAsObjectDefinition as ComposeScalarTypeConfig,
14 UnionTypeComposerAsObjectDefinition as ComposeUnionTypeConfig,
15} from "graphql-compose"
16import { GraphQLOutputType } from "graphql"
17import { PluginOptionsSchemaJoi, ObjectSchema } from "gatsby-plugin-utils"
18import { IncomingMessage, ServerResponse } from "http"
19
20export type AvailableFeatures =
21 | "image-cdn"
22 | "graphql-typegen"
23 | "content-file-path"
24 | "stateful-source-nodes"
25 | "adapters"
26
27export {
28 Link,
29 GatsbyLinkProps,
30 navigate,
31 withPrefix,
32 withAssetPrefix,
33} from "gatsby-link"
34
35export * from "gatsby-script"
36
37export {
38 AdapterInit,
39 IAdapter,
40 IStaticRoute,
41 IFunctionRoute,
42 IRedirectRoute,
43 IFunctionDefinition,
44 RoutesManifest,
45 HeaderRoutes,
46 FunctionsManifest,
47 IAdapterConfig,
48 ImageCdnUrlGeneratorFn,
49 ImageCdnSourceImage,
50 ImageCdnTransformArgs,
51 FileCdnUrlGeneratorFn,
52 FileCdnSourceImage,
53 RemoteFileAllowedUrls,
54} from "./dist/utils/adapter/types"
55
56export const useScrollRestoration: (key: string) => {
57 ref: React.MutableRefObject<HTMLElement | undefined>
58 onScroll(): void
59}
60
61export class StaticQueryDocument {
62 /** Prevents structural type widening. */
63 #kind: "StaticQueryDocument"
64
65 /** Allows type-safe access to the static query hash for debugging purposes. */
66 toString(): string
67}
68
69/**
70 * A React Hooks version of StaticQuery.
71 *
72 * StaticQuery can do most of the things that page query can, including fragments. The main differences are:
73 *
74 * - page queries can accept variables (via `pageContext`) but can only be added to _page_ components
75 * - StaticQuery does not accept variables (hence the name "static"), but can be used in _any_ component, including pages
76 *
77 * @see https://www.gatsbyjs.com/docs/how-to/querying-data/use-static-query/
78 */
79export const useStaticQuery: <TData = any>(query: StaticQueryDocument) => TData
80
81export const parsePath: (path: string) => WindowLocation
82
83export const prefetchPathname: (path: string) => void
84
85/**
86 * A props object for adding type safety to your Gatsby pages, can be
87 * extended with both the query response shape, and the page context.
88 *
89 * @example
90 * // When typing a default page from the ./pages dir
91 *
92 * import {PageProps} from "gatsby"
93 * export default (props: PageProps) => {
94 *
95 * @example
96 * // When adding types for both pageContext (represented by LocaleLookUpInfo)
97 * // and GraphQL query data (represented by IndexQueryProps)
98 *
99 * import {PageProps} from "gatsby"
100 *
101 * type IndexQueryProps = { downloadCount: number }
102 * type LocaleLookUpInfo = { translationStrings: any } & { langKey: string, slug: string }
103 * type IndexPageProps = PageProps<IndexQueryProps, LocaleLookUpInfo>
104 *
105 * export default (props: IndexPageProps) => {
106 * ..
107 */
108export type PageProps<
109 DataType = object,
110 PageContextType = object,
111 LocationState = WindowLocation["state"],
112 ServerDataType = object
113> = {
114 /** The path for this current page */
115 path: string
116 /** The URI for the current page */
117 uri: string
118 /** An extended version of window.document which comes from @react/router */
119 location: WindowLocation<LocationState>
120 /** You can't get passed children as this is the root user-land component */
121 children: undefined
122 /** The URL parameters when the page has a `matchPath` */
123 params: Record<string, string>
124 /** Holds information about the build process for this component */
125 pageResources: {
126 component: React.Component
127 json: {
128 data: DataType
129 pageContext: PageContextType
130 }
131 page: {
132 componentChunkName: string
133 path: string
134 webpackCompilationHash: string
135 matchPath?: string
136 }
137 }
138 /**
139 * Data passed into the page via an exported GraphQL query. To set up this type
140 * you need to use [generics](https://www.typescriptlang.org/play/#example/generic-functions),
141 * see below for an example
142 *
143 * @example
144 *
145 * import {PageProps} from "gatsby"
146 *
147 * type IndexQueryProps = { downloadCount: number }
148 * type IndexPageProps = PageProps<IndexQueryProps>
149 *
150 * export default (props: IndexPageProps) => {
151 * ..
152 *
153 */
154 data: DataType
155 /**
156 * A context object which is passed in during the creation of the page. Can be extended if you are using
157 * `createPage` yourself using generics:
158 *
159 * @example
160 *
161 * import {PageProps} from "gatsby"
162 *
163 * type IndexQueryProps = { downloadCount: number }
164 * type LocaleLookUpInfo = { translationStrings: any } & { langKey: string, slug: string }
165 * type IndexPageProps = PageProps<IndexQueryProps, LocaleLookUpInfo>
166 *
167 * export default (props: IndexPageProps) => {
168 * ..
169 */
170 pageContext: PageContextType
171 /** Data passed into the page via the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) SSR function. */
172 serverData: ServerDataType
173}
174
175/**
176 * A props object passed into the Head function for [Gatsby Head API](https://gatsby.dev/gatsby-head).
177 */
178export type HeadProps<
179 DataType = object,
180 PageContextType = object,
181 ServerDataType = object
182> = {
183 location: {
184 /**
185 * Returns the Location object's URL's path.
186 */
187 pathname: string
188 }
189 /** The URL parameters when the page has a `matchPath` */
190 params: Record<string, string>
191 /**
192 * Data passed into the page via an exported GraphQL query.
193 */
194 data: DataType
195 /**
196 * A context object which is passed in during the creation of the page.
197 */
198 pageContext: PageContextType
199 /**
200 * Data passed into the page via the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) SSR function.
201 */
202 serverData: ServerDataType
203}
204
205/**
206 * A shorthand type for combining the props and return type for the [Gatsby Head API](https://gatsby.dev/gatsby-head).
207 */
208export type HeadFC<DataType = object, PageContextType = object> = (
209 props: HeadProps<DataType, PageContextType>
210) => JSX.Element
211
212type SerializableProps =
213 | ISerializableObject
214 | Array<SerializableProps>
215 | string
216 | number
217 | boolean
218 | null
219 | undefined
220
221interface ISerializableObject {
222 [key: string]: SerializableProps
223}
224
225/**
226 * A props object for [slice placholder](https://gatsbyjs.com/docs/reference/built-in-components/gatsby-slice/)
227 */
228export interface SlicePlaceholderProps {
229 alias: string
230 allowEmpty?: boolean
231 children?: React.ReactNode
232 [key: string]: SerializableProps | React.ReactNode
233}
234
235/**
236 * Component used as a slice placholder, to mark a place in the page where a [slice](https://gatsbyjs.com/docs/reference/built-in-components/gatsby-slice/) should be inserted.
237 */
238export declare function Slice(props: SlicePlaceholderProps): JSX.Element
239
240/**
241 * A props object for [slice component](https://gatsbyjs.com/docs/reference/built-in-components/gatsby-slice/)
242 */
243export type SliceComponentProps<
244 DataType = object,
245 SliceContextType = object,
246 AdditionalSerializableProps extends ISerializableObject = object
247> = {
248 data: DataType
249 sliceContext: SliceContextType
250 children?: React.ReactNode
251} & AdditionalSerializableProps
252
253/**
254 * Props object passed into the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) function.
255 */
256export type GetServerDataProps = {
257 headers: Map<string, unknown>
258 method: string
259 url: string
260 query?: Record<string, unknown>
261 params?: Record<string, unknown>
262 pageContext: Record<string, unknown>
263}
264
265/**
266 * The return type (promise payload) from the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) function.
267 */
268export type GetServerDataReturn<ServerDataType = Record<string, unknown>> =
269 Promise<{
270 headers?: Record<string, unknown>
271 props?: ServerDataType
272 status?: number
273 }>
274
275/**
276 * A shorthand type for combining the props and return type for the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) function.
277 */
278export type GetServerData<ServerDataType> = (
279 props: GetServerDataProps
280) => GetServerDataReturn<ServerDataType>
281
282/**
283 * Constructor arguments for the PageRenderer.
284 */
285export interface PageRendererProps {
286 location: WindowLocation
287}
288
289/**
290 * PageRenderer's constructor [loads the page resources](https://www.gatsbyjs.com/docs/production-app/#load-page-resources) for the path.
291 *
292 * 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.com/docs/how-code-splitting-works/#construct-link-and-script-tags-for-current-page) in HTML Generation Docs).
293 * 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.
294 *
295 * @see https://www.gatsbyjs.com/docs/production-app/#page-rendering
296 */
297export class PageRenderer extends React.Component<PageRendererProps> {}
298
299type RenderCallback<T = any> = (data: T) => React.ReactNode
300
301export interface StaticQueryProps<T = any> {
302 query: StaticQueryDocument
303 render?: RenderCallback<T>
304 children?: RenderCallback<T>
305}
306
307/**
308 * StaticQuery can do most of the things that page query can, including fragments. The main differences are:
309 *
310 * - page queries can accept variables (via `pageContext`) but can only be added to _page_ components
311 * - StaticQuery does not accept variables (hence the name "static"), but can be used in _any_ component, including pages
312 * - StaticQuery does not work with raw React.createElement calls; please use JSX, e.g. `<StaticQuery />`
313 *
314 * @see https://www.gatsbyjs.com/docs/static-query/
315 */
316
317export class StaticQuery<T = any> extends React.Component<
318 StaticQueryProps<T>
319> {}
320
321/**
322 * graphql is a tag function. Behind the scenes Gatsby handles these tags in a particular way
323 *
324 * During the Gatsby build process, GraphQL queries are pulled out of the original source for parsing.
325 *
326 * @see https://www.gatsbyjs.com/docs/page-query#how-does-the-graphql-tag-work
327 */
328export const graphql: (query: TemplateStringsArray) => StaticQueryDocument
329
330export interface GraphQLTypegenOptions {
331 typesOutputPath?: string
332 documentSearchPaths?: string[]
333 generateOnBuild?: boolean
334}
335
336type Proxy = {
337 prefix: string
338 url: string
339}
340
341type Header = {
342 /**
343 * The path to match requests against.
344 */
345 source: string
346 /**
347 * Your custom response headers.
348 */
349 headers: Array<{
350 key: string
351 value: string
352 }>
353}
354
355/**
356 * Gatsby configuration API.
357 *
358 * @see https://www.gatsbyjs.com/docs/reference/config-files/gatsby-config/
359 */
360export interface GatsbyConfig {
361 /** When you want to reuse common pieces of data across the site (for example, your site title), you can store that here. */
362 siteMetadata?: Record<string, unknown>
363 /** 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. */
364 plugins?: Array<PluginRef>
365 /** You can activate and deactivate current experiments here. These are experimental features that are currently under development and need testing. When opting in to an experiment you'll receive a console message with more information of what it does and a link to an umbrella discussion. */
366 flags?: Record<string, boolean>
367 /** 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. */
368 pathPrefix?: string
369 /** `never` removes all trailing slashes, `always` adds it, and `ignore` doesn't automatically change anything and it's in user hands to keep things consistent. By default `always` is used. */
370 trailingSlash?: "always" | "never" | "ignore"
371 /** In some circumstances you may want to deploy assets (non-HTML resources such as JavaScript, CSS, etc.) to a separate domain. `assetPrefix` allows you to use Gatsby with assets hosted from a separate domain */
372 assetPrefix?: string
373 /** More easily incorporate content into your pages through automatic TypeScript type generation and better GraphQL IntelliSense. If set to true, the default GraphQLTypegenOptions are used. See https://www.gatsbyjs.com/docs/reference/config-files/gatsby-config/ for all options. */
374 graphqlTypegen?: boolean | GraphQLTypegenOptions
375 /** 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.*/
376 polyfill?: boolean
377 mapping?: Record<string, string>
378 jsxRuntime?: "automatic" | "classic"
379 jsxImportSource?: string
380 /**
381 * Setting the proxy config option will tell the develop server to proxy any unknown requests to your specified server.
382 * @see https://www.gatsbyjs.com/docs/api-proxy/
383 * */
384 proxy?: Proxy | Proxy[]
385 /**
386 * A list of trusted URLs that will be proxied for use with the gatsby-script off-main-thread strategy.
387 * @see https://gatsby.dev/gatsby-script
388 */
389 partytownProxiedURLs?: Array<string>
390 /** 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. */
391 developMiddleware?(app: any): void
392 /**
393 * You can set custom HTTP headers on the response of a given path. This allows you to, e.g. modify the caching behavior or configure access control. You can apply HTTP headers to static routes and redirects.
394 * @see http://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/headers/
395 */
396 headers?: Array<Header>
397 /**
398 * Adapters are responsible for taking the production output from Gatsby and turning it into something your deployment platform understands. They make it easier to build and deploy Gatsby on any deployment platform.
399 * @see http://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/adapters/
400 */
401 adapter?: IAdapter
402}
403
404/**
405 * Gatsby API for Node.js.
406 *
407 * @see https://www.gatsbyjs.com/docs/node-apis/
408 */
409export interface GatsbyNode<
410 TNode extends Record<string, unknown> = Record<string, unknown>,
411 TContext = Record<string, unknown>
412> {
413 /**
414 * Tell plugins to add pages. This extension point is called only after the initial
415 * sourcing and transformation of nodes plus creation of the GraphQL schema are
416 * complete so you can query your data in order to create pages.
417 *
418 * @see https://www.gatsbyjs.com/docs/node-apis/#createPages
419 */
420 createPages?(
421 args: CreatePagesArgs & {
422 traceId: "initial-createPages"
423 },
424 options: PluginOptions,
425 callback: PluginCallback<void>
426 ): void | Promise<void>
427
428 /**
429 * Like `createPages` but for plugins who want to manage creating and removing
430 * pages themselves in response to changes in data *not* managed by Gatsby.
431 * Plugins implementing `createPages` will get called regularly to recompute
432 * page information as Gatsby's data changes but those implementing
433 * `createPagesStatefully` will not.
434 *
435 * An example of a plugin that uses this extension point is the plugin
436 * [gatsby-plugin-page-creator](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-page-creator)
437 * which monitors the `src/pages` directory for the adding and removal of JS
438 * pages. As its source of truth, files in the pages directory, is not known by
439 * Gatsby, it needs to keep its own state about its world to know when to
440 * add and remove pages.
441 */
442 createPagesStatefully?(
443 args: CreatePagesArgs & {
444 traceId: "initial-createPagesStatefully"
445 },
446 options: PluginOptions,
447 callback: PluginCallback<void>
448 ): void | Promise<void>
449
450 /**
451 * Let plugins extend/mutate the site's Babel configuration.
452 * This API will change before 2.0 as it needs still to be converted to use
453 * Redux actions.
454 */
455 onCreateBabelConfig?(
456 args: CreateBabelConfigArgs,
457 options: PluginOptions,
458 callback: PluginCallback<void>
459 ): void | Promise<void>
460
461 /**
462 * Run when gatsby develop server is started, its useful to add proxy and middleware
463 * to the dev server app
464 * @param {object} $0
465 * @param {Express} $0.app The [Express app](https://expressjs.com/en/4x/api.html#app) used to run the dev server
466 *
467 * @example
468 *
469 * exports.onCreateDevServer = ({ app }) => {
470 * app.get('/hello', function (req, res) {
471 * res.send('hello world')
472 * })
473 * }
474 */
475 onCreateDevServer?(
476 args: CreateDevServerArgs,
477 options: PluginOptions,
478 calllback: PluginCallback<void>
479 ): void | Promise<void>
480
481 /**
482 * Called when a new node is created. Plugins wishing to extend or
483 * transform nodes created by other plugins should implement this API.
484 *
485 * See also the documentation for `createNode`
486 * and [`createNodeField`](https://www.gatsbyjs.com/docs/reference/config-files/actions/#createNodeField)
487 * @param {object} $0
488 * @param {object} $0.node A node object.
489 * @param {object} $0.actions
490 * @param {function} $0.actions.createNode Create a new node.
491 * @param {function} $0.actions.createNodeField Extend another node. The new node field is placed under the fields key on the extended node object.
492 * @example
493 * exports.onCreateNode = ({ node, getNode, actions }) => {
494 * const { createNodeField } = actions
495 *
496 * if (node.internal.type === `MarkdownRemark`) {
497 * const nodePath = node.fileAbsolutePath
498 *
499 * if (nodePath.match(/\/blog\//)) {
500 * const postSlug = createFilePath({
501 * node,
502 * getNode,
503 * basePath: `src/content`,
504 * trailingSlash: true,
505 * })
506 *
507 * createNodeField({
508 * node,
509 * name: `slug`,
510 * value: `/blog/${postSlug}/`,
511 * })
512 * }
513 * }
514 * }
515 */
516 onCreateNode?(
517 args: CreateNodeArgs<TNode>,
518 options: PluginOptions,
519 callback: PluginCallback<void>
520 ): void | Promise<void>
521
522 /**
523 * Called before scheduling a `onCreateNode` callback for a plugin. If it returns falsy
524 * then Gatsby will not schedule the `onCreateNode` callback for this node for this plugin.
525 * Note: this API does not receive the regular `api` that other callbacks get as first arg.
526 *
527 * @gatsbyVersion 2.24.80
528 * @example
529 * exports.shouldOnCreateNode = ({node}, pluginOptions) => node.internal.type === 'Image'
530 */
531 shouldOnCreateNode?(args: { node: TNode }, options: PluginOptions): boolean
532
533 /**
534 * Called when a new page is created. This extension API is useful
535 * for programmatically manipulating pages created by other plugins e.g.
536 * if you want paths without trailing slashes.
537 *
538 * See the guide [Creating and Modifying Pages](https://www.gatsbyjs.com/docs/creating-and-modifying-pages/)
539 * for more on this API.
540 */
541 onCreatePage?(
542 args: CreatePageArgs<TContext>,
543 options: PluginOptions,
544 callback: PluginCallback<void>
545 ): void | Promise<void>
546
547 /**
548 * Let plugins extend/mutate the site's webpack configuration.
549 * @see https://www.gatsbyjs.com/docs/node-apis/#onCreateWebpackConfig
550 */
551 onCreateWebpackConfig?(
552 args: CreateWebpackConfigArgs,
553 options: PluginOptions,
554 callback: PluginCallback<void>
555 ): void | Promise<void>
556
557 /** Called at the end of the bootstrap process after all other extension APIs have been called. */
558 onPostBootstrap?(
559 args: ParentSpanPluginArgs,
560 options: PluginOptions,
561 callback: PluginCallback<void>
562 ): void | Promise<void>
563
564 /** The last extension point called after all other parts of the build process are complete. */
565 onPostBuild?(
566 args: BuildArgs,
567 options: PluginOptions,
568 callback: PluginCallback<void>
569 ): void | Promise<void>
570
571 /** Called at the end of the bootstrap process after all other extension APIs have been called. If you indend to use this API in a plugin, use "onPluginInit" instead. */
572 onPreBootstrap?(
573 args: ParentSpanPluginArgs,
574 options: PluginOptions,
575 callback: PluginCallback<void>
576 ): void | Promise<void>
577
578 /** The first extension point called during the build process. Called after the bootstrap has completed but before the build steps start. */
579 onPreBuild?(
580 args: BuildArgs,
581 options: PluginOptions,
582 callback: PluginCallback<void>
583 ): void | Promise<void>
584
585 /** Called once Gatsby has initialized itself and is ready to bootstrap your site. */
586 onPreExtractQueries?(
587 args: ParentSpanPluginArgs,
588 options: PluginOptions,
589 callback: PluginCallback<void>
590 ): void | Promise<void>
591
592 /**
593 * Lifecycle executed in each process (one time per process). Used to store actions, etc. for later use. Plugins should use this over other APIs like "onPreBootstrap" or "onPreInit" since onPluginInit will run in main process + all workers to support Parallel Query Running.
594 * @gatsbyVersion 3.9.0
595 * @example
596 * let createJobV2
597 * exports.onPluginInit = ({ actions }) => {
598 * // Store job creation action to use it later
599 * createJobV2 = actions.createJobV2
600 * }
601 */
602 onPluginInit?(
603 args: ParentSpanPluginArgs,
604 options: PluginOptions,
605 callback: PluginCallback<void>
606 ): void | Promise<void>
607
608 /** The first API called during Gatsby execution, runs as soon as plugins are loaded, before cache initialization and bootstrap preparation. If you indend to use this API in a plugin, use "onPluginInit" instead. */
609 onPreInit?(
610 args: PreInitArgs,
611 options: PluginOptions,
612 callback: PluginCallback<void>
613 ): void | Promise<void>
614
615 /**
616 * Ask compile-to-js plugins to process source to JavaScript so the query
617 * runner can extract out GraphQL queries for running.
618 */
619 preprocessSource?(
620 args: PreprocessSourceArgs,
621 options: PluginOptions,
622 callback: PluginCallback<void>
623 ): void | string | Promise<void | string>
624
625 /**
626 * Lets plugins implementing support for other compile-to-js add to the list of "resolvable" file extensions. Gatsby supports `.js` and `.jsx` by default.
627 */
628 resolvableExtensions?(
629 args: ResolvableExtensionsArgs,
630 options: PluginOptions,
631 callback: PluginCallback<Array<string>>
632 ): Array<string> | Promise<Array<string>>
633
634 /**
635 * Called during the creation of the GraphQL schema. Allows plugins
636 * to add new fields to the types created from data nodes. It will be called
637 * separately for each type.
638 *
639 * This function should return an object in the shape of
640 * [GraphQLFieldConfigMap](https://graphql.org/graphql-js/type/#graphqlobjecttype)
641 * which will be appended to fields inferred by Gatsby from data nodes.
642 *
643 * *Note:* Import GraphQL types from `gatsby/graphql` and don't add the `graphql`
644 * package to your project/plugin dependencies to avoid Schema must
645 * contain unique named types but contains multiple types named errors.
646 * `gatsby/graphql` exports all builtin GraphQL types as well as the `graphQLJSON`
647 * type.
648 *
649 * Many transformer plugins use this to add fields that take arguments.
650 *
651 * @see https://www.gatsbyjs.com/docs/node-apis/#setFieldsOnGraphQLNodeType
652 */
653 setFieldsOnGraphQLNodeType?(
654 args: SetFieldsOnGraphQLNodeTypeArgs,
655 options: PluginOptions,
656 callback: PluginCallback<any>
657 ): any
658
659 /**
660 * Extension point to tell plugins to source nodes. This API is called during
661 * the Gatsby bootstrap sequence. Source plugins use this hook to create nodes.
662 * This API is called exactly once per plugin (and once for your site's
663 * `gatsby-config.js` file). If you define this hook in `gatsby-node.js` it
664 * will be called exactly once after all of your source plugins have finished
665 * creating nodes.
666 *
667 * @see https://www.gatsbyjs.com/docs/node-apis/#sourceNodes
668 */
669 sourceNodes?(
670 args: SourceNodesArgs,
671 options: PluginOptions,
672 callback: PluginCallback<void>
673 ): void | Promise<void>
674
675 /**
676 * Add custom field resolvers to the GraphQL schema.
677 *
678 * Allows adding new fields to types by providing field configs, or adding resolver
679 * functions to existing fields.
680 *
681 * Things to note:
682 * * Overriding field types is disallowed, instead use the `createTypes`
683 * action. In case of types added from third-party schemas, where this is not
684 * possible, overriding field types is allowed.
685 * * New fields will not be available on `filter` and `sort` input types. Extend
686 * types defined with `createTypes` if you need this.
687 * * In field configs, types can be referenced as strings.
688 * * When extending a field with an existing field resolver, the original
689 * resolver function is available from `info.originalResolver`.
690 * * The `createResolvers` API is called as the last step in schema generation.
691 * Thus, an intermediate schema is made available on the `schema` property.
692 * In resolver functions themselves, it is recommended to access the final
693 * built schema from `info.schema`.
694 * * Gatsby's data layer, including all internal query capabilities, is
695 * exposed on [`context.nodeModel`](/docs/node-model/). The node store can be
696 * queried directly with `findOne`, `getNodeById` and `getNodesByIds`,
697 * while more advanced queries can be composed with `findAll`.
698 * * It is possible to add fields to the root `Query` type.
699 * * When using the first resolver argument (`source` in the example below,
700 * often also called `parent` or `root`), take care of the fact that field
701 * resolvers can be called more than once in a query, e.g. when the field is
702 * present both in the input filter and in the selection set. This means that
703 * foreign-key fields on `source` can be either resolved or not-resolved.
704 *
705 * For fuller examples, see [`using-type-definitions`](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-type-definitions).
706 *
707 * @see https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#createResolvers
708 */
709 createResolvers?(
710 args: CreateResolversArgs,
711 options: PluginOptions,
712 callback: PluginCallback<void>
713 ): void | Promise<void>
714
715 /**
716 * Customize Gatsby’s GraphQL schema by creating type definitions, field extensions or adding third-party schemas.
717 * The createTypes, createFieldExtension and addThirdPartySchema actions are only available in this API.
718 *
719 * For details on their usage please refer to the actions documentation.
720 *
721 * This API runs immediately before schema generation. For modifications of the generated schema, e.g.
722 * to customize added third-party types, use the createResolvers API.
723 * @see https://www.gatsbyjs.com/docs/node-apis/#createSchemaCustomization
724 */
725 createSchemaCustomization?(
726 args: CreateSchemaCustomizationArgs,
727 options: PluginOptions,
728 callback: PluginCallback<void>
729 ): void | Promise<void>
730
731 /**
732 * Add a Joi schema for the possible options of your plugin.
733 * Currently experimental and not enabled by default.
734 */
735 pluginOptionsSchema?(args: PluginOptionsSchemaArgs): ObjectSchema
736}
737
738/**
739 * Gatsby browser API.
740 *
741 * @see https://www.gatsbyjs.com/docs/browser-apis/
742 */
743export interface GatsbyBrowser<
744 DataType = Record<string, unknown>,
745 PageContext = Record<string, unknown>,
746 LocationState = WindowLocation["state"]
747> {
748 disableCorePrefetching?(
749 args: BrowserPluginArgs,
750 options: PluginOptions
751 ): boolean
752 onClientEntry?(args: BrowserPluginArgs, options: PluginOptions): void
753 onInitialClientRender?(args: BrowserPluginArgs, options: PluginOptions): void
754 onPostPrefetchPathname?(
755 args: PrefetchPathnameArgs,
756 options: PluginOptions
757 ): void
758 onPreRouteUpdate?(args: RouteUpdateArgs, options: PluginOptions): void
759 onPrefetchPathname?(args: PrefetchPathnameArgs, options: PluginOptions): void
760 onRouteUpdate?(args: RouteUpdateArgs, options: PluginOptions): void
761 onRouteUpdateDelayed?(
762 args: RouteUpdateDelayedArgs,
763 options: PluginOptions
764 ): void
765 onServiceWorkerActive?(args: ServiceWorkerArgs, options: PluginOptions): void
766 onServiceWorkerInstalled?(
767 args: ServiceWorkerArgs,
768 options: PluginOptions
769 ): void
770 onServiceWorkerRedundant?(
771 args: ServiceWorkerArgs,
772 options: PluginOptions
773 ): void
774 onServiceWorkerUpdateFound?(
775 args: ServiceWorkerArgs,
776 options: PluginOptions
777 ): void
778 onServiceWorkerUpdateReady?(
779 args: ServiceWorkerArgs,
780 options: PluginOptions
781 ): void
782 registerServiceWorker?(
783 args: BrowserPluginArgs,
784 options: PluginOptions
785 ): boolean
786 replaceHydrateFunction?(
787 args: BrowserPluginArgs,
788 options: PluginOptions
789 ): Renderer
790 shouldUpdateScroll?(
791 args: ShouldUpdateScrollArgs,
792 options: PluginOptions
793 ): boolean | [number, number] | string
794 wrapPageElement?(
795 args: WrapPageElementBrowserArgs<DataType, PageContext, LocationState>,
796 options: PluginOptions
797 ): React.ReactElement
798 wrapRootElement?(
799 args: WrapRootElementBrowserArgs,
800 options: PluginOptions
801 ): React.ReactElement
802}
803
804/**
805 * Gatsby server-side rendering API.
806 *
807 * @see https://www.gatsbyjs.com/docs/ssr-apis/
808 */
809export interface GatsbySSR<
810 DataSet = Record<string, unknown>,
811 PageContext = Record<string, unknown>
812> {
813 /**
814 * Called after every page Gatsby server renders while building HTML so you can
815 * replace head components to be rendered in your `html.js`. This is useful if
816 * you need to reorder scripts or styles added by other plugins.
817 * @example
818 * // Move Typography.js styles to the top of the head section so they're loaded first.
819 * exports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
820 * const headComponents = getHeadComponents()
821 * headComponents.sort((x, y) => {
822 * if (x.key === 'TypographyStyle') {
823 * return -1
824 * } else if (y.key === 'TypographyStyle') {
825 * return 1
826 * }
827 * return 0
828 * })
829 * replaceHeadComponents(headComponents)
830 * }
831 */
832 onPreRenderHTML?(args: PreRenderHTMLArgs, options: PluginOptions): void
833
834 /**
835 * Called after every page Gatsby server renders while building HTML so you can
836 * set head and body components to be rendered in your `html.js`.
837 *
838 * Gatsby does a two-pass render for HTML. It loops through your pages first
839 * rendering only the body and then takes the result body HTML string and
840 * passes it as the `body` prop to your `html.js` to complete the render.
841 *
842 * It's often handy to be able to send custom components to your `html.js`.
843 * For example, it's a very common pattern for React.js libraries that
844 * support server rendering to pull out data generated during the render to
845 * add to your HTML.
846 *
847 * Using this API over `replaceRenderer` is preferable as
848 * multiple plugins can implement this API where only one plugin can take
849 * over server rendering. However, if your plugin requires taking over server
850 * rendering then that's the one to use
851 * @example
852 * const { Helmet } = require("react-helmet")
853 *
854 * exports.onRenderBody = (
855 * { setHeadComponents, setHtmlAttributes, setBodyAttributes },
856 * pluginOptions
857 * ) => {
858 * const helmet = Helmet.renderStatic()
859 * setHtmlAttributes(helmet.htmlAttributes.toComponent())
860 * setBodyAttributes(helmet.bodyAttributes.toComponent())
861 * setHeadComponents([
862 * helmet.title.toComponent(),
863 * helmet.link.toComponent(),
864 * helmet.meta.toComponent(),
865 * helmet.noscript.toComponent(),
866 * helmet.script.toComponent(),
867 * helmet.style.toComponent(),
868 * ])
869 * }
870 */
871 onRenderBody?(args: RenderBodyArgs, options: PluginOptions): void
872
873 /**
874 * Replace the default server renderer. This is useful for integration with
875 * Redux, css-in-js libraries, etc. that need custom setups for server
876 * rendering.
877 * @example
878 * // From gatsby-plugin-glamor
879 * const { renderToString } = require("react-dom/server")
880 * const inline = require("glamor-inline")
881 *
882 * exports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
883 * const bodyHTML = renderToString(bodyComponent)
884 * const inlinedHTML = inline(bodyHTML)
885 *
886 * replaceBodyHTMLString(inlinedHTML)
887 * }
888 */
889 replaceRenderer?(
890 args: ReplaceRendererArgs,
891 options: PluginOptions
892 ): void | Promise<void>
893
894 /**
895 * Allow a plugin to wrap the page element.
896 *
897 * This is useful for setting wrapper component around pages that won't get
898 * unmounted on page change. For setting Provider components use `wrapRootElement`.
899 *
900 * _Note:_ [There is equivalent hook in Browser API](https://www.gatsbyjs.com/docs/browser-apis/#wrapPageElement)
901 * @example
902 * const React = require("react")
903 * const Layout = require("./src/components/layout")
904 *
905 * exports.wrapPageElement = ({ element, props }) => {
906 * // props provide same data to Layout as Page element will get
907 * // including location, data, etc - you don't need to pass it
908 * return <Layout {...props}>{element}</Layout>
909 * }
910 */
911 wrapPageElement?(
912 args: WrapPageElementNodeArgs<DataSet, PageContext>,
913 options: PluginOptions
914 ): React.ReactElement
915
916 /**
917 * Allow a plugin to wrap the root element.
918 *
919 * This is useful to setup any Providers component that will wrap your application.
920 * For setting persistent UI elements around pages use `wrapPageElement`.
921 *
922 * _Note:_ [There is equivalent hook in Browser API](https://www.gatsbyjs.com/docs/browser-apis/#wrapRootElement)
923 * @example
924 * const React = require("react")
925 * const { Provider } = require("react-redux")
926 *
927 * const createStore = require("./src/state/createStore")
928 * const store = createStore()
929 *
930 * exports.wrapRootElement = ({ element }) => {
931 * return (
932 * <Provider store={store}>
933 * {element}
934 * </Provider>
935 * )
936 * }
937 */
938 wrapRootElement?(
939 args: WrapRootElementNodeArgs,
940 options: PluginOptions
941 ): React.ReactElement
942}
943
944export interface PluginOptions {
945 plugins: unknown[]
946 [key: string]: unknown
947}
948
949export type PluginCallback<R = any> = (err: Error | null, result?: R) => void
950
951export interface CreatePagesArgs extends ParentSpanPluginArgs {
952 graphql<TData, TVariables = any>(
953 query: string,
954 variables?: TVariables
955 ): Promise<{
956 errors?: any
957 data?: TData
958 }>
959 traceId: string
960 waitForCascadingActions: boolean
961}
962
963type GatsbyStages =
964 | "develop"
965 | "develop-html"
966 | "build-javascript"
967 | "build-html"
968
969export interface CreateBabelConfigArgs extends ParentSpanPluginArgs {
970 stage: GatsbyStages
971}
972
973export interface CreateDevServerArgs extends ParentSpanPluginArgs {
974 app: any
975}
976
977export interface CreateNodeArgs<
978 TNode extends Record<string, unknown> = Record<string, unknown>
979> extends ParentSpanPluginArgs {
980 node: Node & TNode
981 traceId: string
982 traceTags: {
983 nodeId: string
984 nodeType: string
985 }
986}
987
988export interface CreatePageArgs<TContext = Record<string, unknown>>
989 extends ParentSpanPluginArgs {
990 page: Page<TContext>
991 traceId: string
992}
993
994export interface CreateWebpackConfigArgs extends ParentSpanPluginArgs {
995 getConfig: Function
996 stage: GatsbyStages
997 rules: WebpackRules
998 loaders: WebpackLoaders
999 plugins: WebpackPlugins
1000}
1001
1002export interface PreprocessSourceArgs extends ParentSpanPluginArgs {
1003 filename: string
1004 contents: string
1005}
1006
1007export interface ResolvableExtensionsArgs extends ParentSpanPluginArgs {
1008 traceId: "initial-resolvableExtensions"
1009}
1010
1011export interface SetFieldsOnGraphQLNodeTypeArgs extends ParentSpanPluginArgs {
1012 type: {
1013 name: string
1014 nodes: any[]
1015 }
1016 traceId: "initial-setFieldsOnGraphQLNodeType"
1017}
1018
1019export interface GatsbyGraphQLObjectType {
1020 kind: "OBJECT"
1021 config: ComposeObjectTypeConfig<any, any>
1022}
1023
1024export interface GatsbyGraphQLInputObjectType {
1025 kind: "INPUT_OBJECT"
1026 config: ComposeInputObjectTypeConfig
1027}
1028
1029export interface GatsbyGraphQLUnionType {
1030 kind: "UNION"
1031 config: ComposeUnionTypeConfig<any, any>
1032}
1033
1034export interface GatsbyGraphQLInterfaceType {
1035 kind: "INTERFACE"
1036 config: ComposeInterfaceTypeConfig<any, any>
1037}
1038
1039export interface GatsbyGraphQLEnumType {
1040 kind: "ENUM"
1041 config: ComposeEnumTypeConfig
1042}
1043
1044export interface GatsbyGraphQLScalarType {
1045 kind: "SCALAR"
1046 config: ComposeScalarTypeConfig
1047}
1048
1049export type GatsbyGraphQLType =
1050 | GatsbyGraphQLObjectType
1051 | GatsbyGraphQLInputObjectType
1052 | GatsbyGraphQLUnionType
1053 | GatsbyGraphQLInterfaceType
1054 | GatsbyGraphQLEnumType
1055 | GatsbyGraphQLScalarType
1056
1057export interface NodePluginSchema {
1058 buildObjectType(
1059 config: ComposeObjectTypeConfig<any, any>
1060 ): GatsbyGraphQLObjectType
1061 buildUnionType(
1062 config: ComposeUnionTypeConfig<any, any>
1063 ): GatsbyGraphQLUnionType
1064 buildInterfaceType(
1065 config: ComposeInterfaceTypeConfig<any, any>
1066 ): GatsbyGraphQLInterfaceType
1067 buildInputObjectType(
1068 config: ComposeInputObjectTypeConfig
1069 ): GatsbyGraphQLInputObjectType
1070 buildEnumType(config: ComposeEnumTypeConfig): GatsbyGraphQLEnumType
1071 buildScalarType(config: ComposeScalarTypeConfig): GatsbyGraphQLScalarType
1072}
1073export interface PreInitArgs extends ParentSpanPluginArgs {
1074 actions: Actions
1075}
1076
1077export interface SourceNodesArgs extends ParentSpanPluginArgs {
1078 traceId: "initial-sourceNodes"
1079 waitForCascadingActions: boolean
1080 webhookBody: any
1081}
1082
1083export interface CreateResolversArgs extends ParentSpanPluginArgs {
1084 intermediateSchema: object
1085 createResolvers: Function
1086 traceId: "initial-createResolvers"
1087}
1088
1089export interface CreateSchemaCustomizationArgs extends ParentSpanPluginArgs {
1090 traceId: "initial-createSchemaCustomization"
1091}
1092
1093export interface PreRenderHTMLArgs {
1094 getHeadComponents: () => React.ReactNode[]
1095 replaceHeadComponents: (comp: React.ReactNode[]) => void
1096 getPreBodyComponents: () => React.ReactNode[]
1097 replacePreBodyComponents: (comp: React.ReactNode[]) => void
1098 getPostBodyComponents: () => React.ReactNode[]
1099 replacePostBodyComponents: (comp: React.ReactNode[]) => void
1100 pathname: string
1101}
1102
1103type ReactProps<T extends Element> = React.DetailedHTMLProps<
1104 React.HTMLAttributes<T>,
1105 T
1106>
1107export interface RenderBodyArgs {
1108 loadPageDataSync: (pathname: string) => { result: Record<string, unknown> }
1109 pathname: string
1110 setHeadComponents: (comp: React.ReactNode[]) => void
1111 setHtmlAttributes: (attr: ReactProps<HTMLHtmlElement>) => void
1112 setBodyAttributes: (attr: ReactProps<HTMLBodyElement>) => void
1113 setPreBodyComponents: (comp: React.ReactNode[]) => void
1114 setPostBodyComponents: (comp: React.ReactNode[]) => void
1115 setBodyProps: Function
1116}
1117
1118export interface ReplaceRendererArgs {
1119 replaceBodyHTMLString: (str: string) => void
1120 bodyComponent: React.ReactNode
1121 setHeadComponents: (comp: React.ReactNode[]) => void
1122 setHtmlAttributes: (attr: ReactProps<HTMLHtmlElement>) => void
1123 setBodyAttributes: (attr: ReactProps<HTMLBodyElement>) => void
1124 setPreBodyComponents: (comp: React.ReactNode[]) => void
1125 setPostBodyComponents: (comp: React.ReactNode[]) => void
1126 setBodyProps: Function
1127 pathname: string
1128}
1129
1130export interface WrapPageElementNodeArgs<
1131 DataType = Record<string, unknown>,
1132 PageContextType = Record<string, unknown>
1133> {
1134 element: React.ReactElement
1135 props: PageProps<DataType, PageContextType>
1136}
1137
1138export interface WrapRootElementNodeArgs {
1139 element: React.ReactElement
1140 pathname: string
1141}
1142
1143export interface ParentSpanPluginArgs extends NodePluginArgs {
1144 parentSpan: Span
1145}
1146
1147export interface NodePluginArgs {
1148 /**
1149 * Use to prefix resources URLs. `pathPrefix` will be either empty string or
1150 * path that starts with slash and doesn't end with slash. `pathPrefix` also
1151 * becomes `<assetPrefix>/<pathPrefix>` when you pass both `assetPrefix` and
1152 * `pathPrefix` in your `gatsby-config.js`.
1153 *
1154 * See [Adding a Path Prefix](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)
1155 * page for details about path prefixing.
1156 */
1157 pathPrefix: string
1158
1159 /**
1160 * This is the same as `pathPrefix` passed in `gatsby-config.js`.
1161 * It's an empty string if you don't pass `pathPrefix`.
1162 * When using assetPrefix, you can use this instead of pathPrefix to recieve the string you set in `gatsby-config.js`.
1163 * It won't include the `assetPrefix`.
1164 */
1165 basePath: string
1166
1167 /**
1168 * Collection of functions used to programmatically modify Gatsby’s internal state.
1169 */
1170 actions: Actions
1171
1172 /**
1173 * Get content for a node from the plugin that created it.
1174 *
1175 * @example
1176 * module.exports = async function onCreateNode(
1177 * { node, loadNodeContent, actions, createNodeId }
1178 * ) {
1179 * if (node.internal.mediaType === 'text/markdown') {
1180 * const { createNode, createParentChildLink } = actions
1181 * const textContent = await loadNodeContent(node)
1182 * // process textContent and create child nodes
1183 * }
1184 * }
1185 */
1186 loadNodeContent(this: void, node: Node): Promise<string>
1187
1188 /**
1189 * Internal redux state used for application state. Do not use, unless you
1190 * absolutely must. Store is considered a private API and can change with
1191 * any version.
1192 */
1193 store: Store
1194
1195 /**
1196 * Internal event emitter / listener. Do not use, unless you absolutely
1197 * must. Emitter is considered a private API and can change with any version.
1198 */
1199 emitter: EventEmitter
1200
1201 /**
1202 * Get array of all nodes.
1203 *
1204 * @returns Array of nodes.
1205 * @example
1206 * const allNodes = getNodes()
1207 */
1208 getNodes(this: void): Node[]
1209
1210 /**
1211 * Get single node by given ID.
1212 * Don't use this in graphql resolvers - see
1213 * `getNodeAndSavePathDependency`
1214 *
1215 * @param id id of the node.
1216 * @returns Single node instance.
1217 * @example
1218 * const node = getNode(id)
1219 */
1220 getNode(this: void, id: string): Node | undefined
1221
1222 /**
1223 * Get array of nodes of given type.
1224 * @param type Type of nodes
1225 * @returns Array of nodes.
1226 *
1227 * @example
1228 * const markdownNodes = getNodesByType(`MarkdownRemark`)
1229 */
1230 getNodesByType(this: void, type: string): Node[]
1231
1232 /**
1233 * Set of utilities to output information to user
1234 */
1235 reporter: Reporter
1236
1237 /**
1238 * Get single node by given ID and create dependency for given path.
1239 * This should be used instead of `getNode` in graphql resolvers to enable
1240 * tracking dependencies for query results. If it's not used Gatsby will
1241 * not rerun query if node changes leading to stale query results. See
1242 * [Page -> Node Dependency Tracking](/docs/page-node-dependencies/)
1243 * for more details.
1244 * @param id id of the node.
1245 * @param path of the node.
1246 * @returns Single node instance.
1247 */
1248 getNodeAndSavePathDependency(this: void, id: string, path: string): Node
1249
1250 /**
1251 * Key-value store used to persist results of time/memory/cpu intensive
1252 * tasks. All functions are async and return promises.
1253 */
1254 cache: GatsbyCache
1255
1256 /**
1257 * Get cache instance by name - this should only be used by plugins that accept subplugins.
1258 * @param id id of the node
1259 * @returns See [cache](https://www.gatsbyjs.com/docs/reference/config-files/node-api-helpers/#cache) section for reference.
1260 */
1261 getCache(this: void, id: string): GatsbyCache
1262
1263 /**
1264 * Utility function useful to generate globally unique and stable node IDs.
1265 * It will generate different IDs for different plugins if they use same
1266 * input.
1267 *
1268 * @returns UUIDv5 ID string
1269 * @example
1270 * const node = {
1271 * id: createNodeId(`${backendData.type}${backendData.id}`),
1272 * ...restOfNodeData
1273 * }
1274 */
1275 createNodeId(this: void, input: string): string
1276
1277 /**
1278 * Create a stable content digest from a string or object, you can use the
1279 * result of this function to set the `internal.contentDigest` field
1280 * on nodes. Gatsby uses the value of this field to invalidate stale data
1281 * when your content changes.
1282 * @param input
1283 * @returns Hash string
1284 * @example
1285 * const node = {
1286 * ...nodeData,
1287 * internal: {
1288 * type: `TypeOfNode`,
1289 * contentDigest: createContentDigest(nodeData)
1290 * }
1291 * }
1292 */
1293 createContentDigest(this: void, input: string | object): string
1294
1295 /**
1296 * Set of utilities that allow adding more detailed tracing for plugins.
1297 * Check
1298 * [Performance tracing](https://www.gatsbyjs.com/docs/performance-tracing)
1299 * page for more details.
1300 */
1301 tracing: Tracing
1302 schema: NodePluginSchema
1303 [key: string]: unknown
1304}
1305
1306interface ActionPlugin {
1307 name: string
1308}
1309
1310interface CreateNodeFieldArgs {
1311 node: Node
1312 name: string
1313 value: string
1314}
1315
1316interface ActionOptions {
1317 [key: string]: unknown
1318}
1319
1320export interface BuildArgs extends ParentSpanPluginArgs {
1321 graphql<TData, TVariables = any>(
1322 query: string,
1323 variables?: TVariables
1324 ): Promise<{
1325 errors?: any
1326 data?: TData
1327 }>
1328}
1329
1330export interface Actions {
1331 /** @see https://www.gatsbyjs.com/docs/actions/#deletePage */
1332 deletePage(this: void, args: { path: string; component: string }): void
1333
1334 /** @see https://www.gatsbyjs.com/docs/actions/#createPage */
1335 createPage<TContext = Record<string, unknown>>(
1336 this: void,
1337 args: Page<TContext>,
1338 plugin?: ActionPlugin,
1339 option?: ActionOptions
1340 ): void
1341
1342 /** @see https://www.gatsbyjs.com/docs/reference/config-files/actions/#createSlice */
1343 createSlice<TContext = Record<string, unknown>>(
1344 this: void,
1345 args: SliceInput<TContext>,
1346 plugin?: ActionPlugin,
1347 option?: ActionOptions
1348 ): void
1349
1350 /** @see https://www.gatsbyjs.com/docs/actions/#deleteNode */
1351 deleteNode(node: NodeInput, plugin?: ActionPlugin): void
1352
1353 /** @see https://www.gatsbyjs.com/docs/actions/#createNode */
1354 createNode<TNode = Record<string, unknown>>(
1355 this: void,
1356 node: NodeInput & TNode,
1357 plugin?: ActionPlugin,
1358 options?: ActionOptions
1359 ): void | Promise<void>
1360
1361 /** @see https://www.gatsbyjs.com/docs/actions/#touchNode */
1362 touchNode(node: NodeInput, plugin?: ActionPlugin): void
1363
1364 /** @see https://www.gatsbyjs.com/docs/actions/#createNodeField */
1365 createNodeField(
1366 this: void,
1367 args: {
1368 node: Node
1369 name?: string
1370 value: any
1371 },
1372 plugin?: ActionPlugin,
1373 options?: ActionOptions
1374 ): void
1375
1376 /** @see https://www.gatsbyjs.com/docs/actions/#createParentChildLink */
1377 createParentChildLink(
1378 this: void,
1379 args: { parent: Node; child: NodeInput },
1380 plugin?: ActionPlugin
1381 ): void
1382
1383 /** @see https://www.gatsbyjs.com/docs/reference/config-files/actions/#unstable_createNodeManifest */
1384 unstable_createNodeManifest(
1385 this: void,
1386 args: {
1387 manifestId: string
1388 node: Node
1389 updatedAtUTC?: string | number
1390 },
1391 plugin?: ActionPlugin
1392 ): void
1393
1394 /** @see https://www.gatsbyjs.com/docs/actions/#setRequestHeaders */
1395 setRequestHeaders(
1396 this: void,
1397 args: { domain: string; headers: Record<string, string> },
1398 plugin?: ActionPlugin
1399 ): void
1400
1401 /** @see https://www.gatsbyjs.com/docs/actions/#setWebpackConfig */
1402 setWebpackConfig(this: void, config: object, plugin?: ActionPlugin): void
1403
1404 /** @see https://www.gatsbyjs.com/docs/actions/#replaceWebpackConfig */
1405 replaceWebpackConfig(this: void, config: object, plugin?: ActionPlugin): void
1406
1407 /** @see https://www.gatsbyjs.com/docs/actions/#setBabelOptions */
1408 setBabelOptions(this: void, options: object, plugin?: ActionPlugin): void
1409
1410 /** @see https://www.gatsbyjs.com/docs/actions/#setBabelPlugin */
1411 setBabelPlugin(
1412 this: void,
1413 config: { name: string; options: object },
1414 plugin?: ActionPlugin
1415 ): void
1416
1417 /** @see https://www.gatsbyjs.com/docs/actions/#setBabelPreset */
1418 setBabelPreset(
1419 this: void,
1420 config: { name: string; options: object },
1421 plugin?: ActionPlugin
1422 ): void
1423
1424 /** @see https://www.gatsbyjs.com/docs/actions/#createJob */
1425 createJob(
1426 this: void,
1427 job: Record<string, unknown> & { id: string },
1428 plugin?: ActionPlugin
1429 ): void
1430
1431 /** @see https://www.gatsbyjs.com/docs/actions/#createJobV2 */
1432 createJobV2(
1433 this: void,
1434 job: {
1435 name: string
1436 inputPaths: string[]
1437 outputDir: string
1438 args: Record<string, unknown>
1439 },
1440 plugin?: ActionPlugin
1441 ): Promise<unknown>
1442
1443 /** @see https://www.gatsbyjs.com/docs/actions/#addGatsbyImageSourceUrl */
1444 addGatsbyImageSourceUrl(this: void, sourceUrl: string): void
1445
1446 /** @see https://www.gatsbyjs.com/docs/actions/#setJob */
1447 setJob(
1448 this: void,
1449 job: Record<string, unknown> & { id: string },
1450 plugin?: ActionPlugin
1451 ): void
1452
1453 /** @see https://www.gatsbyjs.com/docs/actions/#endJob */
1454 endJob(this: void, job: { id: string }, plugin?: ActionPlugin): void
1455
1456 /** @see https://www.gatsbyjs.com/docs/actions/#setPluginStatus */
1457 setPluginStatus(
1458 this: void,
1459 status: Record<string, unknown>,
1460 plugin?: ActionPlugin
1461 ): void
1462
1463 /** @see https://www.gatsbyjs.com/docs/actions/#createRedirect */
1464 createRedirect(
1465 this: void,
1466 redirect: {
1467 fromPath: string
1468 isPermanent?: boolean
1469 toPath: string
1470 redirectInBrowser?: boolean
1471 force?: boolean
1472 statusCode?: number
1473 ignoreCase?: boolean
1474 [key: string]: unknown
1475 },
1476 plugin?: ActionPlugin
1477 ): void
1478
1479 /** @see https://www.gatsbyjs.com/docs/actions/#addThirdPartySchema */
1480 addThirdPartySchema(
1481 this: void,
1482 args: { schema: object },
1483 plugin?: ActionPlugin,
1484 traceId?: string
1485 ): void
1486
1487 /** @see https://www.gatsbyjs.com/docs/actions/#createTypes */
1488 createTypes(
1489 this: void,
1490 types:
1491 | string
1492 | GraphQLOutputType
1493 | GatsbyGraphQLType
1494 | Array<string | GraphQLOutputType | GatsbyGraphQLType>,
1495 plugin?: ActionPlugin,
1496 traceId?: string
1497 ): void
1498
1499 /** @see https://www.gatsbyjs.com/docs/actions/#createFieldExtension */
1500 createFieldExtension(
1501 this: void,
1502 extension: object,
1503 plugin?: ActionPlugin,
1504 traceId?: string
1505 ): void
1506
1507 printTypeDefinitions(
1508 this: void,
1509 options: {
1510 path?: string
1511 include?: { types?: Array<string>; plugins?: Array<string> }
1512 exclude?: { types?: Array<string>; plugins?: Array<string> }
1513 withFieldTypes?: boolean
1514 },
1515 plugin?: ActionPlugin,
1516 traceId?: string
1517 ): void
1518
1519 /**
1520 * Marks the source plugin that called this function as stateful. Gatsby will not check for stale nodes for any plugin that calls this.
1521 */
1522 enableStatefulSourceNodes?(this: void, plugin?: ActionPlugin): void
1523
1524 /** @see https://www.gatsbyjs.com/docs/actions/#addRemoteFileAllowedUrl */
1525 addRemoteFileAllowedUrl?(
1526 this: void,
1527 url: string | Array<string>,
1528 plugin?: ActionPlugin,
1529 traceId?: string
1530 ): void
1531}
1532
1533export interface Store {
1534 dispatch: Function
1535 subscribe: Function
1536 getState: Function
1537 replaceReducer: Function
1538}
1539
1540export type ActivityTracker = {
1541 start(): () => void
1542 end(): () => void
1543 span: Object
1544 setStatus(status: string): void
1545 panic: (errorMeta: string | Object, error?: Object) => never
1546 panicOnBuild: (errorMeta: string | Object, error?: Object) => void
1547}
1548
1549export type ProgressActivityTracker = Omit<ActivityTracker, "end"> & {
1550 tick(increment?: number): void
1551 done(): void
1552 total: number
1553}
1554
1555export type ActivityArgs = {
1556 parentSpan?: Object
1557 id?: string
1558}
1559
1560/**
1561 * @deprecated Use `GatsbyCache` instead
1562 */
1563export interface Cache {
1564 name: string
1565 store: {
1566 create: Function
1567 }
1568 cache: {
1569 getAndPassUp: Function
1570 wrap: Function
1571 set: Function
1572 mset: Function
1573 get: Function
1574 mget: Function
1575 del: Function
1576 reset: Function
1577 }
1578}
1579
1580export interface GatsbyCache {
1581 name: string
1582 directory: string
1583 /**
1584 * Retrieve cached value
1585 * @param key Cache key
1586 * @returns Promise resolving to cached value
1587 * @example
1588 * const value = await cache.get(`unique-key`)
1589 */
1590 get(key: string): Promise<any>
1591
1592 /**
1593 * Cache value
1594 * @param key Cache key
1595 * @param value Value to be cached
1596 * @returns Promise resolving to cached value
1597 * @example
1598 * await cache.set(`unique-key`, value)
1599 */
1600 set(key: string, value: any): Promise<any>
1601
1602 /**
1603 * Deletes cached value
1604 * @param {string} key Cache key
1605 * @returns {Promise<void>} Promise resolving once key is deleted from cache
1606 * @example
1607 * await cache.del(`unique-key`)
1608 */
1609 del(key: string): Promise<void>
1610}
1611
1612export interface Tracing {
1613 tracer: object
1614 parentSpan: object
1615 startSpan: Function
1616}
1617
1618export interface PackageJson {
1619 name?: string
1620 description?: string
1621 version?: string
1622 main?: string
1623 author?:
1624 | string
1625 | {
1626 name: string
1627 email: string
1628 }
1629 license?: string
1630 dependencies?: Record<string, string>
1631 devDependencies?: Record<string, string>
1632 peerDependencies?: Record<string, string>
1633 optionalDependencies?: Record<string, string>
1634 bundledDependencies?: Array<string>
1635 keywords?: string[]
1636}
1637
1638export interface WebpackRules {
1639 js: Function
1640 mjs: Function
1641 eslint: Function
1642 yaml: Function
1643 fonts: Function
1644 images: Function
1645 media: Function
1646 miscAssets: Function
1647 css: Function
1648 cssModules: Function
1649 postcss: Function
1650 [key: string]: Function
1651}
1652
1653export interface WebpackLoaders {
1654 json: Function
1655 yaml: Function
1656 null: Function
1657 raw: Function
1658 style: Function
1659 miniCssExtract: Function
1660 css: Function
1661 postcss: Function
1662 file: Function
1663 url: Function
1664 js: Function
1665 eslint: Function
1666 imports: Function
1667 exports: Function
1668 [key: string]: Function
1669}
1670
1671export interface WebpackPlugins {
1672 normalModuleReplacement: Function
1673 contextReplacement: Function
1674 ignore: Function
1675 watchIgnore: Function
1676 banner: Function
1677 prefetch: Function
1678 automaticPrefetch: Function
1679 define: Function
1680 provide: Function
1681 hotModuleReplacement: Function
1682 sourceMapDevTool: Function
1683 evalSourceMapDevTool: Function
1684 evalDevToolModule: Function
1685 cache: Function
1686 extendedAPI: Function
1687 externals: Function
1688 jsonpTemplate: Function
1689 libraryTemplate: Function
1690 loaderTarget: Function
1691 memoryOutputFile: Function
1692 progress: Function
1693 setVarMainTemplate: Function
1694 umdMainTemplate: Function
1695 noErrors: Function
1696 noEmitOnErrors: Function
1697 newWatching: Function
1698 environment: Function
1699 dll: Function
1700 dllReference: Function
1701 loaderOptions: Function
1702 namedModules: Function
1703 namedChunks: Function
1704 hashedModuleIds: Function
1705 moduleFilenameH: Function
1706 aggressiveMerging: Function
1707 aggressiveSplitting: Function
1708 splitChunks: Function
1709 chunkModuleIdRange: Function
1710 dedupe: Function
1711 limitChunkCount: Function
1712 minChunkSize: Function
1713 occurrenceOrder: Function
1714 moduleConcatenation: Function
1715 minifyJs: Function
1716 minifyCss: Function
1717 extractText: Function
1718 moment: Function
1719 [key: string]: Function
1720}
1721
1722export interface PrefetchPathnameArgs extends BrowserPluginArgs {
1723 pathname: string
1724}
1725
1726export interface RouteUpdateArgs extends BrowserPluginArgs {
1727 location: Location
1728 prevLocation: Location | null
1729}
1730
1731export interface ShouldUpdateScrollArgs extends BrowserPluginArgs {
1732 prevRouterProps?: {
1733 location: Location
1734 }
1735 pathname: string
1736 routerProps: {
1737 location: Location & NavigateOptions<any>
1738 }
1739 getSavedScrollPosition: Function
1740}
1741
1742export interface WrapPageElementBrowserArgs<
1743 DataType = Record<string, unknown>,
1744 PageContextType = Record<string, unknown>,
1745 LocationState = WindowLocation["state"]
1746> extends BrowserPluginArgs {
1747 element: React.ReactElement
1748 props: PageProps<DataType, PageContextType, LocationState>
1749}
1750
1751export interface WrapRootElementBrowserArgs extends BrowserPluginArgs {
1752 element: React.ReactElement
1753 pathname: string
1754}
1755
1756export interface BrowserPluginArgs {
1757 getResourceURLsForPathname: Function
1758 [key: string]: unknown
1759}
1760
1761export interface RouteUpdateDelayedArgs extends BrowserPluginArgs {
1762 location: Location
1763}
1764
1765export interface ServiceWorkerArgs extends BrowserPluginArgs {
1766 serviceWorker: ServiceWorkerRegistration
1767}
1768
1769export interface NodeInput {
1770 id: string
1771 parent?: string | null
1772 children?: string[]
1773 internal: {
1774 type: string
1775 mediaType?: string
1776 content?: string
1777 contentDigest: string
1778 description?: string
1779 contentFilePath?: string
1780 }
1781 [key: string]: unknown
1782}
1783
1784export interface Node extends NodeInput {
1785 parent: string | null
1786 children: string[]
1787 internal: NodeInput["internal"] & {
1788 owner: string
1789 }
1790 [key: string]: unknown
1791}
1792
1793export interface Page<TContext = Record<string, unknown>> {
1794 path: string
1795 matchPath?: string
1796 component: string
1797 context?: TContext
1798 ownerNodeId?: string
1799 defer?: boolean
1800 slices?: Record<string, string>
1801}
1802
1803export interface SliceInput<TContext = Record<string, unknown>> {
1804 id: string
1805 component: string
1806 context?: TContext
1807}
1808
1809export interface IPluginRefObject {
1810 resolve: string
1811 options?: IPluginRefOptions
1812 parentDir?: string
1813 /** @private Internal key used by create-gatsby during plugin installation. Not necessary to define and can be removed. */
1814 __key?: string
1815}
1816
1817export type PluginRef = string | IPluginRefObject
1818
1819export interface IPluginRefOptions {
1820 plugins?: PluginRef[]
1821 path?: string
1822 [option: string]: unknown
1823}
1824
1825export interface PluginOptionsSchemaArgs {
1826 Joi: PluginOptionsSchemaJoi
1827}
1828
1829/**
1830 * Send body of response
1831 */
1832type Send<T> = (body: T) => void
1833
1834/**
1835 * Gatsby Function route response
1836 */
1837export interface GatsbyFunctionResponse<T = any> extends ServerResponse {
1838 /**
1839 * Send `any` data in response
1840 */
1841 send: Send<T>
1842 /**
1843 * Send `JSON` data in response
1844 */
1845 json: Send<T>
1846 /**
1847 * Set the HTTP status code of the response
1848 */
1849 status: (statusCode: number) => GatsbyFunctionResponse<T>
1850 redirect(url: string): GatsbyFunctionResponse<T>
1851 redirect(status: number, url: string): GatsbyFunctionResponse<T>
1852}
1853
1854/**
1855 * Gatsby function route request
1856 */
1857export interface GatsbyFunctionRequest<ReqBody = any> extends IncomingMessage {
1858 /**
1859 * Object of values from URL query parameters (after the ? in the URL)
1860 */
1861 query: Record<string, string>
1862
1863 /**
1864 * Object of values from route parameters
1865 */
1866 params: Record<string, string>
1867 body: ReqBody
1868 /**
1869 * Object of `cookies` from header
1870 */
1871 cookies: Record<string, string>
1872 /**
1873 * Optional field to store the full raw URL by adapters
1874 */
1875 rawUrl?: string
1876}
1877
1878export interface GatsbyFunctionBodyParserCommonMiddlewareConfig {
1879 type?: string
1880 limit?: string | number
1881}
1882
1883export interface GatsbyFunctionBodyParserUrlencodedConfig
1884 extends GatsbyFunctionBodyParserCommonMiddlewareConfig {
1885 extended: boolean
1886}
1887
1888export interface GatsbyFunctionBodyParserConfig {
1889 json?: GatsbyFunctionBodyParserCommonMiddlewareConfig
1890 raw?: GatsbyFunctionBodyParserCommonMiddlewareConfig
1891 text?: GatsbyFunctionBodyParserCommonMiddlewareConfig
1892 urlencoded?: GatsbyFunctionBodyParserUrlencodedConfig
1893}
1894
1895export interface GatsbyFunctionConfig {
1896 bodyParser?: GatsbyFunctionBodyParserConfig
1897}
1898
1899declare module NodeJS {
1900 interface Global {
1901 __GATSBY: {
1902 buildId: string
1903 root: string
1904 }
1905 }
1906}
1907
\No newline at end of file