UNPKG

15 kBJavaScriptView Raw
1"use strict";
2
3/**
4 * Lets plugins implementing support for other compile-to-js add to the list
5 * of "resolvable" file extensions. Gatsby supports `.js` and `.jsx` by default.
6 * @returns {Array<string>} array of extensions
7 */
8exports.resolvableExtensions = true;
9/**
10 * Tell plugins to add pages. This extension point is called only after the initial
11 * sourcing and transformation of nodes plus creation of the GraphQL schema are
12 * complete so you can query your data in order to create pages.
13 *
14 * See also [the documentation for the action `createPage`](/docs/actions/#createPage).
15 * @example
16 * const path = require(`path`)
17 *
18 * exports.createPages = ({ graphql, actions }) => {
19 * const { createPage } = actions
20 * const blogPostTemplate = path.resolve(`src/templates/blog-post.js`)
21 * // Query for markdown nodes to use in creating pages.
22 * // You can query for whatever data you want to create pages for e.g.
23 * // products, portfolio items, landing pages, etc.
24 * // Variables can be added as the second function parameter
25 * return graphql(`
26 * query loadPagesQuery ($limit: Int!) {
27 * allMarkdownRemark(limit: $limit) {
28 * edges {
29 * node {
30 * frontmatter {
31 * slug
32 * }
33 * }
34 * }
35 * }
36 * }
37 * `, { limit: 1000 }).then(result => {
38 * if (result.errors) {
39 * throw result.errors
40 * }
41 *
42 * // Create blog post pages.
43 * result.data.allMarkdownRemark.edges.forEach(edge => {
44 * createPage({
45 * // Path for this page — required
46 * path: `${edge.node.frontmatter.slug}`,
47 * component: blogPostTemplate,
48 * context: {
49 * // Add optional context data to be inserted
50 * // as props into the page component..
51 * //
52 * // The context data can also be used as
53 * // arguments to the page GraphQL query.
54 * //
55 * // The page "path" is always available as a GraphQL
56 * // argument.
57 * },
58 * })
59 * })
60 * })
61 * }
62 */
63
64exports.createPages = true;
65/**
66 * Like `createPages` but for plugins who want to manage creating and removing
67 * pages themselves in response to changes in data *not* managed by Gatsby.
68 * Plugins implementing `createPages` will get called regularly to recompute
69 * page information as Gatsby's data changes but those implementing
70 * `createPagesStatefully` will not.
71 *
72 * An example of a plugin that uses this extension point is the plugin
73 * [gatsby-plugin-page-creator](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-page-creator)
74 * which monitors the `src/pages` directory for the adding and removal of JS
75 * pages. As its source of truth, files in the pages directory, is not known by
76 * Gatsby, it needs to keep its own state about its world to know when to
77 * add and remove pages.
78 */
79
80exports.createPagesStatefully = true;
81/**
82 * Extension point to tell plugins to source nodes. This API is called during
83 * the Gatsby bootstrap sequence. Source plugins use this hook to create nodes.
84 * This API is called exactly once per plugin (and once for your site's
85 * `gatsby-config.js` file). If you define this hook in `gatsby-node.js` it
86 * will be called exactly once after all of your source plugins have finished
87 * creating nodes.
88 *
89 * See also the documentation for [`createNode`](/docs/actions/#createNode).
90 * @example
91 * exports.sourceNodes = ({ actions, createNodeId, createContentDigest }) => {
92 * const { createNode } = actions
93 *
94 * // Data can come from anywhere, but for now create it manually
95 * const myData = {
96 * key: 123,
97 * foo: `The foo field of my node`,
98 * bar: `Baz`
99 * }
100 *
101 * const nodeContent = JSON.stringify(myData)
102 *
103 * const nodeMeta = {
104 * id: createNodeId(`my-data-${myData.key}`),
105 * parent: null,
106 * children: [],
107 * internal: {
108 * type: `MyNodeType`,
109 * mediaType: `text/html`,
110 * content: nodeContent,
111 * contentDigest: createContentDigest(myData)
112 * }
113 * }
114 *
115 * const node = Object.assign({}, myData, nodeMeta)
116 * createNode(node)
117 * }
118 */
119
120exports.sourceNodes = true;
121/**
122 * Called when a new node is created. Plugins wishing to extend or
123 * transform nodes created by other plugins should implement this API.
124 *
125 * See also the documentation for [`createNode`](/docs/actions/#createNode)
126 * and [`createNodeField`](/docs/actions/#createNodeField)
127 * @example
128 * exports.onCreateNode = ({ node, actions }) => {
129 * const { createNode, createNodeField } = actions
130 * // Transform the new node here and create a new node or
131 * // create a new node field.
132 * }
133 */
134
135exports.onCreateNode = true;
136/**
137 * Called when a new page is created. This extension API is useful
138 * for programmatically manipulating pages created by other plugins e.g.
139 * if you want paths without trailing slashes.
140 *
141 * There is a mechanism in Gatsby to prevent calling onCreatePage for pages
142 * created by the same gatsby-node.js to avoid infinite loops/callback.
143 *
144 * See the guide [Creating and Modifying Pages](/docs/creating-and-modifying-pages/)
145 * for more on this API.
146 */
147
148exports.onCreatePage = true;
149/**
150 * Called during the creation of the GraphQL schema. Allows plugins
151 * to add new fields to the types created from data nodes. It will be called
152 * separately for each type.
153 *
154 * This function should return an object in the shape of
155 * [GraphQLFieldConfigMap](https://graphql.org/graphql-js/type/#graphqlobjecttype)
156 * which will be appended to fields inferred by Gatsby from data nodes.
157 *
158 * *Note:* Import GraphQL types from `gatsby/graphql` and don't add the `graphql`
159 * package to your project/plugin dependencies to avoid `Schema must
160 * contain unique named types but contains multiple types named` errors.
161 * `gatsby/graphql` exports all builtin GraphQL types as well as the `GraphQLJSON`
162 * type.
163 *
164 * Many transformer plugins use this to add fields that take arguments.
165 *
166 * * [`gatsby-transformer-remark`](/packages/gatsby-transformer-remark/)
167 * adds an "excerpt" field where the user when writing their query can specify
168 * how many characters to prune the markdown source to.
169 * * [`gatsby-transformer-sharp`](/packages/gatsby-transformer-sharp/) exposes
170 * many image transformation options as GraphQL fields.
171 *
172 * @param {object} $0
173 * @param {object} $0.type Object containing `name` and `nodes`
174 * @example
175 * import { GraphQLString } from "gatsby/graphql"
176 *
177 * exports.setFieldsOnGraphQLNodeType = ({ type }) => {
178 * if (type.name === `File`) {
179 * return {
180 * newField: {
181 * type: GraphQLString,
182 * args: {
183 * myArgument: {
184 * type: GraphQLString,
185 * }
186 * },
187 * resolve: (source, fieldArgs) => {
188 * return `Id of this node is ${source.id}.
189 * Field was called with argument: ${fieldArgs.myArgument}`
190 * }
191 * }
192 * }
193 * }
194 *
195 * // by default return empty object
196 * return {}
197 * }
198 */
199
200exports.setFieldsOnGraphQLNodeType = true;
201/**
202 * Customize Gatsby's GraphQL schema by creating type definitions, field
203 * extensions or adding third-party schemas.
204 *
205 * The [`createTypes`](/docs/actions/#createTypes),
206 * [`createFieldExtension`](/docs/actions/#createFieldExtension) and
207 * [`addThirdPartySchema`](/docs/actions/#addThirdPartySchema) actions
208 * are only available in this API. For details on their usage please refer to
209 * the actions documentation.
210 *
211 * This API runs immediately before schema generation. For modifications of the
212 * generated schema, e.g. to customize added third-party types, use the
213 * [`createResolvers`](/docs/node-apis/#createResolvers) API.
214 *
215 * @gatsbyVersion 2.12.0
216 * @param {object} $0
217 * @param {object} $0.actions
218 * @param {object} $0.actions.createTypes
219 * @param {object} $0.actions.createFieldExtension
220 * @param {object} $0.actions.addThirdPartySchema
221 * @example
222 * exports.createSchemaCustomization = ({ actions }) => {
223 * const { createTypes, createFieldExtension } = actions
224 *
225 * createFieldExtension({
226 * name: 'shout',
227 * extend: () => ({
228 * resolve(source, args, context, info) {
229 * return String(source[info.fieldName]).toUpperCase()
230 * }
231 * })
232 * })
233 *
234 * const typeDefs = `
235 * type MarkdownRemark implements Node @dontInfer {
236 * frontmatter: Frontmatter
237 * }
238 * type Frontmatter {
239 * title: String!
240 * tagline: String @shout
241 * date: Date @dateformat
242 * image: File @fileByRelativePath
243 * }
244 * `
245 * createTypes(typeDefs)
246 * }
247 */
248
249exports.createSchemaCustomization = true;
250/**
251 * Add custom field resolvers to the GraphQL schema.
252 *
253 * Allows adding new fields to types by providing field configs, or adding resolver
254 * functions to existing fields.
255 *
256 * Things to note:
257 * * Overriding field types is disallowed, instead use the `createTypes`
258 * action. In case of types added from third-party schemas, where this is not
259 * possible, overriding field types is allowed.
260 * * New fields will not be available on `filter` and `sort` input types. Extend
261 * types defined with `createTypes` if you need this.
262 * * In field configs, types can be referenced as strings.
263 * * When extending a field with an existing field resolver, the original
264 * resolver function is available from `info.originalResolver`.
265 * * The `createResolvers` API is called as the last step in schema generation.
266 * Thus, an intermediate schema is made available on the `intermediateSchema` property.
267 * In resolver functions themselves, it is recommended to access the final
268 * built schema from `info.schema`.
269 * * Gatsby's data layer, including all internal query capabilities, is
270 * exposed on [`context.nodeModel`](/docs/node-model/). The node store can be
271 * queried directly with `getAllNodes`, `getNodeById` and `getNodesByIds`,
272 * while more advanced queries can be composed with `runQuery`. Note that
273 * `runQuery` will call field resolvers before querying, so e.g. foreign-key
274 * fields will be expanded to full nodes. The other methods on `nodeModel`
275 * don't do this.
276 * * It is possible to add fields to the root `Query` type.
277 * * When using the first resolver argument (`source` in the example below,
278 * often also called `parent` or `root`), take care of the fact that field
279 * resolvers can be called more than once in a query, e.g. when the field is
280 * present both in the input filter and in the selection set. This means that
281 * foreign-key fields on `source` can be either resolved or not-resolved.
282 *
283 * For fuller examples, see [`using-type-definitions`](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-type-definitions).
284 *
285 * @gatsbyVersion 2.2.0
286 * @param {object} $0
287 * @param {GraphQLSchema} $0.intermediateSchema Current GraphQL schema
288 * @param {function} $0.createResolvers Add custom resolvers to GraphQL field configs
289 * @param {object} $1
290 * @param {object} $1.resolvers Resolvers from plugin options in `gatsby-config.js`.
291 * @example
292 * exports.createResolvers = ({ createResolvers }) => {
293 * const resolvers = {
294 * Author: {
295 * fullName: {
296 * resolve: (source, args, context, info) => {
297 * return source.firstName + source.lastName
298 * }
299 * },
300 * },
301 * Query: {
302 * allRecentPosts: {
303 * type: [`BlogPost`],
304 * resolve: (source, args, context, info) => {
305 * const posts = context.nodeModel.getAllNodes({ type: `BlogPost` })
306 * const recentPosts = posts.filter(
307 * post => post.publishedAt > Date.UTC(2018, 0, 1)
308 * )
309 * return recentPosts
310 * }
311 * }
312 * }
313 * }
314 * createResolvers(resolvers)
315 * }
316 */
317
318exports.createResolvers = true;
319/**
320 * Ask compile-to-js plugins to process source to JavaScript so the query
321 * runner can extract out GraphQL queries for running.
322 */
323
324exports.preprocessSource = true;
325/**
326 * Tell plugins with expensive "side effects" from queries to start running
327 * those now. This is a soon-to-be-replaced API only currently in use by
328 * `gatsby-plugin-sharp`.
329 */
330
331exports.generateSideEffects = true;
332/**
333 * Let plugins extend/mutate the site's Babel configuration.
334 * This API will change before 2.0 as it needs still to be converted to use
335 * Redux actions.
336 */
337
338exports.onCreateBabelConfig = true;
339/**
340 * Let plugins extend/mutate the site's webpack configuration.
341 *
342 * See also the documentation for [`setWebpackConfig`](/docs/actions/#setWebpackConfig).
343 *
344 * @param {object} $0
345 * @param {string} $0.stage The current build stage. One of 'develop', 'develop-html',
346 * 'build-javascript', or 'build-html'
347 * @param {function} $0.getConfig Returns the current webpack config
348 * @param {object} $0.rules A set of preconfigured webpack config rules
349 * @param {object} $0.loaders A set of preconfigured webpack config loaders
350 * @param {object} $0.plugins A set of preconfigured webpack config plugins
351 * @param {object} $0.actions
352 * @example
353 * exports.onCreateWebpackConfig = ({
354 * stage, getConfig, rules, loaders, actions
355 * }) => {
356 * actions.setWebpackConfig({
357 * module: {
358 * rules: [
359 * {
360 * test: 'my-css',
361 * use: [loaders.style(), loaders.css()]
362 * },
363 * ],
364 * },
365 * });
366 * }
367 */
368
369exports.onCreateWebpackConfig = true;
370/**
371 * The first API called during Gatsby execution, runs as soon as plugins are loaded, before cache initialization and bootstrap preparation.
372 */
373
374exports.onPreInit = true;
375/**
376 * Called once Gatsby has initialized itself and is ready to bootstrap your site.
377 */
378
379exports.onPreBootstrap = true;
380/**
381 * Called at the end of the bootstrap process after all other extension APIs have been called.
382 */
383
384exports.onPostBootstrap = true;
385/**
386 * The first extension point called during the build process. Called after the bootstrap has completed but before the build steps start.
387 */
388
389exports.onPreBuild = true;
390/**
391 * The last extension point called after all other parts of the build process
392 * are complete.
393 */
394
395exports.onPostBuild = true;
396/**
397 * Run before GraphQL queries/fragments are extracted from JavaScript files. Useful for plugins
398 * to add more JavaScript files with queries/fragments e.g. from node_modules.
399 *
400 * See gatsby-transformer-sharp and gatsby-source-contentful for examples.
401 */
402
403exports.onPreExtractQueries = true;
404/**
405 * Run when gatsby develop server is started, its useful to add proxy and middleware
406 * to the dev server app
407 * @param {object} $0
408 * @param {Express} $0.app The [Express app](https://expressjs.com/en/4x/api.html#app) used to run the dev server
409 * @example
410 * exports.onCreateDevServer = ({ app }) => {
411 * app.get('/hello', function (req, res) {
412 * res.send('hello world')
413 * })
414 * }
415 */
416
417exports.onCreateDevServer = true;
418//# sourceMappingURL=api-node-docs.js.map
\No newline at end of file