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
{{ message }}
This repository was archived by the owner on Dec 27, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+82-19Lines changed: 82 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,42 @@ Source plugin for pulling documents into Gatsby from a Strapi API.
4
4
5
5
> **WARNING**: This is the README for v1.0.0 which is in `alpha` version for now. Make sure to install it with @alpha to try it out. It's designed to be used with Gatsby v3.
6
6
7
-
## Install
7
+
## Installing the plugin
8
8
9
-
`npm install --save gatsby-source-strapi@alpha`
9
+
```sh
10
+
# Using Yarn
11
+
yarn add gatsby-source-strapi@alpha
10
12
11
-
## How to use
13
+
# Or using NPM
14
+
npm install --save gatsby-source-strapi@alpha
15
+
```
16
+
17
+
## Setting up the plugin
18
+
19
+
You can enable and configure this plugin in your `gatsby-config.js` file.
20
+
21
+
### Basic usage
22
+
23
+
```javascript
24
+
// In your gatsby-config.js
25
+
plugins: [
26
+
{
27
+
resolve:`gatsby-source-strapi`,
28
+
options: {
29
+
apiURL:`http://localhost:1337`,
30
+
queryLimit:1000, // Defaults to 100
31
+
collectionTypes: [`article`, `user`],
32
+
singleTypes: [`home-page`, `contact`],
33
+
},
34
+
},
35
+
];
36
+
```
37
+
38
+
### Advanced usage
39
+
40
+
#### Custom endpoint
41
+
42
+
By default, we use the pluralize module to deduct the endpoint that matches a collection type. You can opt out of this behavior. To do so, pass an entity definition object with your custom endpoint.
12
43
13
44
```javascript
14
45
// In your gatsby-config.js
@@ -17,30 +48,63 @@ plugins: [
17
48
resolve:`gatsby-source-strapi`,
18
49
options: {
19
50
apiURL:`http://localhost:1337`,
20
-
queryLimit:1000, // Default to 100
21
51
collectionTypes: [
22
-
`article`,
23
-
`user`,
24
-
// if you don't want to leave the definition of an api endpoint to the pluralize module
25
52
{
26
53
name:`collection-name`,
27
54
endpoint:`custom-endpoint`,
28
55
},
29
-
// if you want to use custom query strings (e.g. to fetch all locales)
30
-
// mapping of api.qs object will be used to create final query string (e.g: http://localhost:1337/collection-name?_locale=all)
56
+
]
57
+
},
58
+
},
59
+
];
60
+
```
61
+
62
+
#### Internationalization support
63
+
64
+
Strapi now supports [internationalization](https://strapi.io/documentation/developer-docs/latest/development/plugins/i18n.html#installation). But by default, this plugin will only fetch data in the default locale of your Strapi app. If your content types are available in different locales, you can also pass an entity definition object to specify the locale you want to fetch for a content type. Use the `all` value to get all available locales.
65
+
66
+
```javascript
67
+
// In your gatsby-config.js
68
+
plugins: [
69
+
{
70
+
resolve:`gatsby-source-strapi`,
71
+
options: {
72
+
apiURL:`http://localhost:1337`,
73
+
collectionTypes: [
74
+
// Fetch all locales for collection-name
31
75
{
32
76
name:`collection-name`,
33
-
api: { qs: { _locale:'all' } }
77
+
api: { qs: { _locale:`all` } }
34
78
},
35
-
//exemple fetching only english content
79
+
//Only fetch english content for other-collection-name
36
80
{
37
-
name:`collection-name`,
38
-
api: { qs: { _locale:'en' } }
81
+
name:`other-collection-name`,
82
+
api: { qs: { _locale:`en` } }
39
83
},
40
-
],
41
-
//If using single types place them in this array.
42
-
singleTypes: [`home-page`, `contact`],
43
-
// Possibility to login with a strapi user, when content types are not publically available (optional).
84
+
// Combined with a custom endpoint
85
+
{
86
+
name:`another-collection-name`,
87
+
endpoint:`custom-endpoint`,
88
+
api: { qs: { _locale:`en` } }
89
+
},
90
+
]
91
+
},
92
+
},
93
+
];
94
+
```
95
+
96
+
#### Authenticated requests
97
+
98
+
Strapi's [Roles & Permissions plugin](https://strapi.io/documentation/developer-docs/latest/development/plugins/users-permissions.html#concept) allows you to protect your API actions. If you need to access a route that is only available to a logged in user, you can provide your credentials so that this plugin can access to the protected data.
99
+
100
+
```javascript
101
+
// In your gatsby-config.js
102
+
plugins: [
103
+
{
104
+
resolve:`gatsby-source-strapi`,
105
+
options: {
106
+
apiURL:`http://localhost:1337`,
107
+
collectionTypes: [`collection-name`],
44
108
loginData: {
45
109
identifier:'',
46
110
password:'',
@@ -50,7 +114,7 @@ plugins: [
50
114
];
51
115
```
52
116
53
-
## How to query
117
+
## Querying data
54
118
55
119
You can query Document nodes created from your Strapi API like the following:
56
120
@@ -86,7 +150,6 @@ Make sure to add `api.qs._locale` to your strapi configuration in `gatsby-config
0 commit comments