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

Handle empty bucket

Open patspam opened this issue 4 years ago • 3 comments

Great plugin, thanks for creating it!

Sometimes I don't want to process any images - for example in my CI pipeline. An easy way to accomplish that is to do something like in gatsby-config.js:

{
buckets: process.env.GATSBY_SKIP_IMAGE_PROCESSING
          ? []
          : ["my-s3-bucket"],
...
}

and then do GATSBY_SKIP_IMAGE_PROCESSING=1 gatsby build to pretend there are no images.

This is much easier than trying to make your GraphQL queries adapt to the environment variable, because Gatsby graphQL queries are pretty static.

However, when I do that, I get a Gatsby error:

 ERROR #85923  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "allS3Object" on type "Query".

If you don't expect "allS3Object" to exist on the type "Query" it is most likely a typo.
However, if you expect "allS3Object" to exist there are a couple of solutions to common problems:

- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "allS3Object" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field (
"dummy content")

It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "Query":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions

This makes sense, but it would be nice if it Just Worked, or alternatively, if there was documentation in this plugin's README explaining how to add the missing type information.

patspam avatar Jun 17 '20 00:06 patspam