/
index.d.ts
1541 lines (1399 loc) · 46.5 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as React from "react"
import { Renderer } from "react-dom"
import { EventEmitter } from "events"
import { WindowLocation, NavigateFn, NavigateOptions } from "@reach/router"
import { Reporter } from "gatsby-cli/lib/reporter/reporter"
export { Reporter }
import {
EnumTypeComposerAsObjectDefinition as ComposeEnumTypeConfig,
InputTypeComposerAsObjectDefinition as ComposeInputObjectTypeConfig,
InterfaceTypeComposerAsObjectDefinition as ComposeInterfaceTypeConfig,
ObjectTypeComposerAsObjectDefinition as ComposeObjectTypeConfig,
ScalarTypeComposerAsObjectDefinition as ComposeScalarTypeConfig,
UnionTypeComposerAsObjectDefinition as ComposeUnionTypeConfig,
} from "graphql-compose"
import { GraphQLOutputType } from "graphql"
import { PluginOptionsSchemaJoi, ObjectSchema } from "gatsby-plugin-utils"
import { IncomingMessage, ServerResponse } from "http"
export {
default as Link,
GatsbyLinkProps,
navigate,
withPrefix,
withAssetPrefix,
} from "gatsby-link"
export const useScrollRestoration: (
key: string
) => {
ref: React.MutableRefObject<HTMLElement | undefined>
onScroll(): void
}
export const useStaticQuery: <TData = any>(query: any) => TData
export const parsePath: (path: string) => WindowLocation
export const prefetchPathname: (path: string) => void
/**
* A props object for adding type safety to your Gatsby pages, can be
* extended with both the query response shape, and the page context.
*
* @example
* // When typing a default page from the ./pages dir
*
* import {PageProps} from "gatsby"
* export default (props: PageProps) => {
*
* @example
* // When adding types for both pageContext (represented by LocaleLookUpInfo)
* // and GraphQL query data (represented by IndexQueryProps)
*
* import {PageProps} from "gatsby"
*
* type IndexQueryProps = { downloadCount: number }
* type LocaleLookUpInfo = { translationStrings: any } & { langKey: string, slug: string }
* type IndexPageProps = PageProps<IndexQueryProps, LocaleLookUpInfo>
*
* export default (props: IndexPageProps) => {
* ..
*/
export type PageProps<
DataType = object,
PageContextType = object,
LocationState = WindowLocation["state"]
> = {
/** The path for this current page */
path: string
/** The URI for the current page */
uri: string
/** An extended version of window.document which comes from @react/router */
location: WindowLocation<LocationState>
/** A way to handle programmatically controlling navigation */
navigate: NavigateFn
/** You can't get passed children as this is the root user-land component */
children: undefined
/** The URL parameters when the page has a `matchPath` */
params: Record<string, string>
/** Holds information about the build process for this component */
pageResources: {
component: React.Component
json: {
data: DataType
pageContext: PageContextType
}
page: {
componentChunkName: string
path: string
webpackCompilationHash: string
matchPath?: string
}
}
/**
* Data passed into the page via an exported GraphQL query. To set up this type
* you need to use [generics](https://www.typescriptlang.org/play/#example/generic-functions),
* see below for an example
*
* @example
*
* import {PageProps} from "gatsby"
*
* type IndexQueryProps = { downloadCount: number }
* type IndexPageProps = PageProps<IndexQueryProps>
*
* export default (props: IndexPageProps) => {
* ..
*
*/
data: DataType
/**
* A context object which is passed in during the creation of the page. Can be extended if you are using
* `createPage` yourself using generics:
*
* @example
*
* import {PageProps} from "gatsby"
*
* type IndexQueryProps = { downloadCount: number }
* type LocaleLookUpInfo = { translationStrings: any } & { langKey: string, slug: string }
* type IndexPageProps = PageProps<IndexQueryProps, LocaleLookUpInfo>
*
* export default (props: IndexPageProps) => {
* ..
*/
pageContext: PageContextType
}
export interface PageRendererProps {
location: WindowLocation
}
/**
* PageRenderer's constructor [loads the page resources](https://www.gatsbyjs.org/docs/production-app/#load-page-resources) for the path.
*
* 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).
* 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.
*
* @see https://www.gatsbyjs.org/docs/production-app/#page-rendering
*/
export class PageRenderer extends React.Component<PageRendererProps> {}
type RenderCallback<T = any> = (data: T) => React.ReactNode
export interface StaticQueryProps<T = any> {
query: any
render?: RenderCallback<T>
children?: RenderCallback<T>
}
/**
* StaticQuery can do most of the things that page query can, including fragments. The main differences are:
*
* - page queries can accept variables (via `pageContext`) but can only be added to _page_ components
* - StaticQuery does not accept variables (hence the name "static"), but can be used in _any_ component, including pages
* - StaticQuery does not work with raw React.createElement calls; please use JSX, e.g. `<StaticQuery />`
*
* @see https://www.gatsbyjs.org/docs/static-query/
*/
export class StaticQuery<T = any> extends React.Component<
StaticQueryProps<T>
> {}
/**
* graphql is a tag function. Behind the scenes Gatsby handles these tags in a particular way
*
* During the Gatsby build process, GraphQL queries are pulled out of the original source for parsing.
*
* @see https://www.gatsbyjs.org/docs/page-query#how-does-the-graphql-tag-work
*/
export const graphql: (query: TemplateStringsArray) => void
/**
* Gatsby configuration API.
*
* @see https://www.gatsbyjs.org/docs/gatsby-config/
*/
export interface GatsbyConfig {
/** When you want to reuse common pieces of data across the site (for example, your site title), you can store that here. */
siteMetadata?: Record<string, unknown>
/** 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. */
plugins?: Array<PluginRef>
/** 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. */
flags?: Record<string, boolean>
/** 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. */
pathPrefix?: string
/** 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 */
assetPrefix?: string
/** 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.*/
polyfill?: boolean
mapping?: Record<string, string>
/**
* Setting the proxy config option will tell the develop server to proxy any unknown requests to your specified server.
* @see https://www.gatsbyjs.org/docs/api-proxy/
* */
proxy?: {
prefix: string
url: string
}
/** 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. */
developMiddleware?(app: any): void
}
/**
* Gatsby API for Node.js.
*
* @see https://www.gatsbyjs.org/docs/node-apis/
*/
export interface GatsbyNode<
TNode extends Record<string, unknown> = Record<string, unknown>,
TContext = Record<string, unknown>
> {
/**
* Tell plugins to add pages. This extension point is called only after the initial
* sourcing and transformation of nodes plus creation of the GraphQL schema are
* complete so you can query your data in order to create pages.
*
* @see https://www.gatsbyjs.org/docs/node-apis/#createPages
*/
createPages?(
args: CreatePagesArgs & {
traceId: "initial-createPages"
},
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/**
* Like `createPages` but for plugins who want to manage creating and removing
* pages themselves in response to changes in data *not* managed by Gatsby.
* Plugins implementing `createPages` will get called regularly to recompute
* page information as Gatsby's data changes but those implementing
* `createPagesStatefully` will not.
*
* An example of a plugin that uses this extension point is the plugin
* [gatsby-plugin-page-creator](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-page-creator)
* which monitors the `src/pages` directory for the adding and removal of JS
* pages. As its source of truth, files in the pages directory, is not known by
* Gatsby, it needs to keep its own state about its world to know when to
* add and remove pages.
*/
createPagesStatefully?(
args: CreatePagesArgs & {
traceId: "initial-createPagesStatefully"
},
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/**
* Let plugins extend/mutate the site's Babel configuration.
* This API will change before 2.0 as it needs still to be converted to use
* Redux actions.
*/
onCreateBabelConfig?(
args: CreateBabelConfigArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/**
* Run when gatsby develop server is started, its useful to add proxy and middleware
* to the dev server app
* @param {object} $0
* @param {Express} $0.app The [Express app](https://expressjs.com/en/4x/api.html#app) used to run the dev server
*
* @example
*
* exports.onCreateDevServer = ({ app }) => {
* app.get('/hello', function (req, res) {
* res.send('hello world')
* })
* }
*/
onCreateDevServer?(
args: CreateDevServerArgs,
options: PluginOptions,
calllback: PluginCallback<void>
): void | Promise<void>
/**
* Called when a new node is created. Plugins wishing to extend or
* transform nodes created by other plugins should implement this API.
*
* See also the documentation for `createNode`
* and [`createNodeField`](https://www.gatsbyjs.org/docs/actions/#createNodeField)
* @example
* exports.onCreateNode = ({ node, actions }) => {
* const { createNode, createNodeField } = actions
* // Transform the new node here and create a new node or
* // create a new node field.
* }
*/
onCreateNode?(
args: CreateNodeArgs<TNode>,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/**
* Called before scheduling a `onCreateNode` callback for a plugin. If it returns falsy
* then Gatsby will not schedule the `onCreateNode` callback for this node for this plugin.
* Note: this API does not receive the regular `api` that other callbacks get as first arg.
*
* @gatsbyVersion 2.24.80
* @example
* exports.unstable_shouldOnCreateNode = ({node}, pluginOptions) => node.internal.type === 'Image'
*/
unstable_shouldOnCreateNode?(
args: { node: TNode },
options: PluginOptions
): boolean
/**
* Called when a new page is created. This extension API is useful
* for programmatically manipulating pages created by other plugins e.g.
* if you want paths without trailing slashes.
*
* See the guide [Creating and Modifying Pages](https://www.gatsbyjs.org/docs/creating-and-modifying-pages/)
* for more on this API.
*/
onCreatePage?(
args: CreatePageArgs<TContext>,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/**
* Let plugins extend/mutate the site's webpack configuration.
* @see https://www.gatsbyjs.org/docs/node-apis/#onCreateWebpackConfig
*/
onCreateWebpackConfig?(
args: CreateWebpackConfigArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/** Called at the end of the bootstrap process after all other extension APIs have been called. */
onPostBootstrap?(
args: ParentSpanPluginArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/** The last extension point called after all other parts of the build process are complete. */
onPostBuild?(
args: BuildArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/** Called at the end of the bootstrap process after all other extension APIs have been called. */
onPreBootstrap?(
args: ParentSpanPluginArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/** The first extension point called during the build process. Called after the bootstrap has completed but before the build steps start. */
onPreBuild?(
args: BuildArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/** Called once Gatsby has initialized itself and is ready to bootstrap your site. */
onPreExtractQueries?(
args: ParentSpanPluginArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/** The first API called during Gatsby execution, runs as soon as plugins are loaded, before cache initialization and bootstrap preparation. */
onPreInit?(
args: ParentSpanPluginArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/**
* Ask compile-to-js plugins to process source to JavaScript so the query
* runner can extract out GraphQL queries for running.
*/
preprocessSource?(
args: PreprocessSourceArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/**
* Lets plugins implementing support for other compile-to-js add to the list of "resolvable" file extensions. Gatsby supports `.js` and `.jsx` by default.
*/
resolvableExtensions?(
args: ResolvableExtensionsArgs,
options: PluginOptions,
callback: PluginCallback<Array<string>>
): Array<string> | Promise<Array<string>>
/**
* Called during the creation of the GraphQL schema. Allows plugins
* to add new fields to the types created from data nodes. It will be called
* separately for each type.
*
* This function should return an object in the shape of
* [GraphQLFieldConfigMap](https://graphql.org/graphql-js/type/#graphqlobjecttype)
* which will be appended to fields inferred by Gatsby from data nodes.
*
* *Note:* Import GraphQL types from `gatsby/graphql` and don't add the `graphql`
* package to your project/plugin dependencies to avoid Schema must
* contain unique named types but contains multiple types named errors.
* `gatsby/graphql` exports all builtin GraphQL types as well as the `graphQLJSON`
* type.
*
* Many transformer plugins use this to add fields that take arguments.
*
* @see https://www.gatsbyjs.org/docs/node-apis/#setFieldsOnGraphQLNodeType
*/
setFieldsOnGraphQLNodeType?(
args: SetFieldsOnGraphQLNodeTypeArgs,
options: PluginOptions,
callback: PluginCallback<any>
): any
/**
* Extension point to tell plugins to source nodes. This API is called during
* the Gatsby bootstrap sequence. Source plugins use this hook to create nodes.
* This API is called exactly once per plugin (and once for your site's
* `gatsby-config.js` file). If you define this hook in `gatsby-node.js` it
* will be called exactly once after all of your source plugins have finished
* creating nodes.
*
* @see https://www.gatsbyjs.org/docs/node-apis/#sourceNodes
*/
sourceNodes?(
args: SourceNodesArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/**
* Add custom field resolvers to the GraphQL schema.
*
* Allows adding new fields to types by providing field configs, or adding resolver
* functions to existing fields.
*
* Things to note:
* * Overriding field types is disallowed, instead use the `createTypes`
* action. In case of types added from third-party schemas, where this is not
* possible, overriding field types is allowed.
* * New fields will not be available on `filter` and `sort` input types. Extend
* types defined with `createTypes` if you need this.
* * In field configs, types can be referenced as strings.
* * When extending a field with an existing field resolver, the original
* resolver function is available from `info.originalResolver`.
* * The `createResolvers` API is called as the last step in schema generation.
* Thus, an intermediate schema is made available on the `schema` property.
* In resolver functions themselves, it is recommended to access the final
* built schema from `info.schema`.
* * Gatsby's data layer, including all internal query capabilities, is
* exposed on [`context.nodeModel`](/docs/node-model/). The node store can be
* queried directly with `getAllNodes`, `getNodeById` and `getNodesByIds`,
* while more advanced queries can be composed with `runQuery`. Note that
* `runQuery` will call field resolvers before querying, so e.g. foreign-key
* fields will be expanded to full nodes. The other methods on `nodeModel`
* don't do this.
* * It is possible to add fields to the root `Query` type.
* * When using the first resolver argument (`source` in the example below,
* often also called `parent` or `root`), take care of the fact that field
* resolvers can be called more than once in a query, e.g. when the field is
* present both in the input filter and in the selection set. This means that
* foreign-key fields on `source` can be either resolved or not-resolved.
*
* For fuller examples, see [`using-type-definitions`](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-type-definitions).
*
* @see https://www.gatsbyjs.org/docs/node-apis/#createResolvers
*/
createResolvers?(
args: CreateResolversArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/**
* Customize Gatsby’s GraphQL schema by creating type definitions, field extensions or adding third-party schemas.
* The createTypes, createFieldExtension and addThirdPartySchema actions are only available in this API.
*
* For details on their usage please refer to the actions documentation.
*
* This API runs immediately before schema generation. For modifications of the generated schema, e.g.
* to customize added third-party types, use the createResolvers API.
* @see https://www.gatsbyjs.org/docs/node-apis/#createSchemaCustomization
*/
createSchemaCustomization?(
args: CreateSchemaCustomizationArgs,
options: PluginOptions,
callback: PluginCallback<void>
): void | Promise<void>
/**
* Add a Joi schema for the possible options of your plugin.
* Currently experimental and not enabled by default.
*/
pluginOptionsSchema?(args: PluginOptionsSchemaArgs): ObjectSchema
}
/**
* Gatsby browser API.
*
* @see https://www.gatsbyjs.org/docs/browser-apis/
*/
export interface GatsbyBrowser<
DataType = Record<string, unknown>,
PageContext = Record<string, unknown>,
LocationState = WindowLocation["state"]
> {
disableCorePrefetching?(
args: BrowserPluginArgs,
options: PluginOptions
): boolean
onClientEntry?(args: BrowserPluginArgs, options: PluginOptions): void
onInitialClientRender?(args: BrowserPluginArgs, options: PluginOptions): void
onPostPrefetchPathname?(
args: PrefetchPathnameArgs,
options: PluginOptions
): void
onPreRouteUpdate?(args: RouteUpdateArgs, options: PluginOptions): void
onPrefetchPathname?(args: PrefetchPathnameArgs, options: PluginOptions): void
onRouteUpdate?(args: RouteUpdateArgs, options: PluginOptions): void
onRouteUpdateDelayed?(
args: RouteUpdateDelayedArgs,
options: PluginOptions
): void
onServiceWorkerActive?(args: ServiceWorkerArgs, options: PluginOptions): void
onServiceWorkerInstalled?(
args: ServiceWorkerArgs,
options: PluginOptions
): void
onServiceWorkerRedundant?(
args: ServiceWorkerArgs,
options: PluginOptions
): void
onServiceWorkerUpdateFound?(
args: ServiceWorkerArgs,
options: PluginOptions
): void
onServiceWorkerUpdateReady?(
args: ServiceWorkerArgs,
options: PluginOptions
): void
registerServiceWorker?(
args: BrowserPluginArgs,
options: PluginOptions
): boolean
replaceHydrateFunction?(
args: BrowserPluginArgs,
options: PluginOptions
): Renderer
shouldUpdateScroll?(
args: ShouldUpdateScrollArgs,
options: PluginOptions
): boolean | [number, number] | string
wrapPageElement?(
args: WrapPageElementBrowserArgs<DataType, PageContext, LocationState>,
options: PluginOptions
): React.ReactElement
wrapRootElement?(
args: WrapRootElementBrowserArgs,
options: PluginOptions
): React.ReactElement
}
/**
* Gatsby server-side rendering API.
*
* @see https://www.gatsbyjs.org/docs/ssr-apis/
*/
export interface GatsbySSR<
DataSet = Record<string, unknown>,
PageContext = Record<string, unknown>
> {
/**
* Called after every page Gatsby server renders while building HTML so you can
* replace head components to be rendered in your `html.js`. This is useful if
* you need to reorder scripts or styles added by other plugins.
* @example
* // Move Typography.js styles to the top of the head section so they're loaded first.
* exports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
* const headComponents = getHeadComponents()
* headComponents.sort((x, y) => {
* if (x.key === 'TypographyStyle') {
* return -1
* } else if (y.key === 'TypographyStyle') {
* return 1
* }
* return 0
* })
* replaceHeadComponents(headComponents)
* }
*/
onPreRenderHTML?(args: PreRenderHTMLArgs, options: PluginOptions): void
/**
* Called after every page Gatsby server renders while building HTML so you can
* set head and body components to be rendered in your `html.js`.
*
* Gatsby does a two-pass render for HTML. It loops through your pages first
* rendering only the body and then takes the result body HTML string and
* passes it as the `body` prop to your `html.js` to complete the render.
*
* It's often handy to be able to send custom components to your `html.js`.
* For example, it's a very common pattern for React.js libraries that
* support server rendering to pull out data generated during the render to
* add to your HTML.
*
* Using this API over `replaceRenderer` is preferable as
* multiple plugins can implement this API where only one plugin can take
* over server rendering. However, if your plugin requires taking over server
* rendering then that's the one to use
* @example
* const { Helmet } = require("react-helmet")
*
* exports.onRenderBody = (
* { setHeadComponents, setHtmlAttributes, setBodyAttributes },
* pluginOptions
* ) => {
* const helmet = Helmet.renderStatic()
* setHtmlAttributes(helmet.htmlAttributes.toComponent())
* setBodyAttributes(helmet.bodyAttributes.toComponent())
* setHeadComponents([
* helmet.title.toComponent(),
* helmet.link.toComponent(),
* helmet.meta.toComponent(),
* helmet.noscript.toComponent(),
* helmet.script.toComponent(),
* helmet.style.toComponent(),
* ])
* }
*/
onRenderBody?(args: RenderBodyArgs, options: PluginOptions): void
/**
* Replace the default server renderer. This is useful for integration with
* Redux, css-in-js libraries, etc. that need custom setups for server
* rendering.
* @example
* // From gatsby-plugin-glamor
* const { renderToString } = require("react-dom/server")
* const inline = require("glamor-inline")
*
* exports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
* const bodyHTML = renderToString(bodyComponent)
* const inlinedHTML = inline(bodyHTML)
*
* replaceBodyHTMLString(inlinedHTML)
* }
*/
replaceRenderer?(args: ReplaceRendererArgs, options: PluginOptions): void
/**
* Allow a plugin to wrap the page element.
*
* This is useful for setting wrapper component around pages that won't get
* unmounted on page change. For setting Provider components use `wrapRootElement`.
*
* _Note:_ [There is equivalent hook in Browser API](https://www.gatsbyjs.org/docs/browser-apis/#wrapPageElement)
* @example
* const React = require("react")
* const Layout = require("./src/components/layout")
*
* exports.wrapPageElement = ({ element, props }) => {
* // props provide same data to Layout as Page element will get
* // including location, data, etc - you don't need to pass it
* return <Layout {...props}>{element}</Layout>
* }
*/
wrapPageElement?(
args: WrapPageElementNodeArgs<DataSet, PageContext>,
options: PluginOptions
): React.ReactElement
/**
* Allow a plugin to wrap the root element.
*
* This is useful to setup any Providers component that will wrap your application.
* For setting persistent UI elements around pages use `wrapPageElement`.
*
* _Note:_ [There is equivalent hook in Browser API](https://www.gatsbyjs.org/docs/browser-apis/#wrapRootElement)
* @example
* const React = require("react")
* const { Provider } = require("react-redux")
*
* const createStore = require("./src/state/createStore")
* const store = createStore()
*
* exports.wrapRootElement = ({ element }) => {
* return (
* <Provider store={store}>
* {element}
* </Provider>
* )
* }
*/
wrapRootElement?(
args: WrapRootElementNodeArgs,
options: PluginOptions
): React.ReactElement
}
export interface PluginOptions {
plugins: unknown[]
[key: string]: unknown
}
export type PluginCallback<R = any> = (err: Error | null, result?: R) => void
export interface CreatePagesArgs extends ParentSpanPluginArgs {
graphql<TData, TVariables = any>(
query: string,
variables?: TVariables
): Promise<{
errors?: any
data?: TData
}>
traceId: string
waitForCascadingActions: boolean
}
type GatsbyStages =
| "develop"
| "develop-html"
| "build-javascript"
| "build-html"
export interface CreateBabelConfigArgs extends ParentSpanPluginArgs {
stage: GatsbyStages
}
export interface CreateDevServerArgs extends ParentSpanPluginArgs {
app: any
}
export interface CreateNodeArgs<
TNode extends Record<string, unknown> = Record<string, unknown>
> extends ParentSpanPluginArgs {
node: Node & TNode
traceId: string
traceTags: {
nodeId: string
nodeType: string
}
}
export interface CreatePageArgs<TContext = Record<string, unknown>>
extends ParentSpanPluginArgs {
page: Page<TContext>
traceId: string
}
export interface CreateWebpackConfigArgs extends ParentSpanPluginArgs {
getConfig: Function
stage: GatsbyStages
rules: WebpackRules
loaders: WebpackLoaders
plugins: WebpackPlugins
}
export interface PreprocessSourceArgs extends ParentSpanPluginArgs {
filename: string
contents: string
}
export interface ResolvableExtensionsArgs extends ParentSpanPluginArgs {
traceId: "initial-resolvableExtensions"
}
export interface SetFieldsOnGraphQLNodeTypeArgs extends ParentSpanPluginArgs {
type: {
name: string
nodes: any[]
}
traceId: "initial-setFieldsOnGraphQLNodeType"
}
export interface GatsbyGraphQLObjectType {
kind: "OBJECT"
config: ComposeObjectTypeConfig<any, any>
}
export interface GatsbyGraphQLInputObjectType {
kind: "INPUT_OBJECT"
config: ComposeInputObjectTypeConfig
}
export interface GatsbyGraphQLUnionType {
kind: "UNION"
config: ComposeUnionTypeConfig<any, any>
}
export interface GatsbyGraphQLInterfaceType {
kind: "INTERFACE"
config: ComposeInterfaceTypeConfig<any, any>
}
export interface GatsbyGraphQLEnumType {
kind: "ENUM"
config: ComposeEnumTypeConfig
}
export interface GatsbyGraphQLScalarType {
kind: "SCALAR"
config: ComposeScalarTypeConfig
}
export type GatsbyGraphQLType =
| GatsbyGraphQLObjectType
| GatsbyGraphQLInputObjectType
| GatsbyGraphQLUnionType
| GatsbyGraphQLInterfaceType
| GatsbyGraphQLEnumType
| GatsbyGraphQLScalarType
export interface NodePluginSchema {
buildObjectType(
config: ComposeObjectTypeConfig<any, any>
): GatsbyGraphQLObjectType
buildUnionType(
config: ComposeUnionTypeConfig<any, any>
): GatsbyGraphQLUnionType
buildInterfaceType(
config: ComposeInterfaceTypeConfig<any, any>
): GatsbyGraphQLInterfaceType
buildInputObjectType(
config: ComposeInputObjectTypeConfig
): GatsbyGraphQLInputObjectType
buildEnumType(config: ComposeEnumTypeConfig): GatsbyGraphQLEnumType
buildScalarType(config: ComposeScalarTypeConfig): GatsbyGraphQLScalarType
}
export interface SourceNodesArgs extends ParentSpanPluginArgs {
traceId: "initial-sourceNodes"
waitForCascadingActions: boolean
}
export interface CreateResolversArgs extends ParentSpanPluginArgs {
intermediateSchema: object
createResolvers: Function
traceId: "initial-createResolvers"
}
export interface CreateSchemaCustomizationArgs extends ParentSpanPluginArgs {
traceId: "initial-createSchemaCustomization"
}
export interface PreRenderHTMLArgs extends NodePluginArgs {
getHeadComponents: () => React.ReactNode[]
replaceHeadComponents: (comp: React.ReactNode[]) => void
getPreBodyComponents: () => React.ReactNode[]
replacePreBodyComponents: (comp: React.ReactNode[]) => void
getPostBodyComponents: () => React.ReactNode[]
replacePostBodyComponents: (comp: React.ReactNode[]) => void
}
type ReactProps<T extends Element> = React.DetailedHTMLProps<
React.HTMLAttributes<T>,
T
>
export interface RenderBodyArgs extends NodePluginArgs {
pathname: string
setHeadComponents: (comp: React.ReactNode[]) => void
setHtmlAttributes: (attr: ReactProps<HTMLHtmlElement>) => void
setBodyAttributes: (attr: ReactProps<HTMLBodyElement>) => void
setPreBodyComponents: (comp: React.ReactNode[]) => void
setPostBodyComponents: (comp: React.ReactNode[]) => void
setBodyProps: Function
}
export interface ReplaceRendererArgs extends NodePluginArgs {
replaceBodyHTMLString: (str: string) => void
bodyComponent: React.ReactNode
setHeadComponents: (comp: React.ReactNode[]) => void
setHtmlAttributes: (attr: ReactProps<HTMLHtmlElement>) => void
setBodyAttributes: (attr: ReactProps<HTMLBodyElement>) => void
setPreBodyComponents: (comp: React.ReactNode[]) => void
setPostBodyComponents: (comp: React.ReactNode[]) => void
setBodyProps: Function
}
export interface WrapPageElementNodeArgs<
DataType = Record<string, unknown>,
PageContextType = Record<string, unknown>
> extends NodePluginArgs {
element: React.ReactElement
props: PageProps<DataType, PageContextType>
pathname: string
}
export interface WrapRootElementNodeArgs extends NodePluginArgs {
element: React.ReactElement
}
export interface ParentSpanPluginArgs extends NodePluginArgs {
parentSpan: object
}
export interface NodePluginArgs {
/**
* Use to prefix resources URLs. `pathPrefix` will be either empty string or
* path that starts with slash and doesn't end with slash. Check
* [Adding a Path Prefix](https://www.gatsbyjs.org/docs/path-prefix/)
* page for details about path prefixing.
*/
pathPrefix: string
/**
* Collection of functions used to programmatically modify Gatsby’s internal state.
*/
actions: Actions
/**
* Get content for a node from the plugin that created it.
*
* @example
* module.exports = async function onCreateNode(
* { node, loadNodeContent, actions, createNodeId }
* ) {
* if (node.internal.mediaType === 'text/markdown') {
* const { createNode, createParentChildLink } = actions
* const textContent = await loadNodeContent(node)
* // process textContent and create child nodes
* }
* }
*/
loadNodeContent(node: Node): Promise<string>
/**
* Internal redux state used for application state. Do not use, unless you
* absolutely must. Store is considered a private API and can change with
* any version.
*/
store: Store
/**
* Internal event emitter / listener. Do not use, unless you absolutely
* must. Emitter is considered a private API and can change with any version.
*/
emitter: EventEmitter
/**
* Get array of all nodes.
*
* @returns Array of nodes.
* @example
* const allNodes = getNodes()
*/
getNodes(): Node[]
/**
* Get single node by given ID.
* Don't use this in graphql resolvers - see
* `getNodeAndSavePathDependency`
*
* @param id id of the node.
* @returns Single node instance.
* @example
* const node = getNode(id)
*/
getNode(id: string): Node
/**
* Get array of nodes of given type.
* @param type Type of nodes
* @returns Array of nodes.
*
* @example
* const markdownNodes = getNodesByType(`MarkdownRemark`)
*/
getNodesByType(type: string): Node[]
/**
* Set of utilities to output information to user
*/
reporter: Reporter
/**
* Get single node by given ID and create dependency for given path.
* This should be used instead of `getNode` in graphql resolvers to enable
* tracking dependencies for query results. If it's not used Gatsby will
* not rerun query if node changes leading to stale query results. See
* [Page -> Node Dependency Tracking](/docs/page-node-dependencies/)
* for more details.
* @param id id of the node.
* @param path of the node.
* @returns Single node instance.
*/
getNodeAndSavePathDependency(id: string, path: string): Node
/**
* Key-value store used to persist results of time/memory/cpu intensive
* tasks. All functions are async and return promises.