Según los documentos oficiales de GraphQL, intenté hacer una consulta con gatsby-transformer-yaml
https://www.graph.cool/docs/reference/graphql-api/query-api-nia9nushae#traversing -a-single-node
query {
projectsYaml(title: "project1"){
description
keywords
published
}
}
esto no funciona, el error es "Argument \"title\" has invalid value \"project1\".\nExpected \"projectsYamlTitleQueryString_2\", found not an object."
también probé este https://www.graph.cool/docs/reference/graphql-api/query-api-nia9nushae#filtering -by-field
query {
allProjectsYaml(filter: {
title: "project1"
}){
edges{
node{
description
keywords
date
}
}
}
}
error: Argument \"filter\" has invalid value {title: \"project1\"}.\nIn field \"title\": Expected \"projectsYamlConnectionTitleQueryString_2\", found not an object.",
src /
datos/
proyectos /
-proyecto1.yml
-proyecto2.yml
y así.
Si esto no puede funcionar, ¿quizás pueda sugerir otra solución para obtener datos de un archivo en particular?
porque si hago solo projectsYaml
solo obtengo el primero, usar allProjectsYaml
me dejaría filtrando la lista en JS ...
gatsby info - portapapeles
Sistema:
SO: Windows 10
CPU: CPU x64 Intel (R) Core (TM) i5-6300HQ a 2,30 GHz
Binarios:
Nodo: 10.8.0 - D: NodeJSnode.EXE
npm: 6.2.0 - D: NodeJSnpm.CMD
Navegadores:
Borde: 42.17134.1.0
npm Paquetes:
gatsby: ^ 1.9.277 => 1.9.277
imagen-de-gatsby: ^ 1.0.55 => 1.0.55
gatsby-link: ^ 1.6.46 => 1.6.46
gatsby-plugin-react-casco: ^ 2.0.11 => 2.0.11
gatsby-plugin-sharp: ^ 1.6.48 => 1.6.48
gatsby-source-filesystem: ^ 1.5.39 => 1.5.39
gatsby-transformer-json: ^ 1.0.20 => 1.0.20
gatsby-transformer-sharp: ^ 1.6.27 => 1.6.27
Gatsby-transformer-yaml: ^ 1.5.18 => 1.5.18
error El sistema no puede encontrar la ruta especificada.
Error: el sistema no puede encontrar la ruta especificada.
envinfo.js: 1 función.e.exports.sync
[npm] / [gatsby-cli] / [envinfo] /dist/envinfo.js:1:7778
envinfo.js: 1 Object.copySync
[npm] / [gatsby-cli] / [envinfo] /dist/envinfo.js:1:104976
envinfo.js: 1 Object.t.writeSync.e [como writeSync]
[npm] / [gatsby-cli] / [envinfo] /dist/envinfo.js:1:123499
envinfo.js: 1
[npm] / [gatsby-cli] / [envinfo] /dist/envinfo.js:1:124274
envinfo.js: 1 Promise.all.then.e
[npm] / [gatsby-cli] / [envinfo] /dist/envinfo.js:1:124289
util.js: 16 tryCatcher
[npm] / [gatsby-cli] / [bluebird] /js/release/util.js:16:23
Promise.js: 512 Promise._settlePromiseFromHandler
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:512:31
Promise.js: 569 Promise._settlePromise
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:569:18
Promise.js: 614 Promise._settlePromise0
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:614:10
Promise.js: 693 Promise._settlePromises
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:693:18
Promise.js: 638 Promise._fulfill
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:638:18
promise_array.js: 126 PromiseArray._resolve
[npm] / [gatsby-cli] / [bluebird] /js/release/promise_array.js:126:19
PromiseArray.js: 144 PromiseArray._promiseFuldered
[npm] / [gatsby-cli] / [bluebird] /js/release/promise_array.js:144:14
Promise.js: 574 Promise._settlePromise
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:574:26
Promise.js: 614 Promise._settlePromise0
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:614:10
Promise.js: 693 Promise._settlePromises
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:693:18
error RECHAZO NO MANEJADO
Error: el sistema no puede encontrar la ruta especificada.
envinfo.js: 1 función.e.exports.sync
[npm] / [gatsby-cli] / [envinfo] /dist/envinfo.js:1:7778
envinfo.js: 1 Object.copySync
[npm] / [gatsby-cli] / [envinfo] /dist/envinfo.js:1:104976
envinfo.js: 1 Object.t.writeSync.e [como writeSync]
[npm] / [gatsby-cli] / [envinfo] /dist/envinfo.js:1:123499
envinfo.js: 1
[npm] / [gatsby-cli] / [envinfo] /dist/envinfo.js:1:124274
envinfo.js: 1 Promise.all.then.e
[npm] / [gatsby-cli] / [envinfo] /dist/envinfo.js:1:124289
util.js: 16 tryCatcher
[npm] / [gatsby-cli] / [bluebird] /js/release/util.js:16:23
Promise.js: 512 Promise._settlePromiseFromHandler
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:512:31
Promise.js: 569 Promise._settlePromise
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:569:18
Promise.js: 614 Promise._settlePromise0
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:614:10
Promise.js: 693 Promise._settlePromises
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:693:18
Promise.js: 638 Promise._fulfill
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:638:18
promise_array.js: 126 PromiseArray._resolve
[npm] / [gatsby-cli] / [bluebird] /js/release/promise_array.js:126:19
PromiseArray.js: 144 PromiseArray._promiseFuldered
[npm] / [gatsby-cli] / [bluebird] /js/release/promise_array.js:144:14
Promise.js: 574 Promise._settlePromise
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:574:26
Promise.js: 614 Promise._settlePromise0
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:614:10
Promise.js: 693 Promise._settlePromises
[npm] / [gatsby-cli] / [bluebird] /js/release/promise.js:693:18
(Los navegadores están equivocados, tengo Opera, Chrome y Firefox, pero no creo que esto sea relevante.
gatsby-config.js
: module.exports = {
siteMetadata: {
title: 'xxx',
},
plugins: [
'gatsby-plugin-react-helmet',
'gatsby-transformer-json',
'gatsby-transformer-sharp',
'gatsby-transformer-yaml',
'gatsby-plugin-sharp',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'data',
path: './src/data',
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'projects',
path: './src/data/projects',
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'img',
path: './src/assets/images',
},
},
],
}
package.json
: N / A
gatsby-node.js
: N / A
gatsby-browser.js
: N / A
gatsby-ssr.js
: N / A
Consulte https://www.gatsbyjs.org/docs/graphql-reference/#filter ; gatsby usa operadores para filtrar, por lo que es más flexible; en su caso, probablemente desee usar:
query { projectsYaml(title: { eq: "project1"})
- eq
significa que el título es igual a "proyecto1" - otros operadores permiten la exclusión ne
, usando expresiones regulares, etc.
Comentario más útil
Consulte https://www.gatsbyjs.org/docs/graphql-reference/#filter ; gatsby usa operadores para filtrar, por lo que es más flexible; en su caso, probablemente desee usar:
query { projectsYaml(title: { eq: "project1"})
-eq
significa que el título es igual a "proyecto1" - otros operadores permiten la exclusiónne
, usando expresiones regulares, etc.