gatsby-source-strapi icon indicating copy to clipboard operation
gatsby-source-strapi copied to clipboard

Possible fallback for when targeted Strapi host is down

Open elussich opened this issue 5 years ago • 4 comments

Hello! First of all, thanks for this awesome plugin.

While developing my Gatsby application with this plugin enabled, I ran through the case when the Strapi host was not running yet (in my case, dockerized on my machine) and at the time of doing gatsby develop I (obviously) got an error with the following message:

error Plugin gatsby-source-strapi returned an error
Error: connect ECONNREFUSED 127.0.0.1:1337

I was wondering if there's a chance to skip plugin's initialization when the Strapi host is not found, and continue with the rest of Gatsby steps to effectively build the app; of course, it's up to the developer to handle all specific flows when consuming Strapi API (via GraphQL and Gatsby custom interfaces).

This way, we are not only blocking the developer from keep on working on the app if Strapi is unavailable, but also providing a way to test and handle connectivity issues between Gatsby and Strapi, altogether.

Let me know your thoughts on this. Thanks again!

elussich avatar Sep 19 '18 20:09 elussich

I am having this issues as well while following the tutorial: https://blog.strapi.io/building-a-static-website-using-gatsby-and-strapi/

I am also having error GraphQL Error Unknown field `allStrapiArticle` on type `Query` 38:5 error Cannot query field "allStrapiArticle" on type "Query" graphql/template-strings

success open and validate gatsby-configs — 0.006 s
success load plugins — 0.265 s
success onPreInit — 0.391 s
success delete html and css files from previous builds — 0.019 s
success initialize cache — 0.005 s
success copy gatsby files — 0.018 s
success onPreBootstrap — 0.005 s
⠁ Starting to fetch data from Strapi (articles)
Starting to fetch data from Strapi (users)
error Plugin gatsby-source-strapi returned an error


  Error: connect ECONNREFUSED 127.0.0.1:1337

warning The gatsby-source-strapi plugin has generated no Gatsby nodes. Do you need it?
success source and transform nodes — 0.081 s
success building schema — 0.242 s
success createPages — 0.001 s
success createPagesStatefully — 0.038 s
success onPreExtractQueries — 0.003 s
success update schema — 0.108 s
error GraphQL Error Unknown field `allStrapiArticle` on type `Query`

  file: /root/gatsby-strapi-tutorial/blog/src/pages/index.js

   1 |
   2 |   query IndexQuery {
>  3 |     allStrapiArticle {
     |     ^
   4 |       edges {
   5 |         node {
   6 |           id
   7 |           title
   8 |           content
   9 |         }
  10 |       }
  11 |     }
  12 |   }
  13 |

success extract queries from components — 0.127 s
⠁ (node:11534) DeprecationWarning: Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.
success run graphql queries — 0.012 s — 5/5 440.27 queries/second
success write out page data — 0.004 s
success write out redirect data — 0.001 s
⡀ onPostBootstrapdone generating icons for manifest
success onPostBootstrap — 0.220 s

info bootstrap finished - 3.578 s

 ERROR  Failed to compile with 1 errors                                                                                                                                                        10:01:12 PM

 error  in ./src/pages/index.js

Module Error (from ./node_modules/eslint-loader/index.js):

/root/gatsby-strapi-tutorial/blog/src/pages/index.js
  38:5  error  Cannot query field "allStrapiArticle" on type "Query"  graphql/template-strings

✖ 1 problem (1 error, 0 warnings)


 @ ./.cache/sync-requires.js 15:50-113
 @ ./.cache/app.js
 @ multi (webpack)-hot-middleware/client.js?path=/__webpack_hmr&reload=true&overlay=false ./.cache/app

✖ 「wdm」:
ERROR in ./src/pages/index.js
Module Error (from ./node_modules/eslint-loader/index.js):

/root/gatsby-strapi-tutorial/blog/src/pages/index.js
  38:5  error  Cannot query field "allStrapiArticle" on type "Query"  graphql/template-strings

✖ 1 problem (1 error, 0 warnings)

 @ ./.cache/sync-requires.js 15:50-113
 @ ./.cache/app.js
 @ multi (webpack)-hot-middleware/client.js?path=/__webpack_hmr&reload=true&overlay=false ./.cache/app
ℹ 「wdm」: Failed to compile.
 WAIT  Compiling...                                                                                                                                                                            10:01:12 PM

ℹ 「wdm」: Compiling...
 ERROR  Failed to compile with 1 errors                                                                                                                                                        10:01:12 PM

 error  in ./src/pages/index.js

Module Error (from ./node_modules/eslint-loader/index.js):

/root/gatsby-strapi-tutorial/blog/src/pages/index.js
  38:5  error  Cannot query field "allStrapiArticle" on type "Query"  graphql/template-strings

✖ 1 problem (1 error, 0 warnings)


 @ ./.cache/sync-requires.js 15:50-113
 @ ./.cache/app.js
 @ multi (webpack)-hot-middleware/client.js?path=/__webpack_hmr&reload=true&overlay=false ./.cache/app

✖ 「wdm」:
ERROR in ./src/pages/index.js
Module Error (from ./node_modules/eslint-loader/index.js):

/root/gatsby-strapi-tutorial/blog/src/pages/index.js
  38:5  error  Cannot query field "allStrapiArticle" on type "Query"  graphql/template-strings

✖ 1 problem (1 error, 0 warnings)

 @ ./.cache/sync-requires.js 15:50-113
 @ ./.cache/app.js
 @ multi (webpack)-hot-middleware/client.js?path=/__webpack_hmr&reload=true&overlay=false ./.cache/app
ℹ 「wdm」: Failed to compile.

clabmb avatar Dec 10 '18 22:12 clabmb

Hi @clabmb, the GraphQL error you are getting is most likely due to the initial error that we were mentioning initially, about the Strapi host not being found. Make sure you have a Strapi instance effectively running on 127.0.0.1:1337 and see if the errors persist.

elussich avatar Dec 11 '18 16:12 elussich

Hi @elussich, thanks.... I just fix the problem... I was so stupid that i forgot to start the strapi service....

clabmb avatar Dec 11 '18 16:12 clabmb

Hello @elussich I suggest you to submit a PR if you want this feature. We don't have time dedicated to work on your point.

lauriejim avatar Dec 27 '18 14:12 lauriejim

Thanks for your interest in this project. This plugin is moving into the Gatsby User Collective and this repo will be archived. Please open an issue in that repository, submit a PR if you'd like to see this implemented, or join us on Discord if you have questions!

moonmeister avatar Dec 27 '22 18:12 moonmeister