You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updated readme to address #47 and also taking a stab at updating #40. (#49)
* Updated readme to address #47 and also taking a stab at updating #40.
* Updating testing configs to get Travis build passing
* PR feedback - non-breaking changes for GATSBY_AIRTABLE_API_KEY, updated Readme, and reverted test changes
* Applying Readme suggestions from code review. Will update examples once more to "right" way in next commit.
* Re-updating tests to reflect the 'right' way to reference .env values
* Updating .env values!
* Updating to reflect best practice with environment variable naming
Copy file name to clipboardExpand all lines: README.md
+49-2Lines changed: 49 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,8 +126,55 @@ Within graphql (the language you query information from and that this plugin put
126
126
127
127
Keys can be found in Airtable by clicking `Help > API Documentation`.
128
128
129
-
The API key can be specified in `gatsby-config.js` as noted in the previous section-- **this exposes your key to anyone viewing your repository and is not recommended**.
129
+
The API key can be hard coded directly in `gatsby-config.js` as noted in the previous section-- **this exposes your key to anyone viewing your repository and is not recommended. You should inject your API key as recommended below to prevent it from being committed to source control**.
130
130
131
-
Alternatively, you may specify your API key using an [Environment Variable](https://www.gatsbyjs.org/docs/environment-variables/). This plugin looks for an environment variable called `GATSBY_AIRTABLE_API_KEY` and will use it prior to resorting to the `apiKey` defined in `gatsby-config.js`. You may also specify it in your command line such as `GATSBY_AIRTABLE_API_KEY=XXXXXX gatsby develop`.
131
+
We recommended specifying your API key using an [Environment Variable](https://www.gatsbyjs.org/docs/environment-variables/). You may also specify it in your command line such as `AIRTABLE_API_KEY=XXXXXX gatsby develop`. Note: If you use an environment variable prepended with `GATSBY_`, it takes advantage of some syntactic sugar courtesy of Gatsby, which automatically makes it available - but any references to environment variables like this that are rendered client-side will **automatically** expose your API key within the browser. To avoid accidentally exposing it, we recommend *not* prepending it with `GATSBY_`.
132
+
133
+
To be safe, you can also setup your API key via a config variable, `apiKey` defined in `gatsby-config.js`. This is the recommended way to inject your API key.
134
+
135
+
```javascript
136
+
// In gatsby-config.js
137
+
plugins: [
138
+
{
139
+
resolve:`gatsby-source-airtable`,
140
+
options: {
141
+
//not prefaced with "GATSBY_", will not automatically be included client-side unless you explicitly expose it
142
+
apiKey:process.env.AIRTABLE_API_KEY
143
+
//...etc
144
+
}
145
+
}
146
+
]
147
+
```
148
+
149
+
You can either use a node tool like "dotenv" to load secrets like your Airtable API key from a .env file, or you can specify it in your command line such as `AIRTABLE_API_KEY=XXXXXX gatsby develop`.
132
150
133
151
If you add or change your API key in an environment variable at the system level, you may need to reload your code editor / IDE for that variable to reload.
152
+
153
+
### Columns without any values (yet)
154
+
155
+
If you want to perform conditional logic based on data that may or may not be present in Airtable, but you do not yet have tabular data for the "may" case, you can update the gatsby-source-airtable section of `gatsby-config.js` to include sensible defaults for those fields
156
+
so that they will be returned via your graphql calls:
157
+
158
+
```javascript
159
+
// In gatsby-config.js
160
+
plugins: [
161
+
{
162
+
resolve:`gatsby-source-airtable`,
163
+
options: {
164
+
apiKey:process.env.AIRTABLE_API_KEY,
165
+
tables: [
166
+
{
167
+
baseId:process.env.AIRTABLE_BASE,
168
+
tableName:process.env.AIRTABLE_TABLE_NAME,
169
+
defaultValues: {
170
+
//currently does not accept null / undefined. use empty string instead
171
+
//and perform your conditional logic on name_of_field.length > 0 ? condition_1 : condition_2
console.warn("\nImplicit setting of GATSBY_AIRTABLE_API_KEY as apiKey will be deprecated in future release, apiKey should be set in gatsby-config.js, please see Readme!")
0 commit comments