9.16.2 • Published 8 months ago

@directus/gatsby-source-directus v9.16.2

Weekly downloads
1,215
License
MIT
Repository
github
Last release
8 months ago

gatsby-source-directus

Source plugin for pulling data into the Gatsby GraphQL Data Layer from a Directus API.

5️⃣ Installation for gatsby 4 and 5

Depending on the gatsby version you are using you will need to include the following dependencies to your project on these respective versions: @4if you are using gatsby@4 and @5 if you are using gatsby@5.

gatsby@4 dependencies

npm install --save gatsby-source-graphql@4 gatsby-source-filesystem@4

gatsby@5 dependencies

npm install --save gatsby-source-graphql@5 gatsby-source-filesystem@5

Install the package

npm install --save @directus/gatsby-source-directus

Usage

  1. Go to gatsby-config.js on your Gatsby project
  2. Add new entry to plugins properly configured with your settings
module.exports = {
	// ... some gatsby configuration
	plugins: [
		// ... some gatsby plugins

		// You can take advantage of the following plugins with gatsby-source-directus

		// `gatsby-plugin-image`,
		// `gatsby-transformer-sharp`,
		// `gatsby-plugin-sharp`,

		// Finally our plugin
		{
			resolve: '@directus/gatsby-source-directus',
			options: {
				url: `https://myproject.directus.cloud`, // Fill with your Directus instance address
				auth: {
					token: 'my_secret_token', // You can use a static token from an user

					// Or you can use the credentials of an user
					// email: "johndoe@directus.cloud",
					// password: "mysecretpassword",
				},
			},
		},
	],
};
  1. Request your data
query {
	# if you change `type.name`, remember to also rename following field
	directus {
		# the collection you want to query
		articles {
			# the fields you want to query from above collection
			title
			files {
				# since this is a M2M relationship, we need to reference the junction field
				directus_files_id {
					# `id` is required to be fetched in order to be used with `gatsby-transformer-sharp`
					id
					imageFile {
						# when using the plugin 'gatsby-transformer-sharp', you can query images with transformations
						childImageSharp {
							gatsbyImageData(width: 200)
						}
					}
				}
			}
		}
	}

	# it's also possible to query system collections
	directus_system {
		users {
			email
		}
		files {
			id
			imageFile {
				childImageSharp {
					gatsbyImageData(width: 200)
				}
			}
		}
	}
}

Note: When using with gatsby-transformer-sharp you will need to query id of the asset (specified on DirectusData_directus_files type).

Options

How to query

The default way to query data is to fetch items from directus field.

query {
	directus {
		items {
			my_collection {
				some_field
				other_field
			}
		}
	}
}

If you specify the type.field, you must query from that field instead.

query {
	# In this case `type.field` is "blog"
	blog {
		items {
			posts {
				id
				title
				slug
				status
			}
		}
	}
	# While in this case `type.field` is "portal"
	portal {
		items {
			pages {
				id
				title
				slug
				status
			}
		}
	}
}

Docs

View more about Directus

9.16.0

10 months ago

9.16.1

10 months ago

9.16.2

8 months ago

9.15.1

1 year ago

9.15.0

1 year ago

9.14.6

1 year ago

9.14.7

1 year ago

9.14.8

1 year ago

9.14.2

1 year ago

9.14.3

1 year ago

9.14.4

1 year ago

9.12.2

2 years ago

9.14.0

2 years ago

9.14.1

2 years ago

9.13.0

2 years ago

9.12.0

2 years ago

9.12.1

2 years ago

9.11.1

2 years ago

9.11.0

2 years ago

9.10.0

2 years ago

9.9.0

2 years ago

9.9.1

2 years ago

9.8.0

2 years ago

9.7.1

2 years ago

9.7.0

2 years ago

9.6.0

2 years ago

9.4.3

2 years ago

9.4.2

2 years ago

9.4.1

2 years ago

9.4.0

2 years ago

9.5.2

2 years ago

9.5.1

2 years ago

9.5.0

2 years ago

9.3.0

2 years ago

9.2.2

2 years ago

9.2.1

2 years ago

9.1.1

2 years ago

9.1.0

2 years ago

9.1.2

2 years ago

9.2.0

2 years ago

9.0.0-rc.100

3 years ago

9.0.0-rc.101

2 years ago

9.0.1

2 years ago

9.0.0

2 years ago

9.0.0-rc.99

3 years ago

9.0.0-rc.98

3 years ago

9.0.0-rc.97

3 years ago

9.0.0-rc.96

3 years ago

9.0.0-rc.95

3 years ago

9.0.0-rc.94

3 years ago

9.0.0-rc.93

3 years ago

9.0.0-rc.92

3 years ago

9.0.0-rc.91

3 years ago

9.0.0-rc.90

3 years ago

9.0.0-rc.89

3 years ago

9.0.0-rc.88

3 years ago

9.0.0-rc.87

3 years ago

9.0.0-rc.86

3 years ago

9.0.0-rc.84

3 years ago

9.0.0-rc.85

3 years ago

9.0.0-rc.83

3 years ago

9.0.0-rc.82

3 years ago

9.0.0-rc.81

3 years ago

9.0.0-rc.79

3 years ago

9.0.0-rc.78

3 years ago

9.0.0-rc.80

3 years ago

9.0.0-rc.77

3 years ago

9.0.0-rc.76

3 years ago

9.0.0-rc.73

3 years ago

9.0.0-rc.72

3 years ago

9.0.0-rc.75

3 years ago

9.0.0-rc.74

3 years ago

9.0.0-rc.71

3 years ago

9.0.0-rc.70

3 years ago

9.0.0-rc.66

3 years ago

9.0.0-rc.65

3 years ago

9.0.0-rc.68

3 years ago

9.0.0-rc.67

3 years ago

9.0.0-rc.62

3 years ago

9.0.0-rc.61

3 years ago

9.0.0-rc.64

3 years ago

9.0.0-rc.63

3 years ago

9.0.0-rc.60

3 years ago

9.0.0-rc.69

3 years ago

9.0.0-rc.59

3 years ago

9.0.0-rc.58

3 years ago

9.0.0-rc.57

3 years ago

9.0.0-rc.56

3 years ago

9.0.0-rc.55

3 years ago

9.0.0-rc.54

3 years ago

9.0.0-rc.53

3 years ago

9.0.0-rc.52

3 years ago

9.0.0-rc.51

3 years ago

9.0.0-rc.50

3 years ago

9.0.0-rc.46

3 years ago

9.0.0-rc.48

3 years ago

9.0.0-rc.49

3 years ago

9.0.0-rc.45

3 years ago

9.0.0-rc.44

3 years ago

9.0.0-rc.43

3 years ago

9.0.0-rc.42

3 years ago

9.0.0-rc.41

3 years ago

9.0.0-rc.40

3 years ago

9.0.0-rc.39

3 years ago

9.0.0-rc.38

3 years ago

9.0.0-rc.37

3 years ago

9.0.0-rc.36

3 years ago

9.0.0-rc.35

3 years ago

0.2.9

4 years ago

0.3.0

4 years ago

0.2.7

4 years ago

0.2.8

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

2.3.0

4 years ago

0.2.1

4 years ago

0.2.1-0

4 years ago

0.2.0-0

4 years ago

0.1.2-0

4 years ago

0.1.1-0

4 years ago

0.1.0

4 years ago