Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New translation: gatsby-lifecycle-apis.md #219

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 43 additions & 42 deletions docs/docs/gatsby-lifecycle-apis.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,68 @@
---
title: Gatsby Lifecycle APIs
title: APIs de ciclo de vida do Gatsby
---

import LayerModel from "../../www/src/components/layer-model"
lucas-araujo-dev marked this conversation as resolved.
Show resolved Hide resolved

Gatsby provides a rich set of lifecycle APIs to hook into its bootstrap,
build, and client runtime operations.
Gatsby fornece um conjunto rico de APIs de ciclo de vida para se conectar ao bootstrap
e operações de compilação e tempo de execução.

Gatsby's design principles include:
Os princípios de design do Gatsby incluem:

- Conventions > code, but use low-level primitives to build conventions with
code.
- Extracting logic and configuration into [plugins](/docs/plugins/) should be
trivial and encouraged.
- Plugins are easy to open source and reuse. They're just NPM packages.
- Convenções > escreva códigos, mas use primitivas de baixo nível para criar
lucas-araujo-dev marked this conversation as resolved.
Show resolved Hide resolved
convenções com código.
- A extração da lógica e da configuração em [plugins](/docs/plugins/) deve ser
trivial e encorajado.
- Os plugins são facéis de abrir e reutilizar. Eles são apenas pacotes do NPM.
lucas-araujo-dev marked this conversation as resolved.
Show resolved Hide resolved

# High level Overview
# Visão geral de alto nível

The following model gives a conceptual overview of how data is sourced and transformed in the process of building a Gatsby site:
O modelo a seguir fornece uma visão geral conceitual de como os dados são originados e transformados no processo de construção de um site de Gatsby:
lucas-araujo-dev marked this conversation as resolved.
Show resolved Hide resolved

<LayerModel />

## Bootstrap sequence
## Sequência do Bootstrap

During "bootstrap" Gatsby:
Durante o "bootstrap" o Gatsby:

- reads `gatsby-config.js` to load in your list of plugins
- initializes its cache (stored in `/.cache`)
- pulls in and preprocesses data ("source and transform nodes") into a GraphQL schema
- creates pages in memory
- from your `/pages` folder
- from your `gatsby-node.js` if you implement `createPages`/`createPagesStatefully` (e.g. templates)
- from any plugins that implement `createPages`/`createPagesStatefully`
- extracts, runs, and replaces graphql queries for pages and `StaticQuery`s
- writes out the pages to cache
- lê o `gatsby-config.js` para carregar a sua lista de plugins
- inicializa seu cache(armazenado em `/.cache`)
lucas-araujo-dev marked this conversation as resolved.
Show resolved Hide resolved
- extrai e pré-processa os dados (origina e transforma os nós) em um esquema GraphQL
- cria páginas na memória
- da sua pasta `/pages`
- do seu `gatsby-config.js` se você implementar `createPages`/`createPagesStatefully` por exemplo.
- de qualquer plugin que implemente `createPages`/`createPagesStatefully`
- extrai, executa e substitui consultas graphql para páginas e `StaticQuery`s
- grava as páginas para armazenar em cache
lucas-araujo-dev marked this conversation as resolved.
Show resolved Hide resolved

In development this is a running process powered by [Webpack](https://github.com/gatsbyjs/gatsby/blob/dd91b8dceb3b8a20820b15acae36529799217ae4/packages/gatsby/package.json#L128) and [`react-hot-loader`](https://github.com/gatsbyjs/gatsby/blob/dd91b8dceb3b8a20820b15acae36529799217ae4/packages/gatsby/package.json#L104), so changes to any files get re-run through the sequence again, with [smart cache invalidation](https://github.com/gatsbyjs/gatsby/blob/ffd8b2d691c995c760fe380769852bcdb26a2278/packages/gatsby/src/bootstrap/index.js#L141). For example, `gatsby-source-filesystem` watches files for changes, and each change triggers re-running queries. Other plugins may also perform this service. Queries are also watched, so if you modify a query, your development app is hot reloaded.
No desenvolvimento, esse é um processo de execução desenvolvido com o [Webpack](https://github.com/gatsbyjs/gatsby/blob/dd91b8dceb3b8a20820b15acae36529799217ae4/packages/gatsby/package.json#L128) e [`react-hot-loader`](https://github.com/gatsbyjs/gatsby/blob/dd91b8dceb3b8a20820b15acae36529799217ae4/packages/gatsby/package.json#L104), para que as alterações em qualquer arquivo sejam reexecutadas pela sequência novamente, com [smart cache invalidation](https://github.com/gatsbyjs/gatsby/blob/ffd8b2d691c995c760fe380769852bcdb26a2278/packages/gatsby/src/bootstrap/index.js#L141). Por exemplo, `gatsby-source-filesystem` observa os arquivos quanto a alterações, e cada alteração aciona consultas reexecutadas. Outros plugins também podem executar esse serviço.
Isso também vale para as consultas, portanto se você modificar uma consulta, seu aplicativo de desenvolvimento é recarregado.

The core of the bootstrap process is the "api-runner", which helps to execute APIs in sequence, with state managed in Redux. Gatsby exposes a number of lifecycle APIs which can either be implemented by you (or any of your configured plugins) in `gatsby-node.js`, `gatsby-browser.js` or `gatsby-ssr.js`.
O núcleo do processo de bootstrap é o "api-runner", que ajuda a executar APIs em sequência, com o estado gerenciado no Redux. O Gatsby expõe várias APIs do ciclo de vida que podem ser implementadas por você (ou por qualquer um de seus plugins configurados) em `gatsby-node.js`,` gatsby-browser.js` ou `gatsby-ssr.js`.

The sequence of the **main** bootstrap Node API lifecycles are:
A sequência dos ciclos de vida da API do nó bootstrap **main** é:

- [onPreBootstrap](/docs/node-apis/#onPreBootstrap) e.g. implemented by [`gatsby-plugin-typography`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-typography/src/gatsby-node.js)
- [sourceNodes](/docs/node-apis/#sourceNodes) e.g. implemented by [`gatsby-source-wikipedia`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wikipedia/src/gatsby-node.js)
- within this `createNode` can be called multiple times, which then triggers [onCreateNode](/docs/node-apis/#onCreateNode).
- (the first schema build happens here)
- [resolvableExtensions](/docs/node-apis/#resolvableExtensions) for filetype/language extensions e.g. [`gatsby-plugin-typescript`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-typescript/src/gatsby-node.js)
- [createPages](/docs/node-apis/#createPages) e.g. implemented by [`page-hot-reloader`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/bootstrap/page-hot-reloader.js)
- within this `createPage` can be called any number of times, which then triggers [onCreatePage](/docs/node-apis/#onCreatePage)
- [onPreExtractQueries](/docs/node-apis/#onPreExtractQueries) e.g. implemented by [`gatsby-transformer-sharp`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-transformer-sharp/src/gatsby-node.js) and [`gatsby-source-contentful`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-contentful/src/gatsby-node.js)
- (schema update happens here)
- **extract queries from components** where the [queryCompiler](https://github.com/gatsbyjs/gatsby/blob/6de0e4408e14e599d4ec73948eb4153dc3cde849/packages/gatsby/src/internal-plugins/query-runner/query-compiler.js#L189) replaces page GraphQL queries and `StaticQueries`
- The [queries are run](https://github.com/gatsbyjs/gatsby/blob/6de0e4408e14e599d4ec73948eb4153dc3cde849/packages/gatsby/src/internal-plugins/query-runner/page-query-runner.js#L120), and [the pages are written out](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/query/redirects-writer.js)
- [onPostBootstrap](/docs/node-apis/#onPostBootstrap) is called (but it is not often used)
- [na pré-inicialização](/docs/node-apis/#onPreBootstrap) Ex.: implementado por [`gatsby-plugin-typography`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-typography/src/gatsby-node.js)
- [Nós de origem](/docs/node-apis/#sourceNodes) Ex.: implementado por [`gatsby-source-wikipedia`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wikipedia/src/gatsby-node.js)
- Dentro deste pode ser chamado várias vezes, o que aciona o `createNode` [onCreateNode](/docs/node-apis/#onCreateNode).
- (A primeira compilação de esquema acontece aqui)
- [Extensões resolvíveis](/docs/node-apis/#resolvableExtensions) para extensões de tipo de arquivo / idioma, Ex.: [`gatsby-plugin-typescript`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-typescript/src/gatsby-node.js)
- [criar páginas](/docs/node-apis/#createPages) Ex.: implementado por [`page-hot-reloader`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/bootstrap/page-hot-reloader.js)
- dentro deste `createPage` pode ser chamado várias vezes, o que aciona [onCreatePage](/docs/node-apis/#onCreatePage)
- [na pré-extração de consultas](/docs/node-apis/#onPreExtractQueries) Ex.: implementado por [`gatsby-transformer-sharp`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-transformer-sharp/src/gatsby-node.js) e [`gatsby-source-contentful`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-contentful/src/gatsby-node.js)
- (atualização de esquema acontece aqui)
- **extrair consultas de componentes** onde o [compilador de consultas](https://github.com/gatsbyjs/gatsby/blob/6de0e4408e14e599d4ec73948eb4153dc3cde849/packages/gatsby/src/internal-plugins/query-runner/query-compiler.js#L189) substitui as consultas da página GraphQL e o `StaticQueries`
- As [consultas são executadas](https://github.com/gatsbyjs/gatsby/blob/6de0e4408e14e599d4ec73948eb4153dc3cde849/packages/gatsby/src/internal-plugins/query-runner/page-query-runner.js#L120), e [as páginas são gravadas](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/query/redirects-writer.js)
- [no Post Bootstrap](/docs/node-apis/#onPostBootstrap) is called (mas não é frequentemente usado)
lucas-araujo-dev marked this conversation as resolved.
Show resolved Hide resolved

## Build sequence
## Sequência de compilação

(to be written)
(para ser escrito)

## Client sequence
## Sequência de cliente

(to be written)
(para ser escrito)

---

Please see the links along the left under "REFERENCE" for the full API documentation.
Consulte os links à esquerda em "REFERENCE" para obter a documentação completa da API.