jonesus / gatsby-source-directus7 Goto Github PK
View Code? Open in Web Editor NEWSource plugin for pulling data into GatsbyJS from Directus CMS (https://directus.io)
Source plugin for pulling data into GatsbyJS from Directus CMS (https://directus.io)
When creating a page using createPage
the data that is put into context is not passed through. An example of my code and error are
gatsby-node.js file
createPage({
path: `/about/${teamType.team_type_slug}`,
component: path.resolve('./src/pages/teams.tsx'),
context: {
// Used as a query argument in the component below
name: "staff",
},
});
teams.tsx file
export const pageQuery = graphql`
query($name: String!) {
teamMembers: allDirectusTeamMember(filter: { team_member_type: { team_type_name: { eq: $name } } }) {
nodes {
directusId
team_first_name
team_job_title
team_last_name
team_bio
team_photo {
data {
full_url
}
}
}
}
}
`;
Then when I build the graphql
Errors: Variable "$name" of required type "String!" was not provided.
I copied the code directly from Gatsby Page
Please let me know if there is something I am doing wrong or if I have to add something to my configs.
Everything works fine in directus but when I run gatsby develop I get this error:
`success open and validate gatsby-configs — 0.008 s
success load plugins — 0.211 s
success onPreInit — 0.007 s
success initialize cache — 0.012 s
success copy gatsby files — 0.024 s
success onPreBootstrap — 0.015 s
⠁ gatsby-source-directus info Directus Data Fetcher initializing...
gatsby-source-directus success Connected to Directus!
gatsby-source-directus success Logged in to Directus!
gatsby-source-directus info Fetching Directus file data...
⡀ source and transform nodesgatsby-source-directus success Found 14 files from Directus.
gatsby-source-directus info Downloading Directus files to Gatsby build cache...
Downloading remote files [==============================] 14/14 0.1 secs 100%
gatsby-source-directus success Downloaded all 14 files from Directus!
gatsby-source-directus info Fetching Directus Collection data...
⠐ source and transform nodesgatsby-source-directus info Fetching Directus Items data...
⠂ source and transform nodesgatsby-source-directus info Fetching Directus Relations data...
⡀ source and transform nodesgatsby-source-directus info Mapping Directus relations to Items...
gatsby-source-directus info Found One-To-Many relation: customer -> categories
error Plugin gatsby-source-directus7 returned an error
TypeError: Cannot read property 'filter' of undefined
process.js:171 mappedEntities.(anonymous function).mappedEntities.(anonymous function).map.entity
[nuvitek-website]/[gatsby-source-directus7]/process.js:171:46
Array.map
process.js:170 relations.forEach.relation
[nuvitek-website]/[gatsby-source-directus7]/process.js:170:47
Array.forEach
process.js:145 mapRelations
[nuvitek-website]/[gatsby-source-directus7]/process.js:145:13
gatsby-node.js:70 Object.exports.sourceNodes
[nuvitek-website]/[gatsby-source-directus7]/gatsby-node.js:70:60
task_queues.js:86 processTicksAndRejections
internal/process/task_queues.js:86:5
success source and transform nodes — 1.309 s
success building schema — 0.367 s
success createPages — 0.001 s
success createPagesStatefully — 0.069 s
success onPreExtractQueries — 0.000 s
success update schema — 0.054 s
success extract queries from components — 0.026 s
success run graphql queries — 0.010 s — 2/2 201.65 queries/second
success write out page data — 0.005 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.001 s
info bootstrap finished - 4.047730672 s
DONE Compiled successfully in 2083ms 5:38:53 PM
You can now view gatsby-starter-hello-world in the browser.
View GraphiQL, an in-browser IDE, to explore your site's data and schema
http://localhost:8000/___graphql
Note that the development build is not optimized.
To create a production build, use npm run build
ℹ 「wdm」:
ℹ 「wdm」: Compiled successfully.`
There are a few more one-to-many relations in my database, but only this fails, what can I do to fix this?
Hey.
Is there a way to authenticate with a static token instead of the credentials?
As it is possible in the original version by iKonrad.
Hey.
I managed to set-up translations as described in the documentation of Directus. Now I'm not able to get this translated posts (e.g. in english or german) with the plugin.
Doc part to the setup: https://docs.directus.io/guides/relationships.html#translations
Is it not possible with this plugin?
Hey.
Right now when the post is created, the URL will be /post/{id}/
. Is it somehow possible to use a slug field? I have one added as title_slug
which is a mirror of the title
field in my Post
collection.
Hey.
I have this weird issue, that after a couple of minutes and a fresh yarn start
, the plugin is returning errors. I don't know what exactly is causing the issue.
UPDATE: This issue only happens, if there is an image in the content or in the teaser field.
Plugin part from logs:
gatsby-source-directus info Directus Data Fetcher initializing...
gatsby-source-directus info targetStatus is: draft
gatsby-source-directus success Connected to Directus!
gatsby-source-directus success Logged in to Directus!
gatsby-source-directus info Fetching Directus file data...
gatsby-source-directus success Found 1 files from Directus.
gatsby-source-directus info Downloading Directus files to Gatsby build cache...
error (node:75578) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
⠀
gatsby-source-directus success Downloaded all 1 files from Directus!
gatsby-source-directus info Fetching Directus Collection data...
gatsby-source-directus info Fetching Directus Items data...
gatsby-source-directus info Status matched for posts 1. Using item
gatsby-source-directus info Fetching Directus Relations data...
gatsby-source-directus info Mapping Directus relations to Items...
gatsby-source-directus info Cleaning junction collections...
gatsby-source-directus info Mapping Directus files to Items...
gatsby-source-directus info Mapping files for posts...
error Plugin gatsby-source-directus7 returned an error
TypeError: Cannot read property 'directus' of undefined
- process.js:300
[test-gatsby]/[gatsby-source-directus7]/process.js:300:77
- Array.map
- process.js:298
[test-gatsby]/[gatsby-source-directus7]/process.js:298:67
- Array.forEach
- process.js:296 mapFilesToNodes
[test-gatsby]/[gatsby-source-directus7]/process.js:296:24
- gatsby-node.js:75 Object.exports.sourceNodes
[test-gatsby]/[gatsby-source-directus7]/gatsby-node.js:75:55
- task_queues.js:89 processTicksAndRejections
internal/process/task_queues.js:89:5
success source and transform nodes - 2.427 s
success building schema - 0.208 s
error GraphQL query returned error: TypeError: Cannot read property 'allDirectusPost' of undefined
success createPages - 0.018 s
success createPagesStatefully - 0.036 s
success onPreExtractQueries - 0.004 s
success update schema - 0.018 s
error GraphQL Error Encountered 1 error(s):
- Unknown field 'directusPost' on type 'Query'.
file: /Users/deanhidri/Fintory/test-gatsby/src/templates/post.js
Posts collection:
hi, there's way to deal with m2m? it seems that, beside the terminal that say:
GSD7: info Status matched for progetti_strumenti 1. Using item GSD7: info Status matched for progetti_strumenti 2. Using item GSD7: info Status matched for strumenti 1. Using item GSD7: info Status matched for test 1. Using item GSD7: info Fetching Directus Relations data... GSD7: success Retrieved all data from Directus! GSD7: info Directus data processing starting... GSD7: info Mapping Directus relations to Items... GSD7: info Found Many-To-Many relation: strumenti <-> Progetti
there's no way to find the relation strumenti <-> Progetti in graphql. It's just not there.
Any idea?
thanks
I was creating a schema in my Directus instance and I realized that I messed up one of the relations, so I deleted it. Due to a different bug in Directus, it was not, however, deleted from the relations table as one would expect. This created the following entries in my relations table:
+----+------------------------------+-------------------+----------------------+---------------------+-------------------+
| id | collection_many | field_many | collection_one | field_one | junction_field |
+----+------------------------------+-------------------+----------------------+---------------------+-------------------+
| 17 | blog_tags | id | blog | NULL | NULL |
| 18 | blog_post_tag_junction | blog_tags_id | blog_tags | blog | blog_id |
| 19 | blog_post_tag_junction | blog_id | blog | tags | blog_tags_id |
As you can see, #18
and #19
are part of the many-to-many relation that I created after I realized my mistake. #17
is a problematic leftover.
I was able to figure out (via some sketchy console.logs) that GSD7 sees the following relations:
[ ...
{ id: 17,
collection_many: 'blog_tags',
field_many: 'id',
collection_one: 'blog',
field_one: null,
junction_field: null },
{ id: 18,
collection_many: 'blog_post_tag_junction',
field_many: 'blog_tags_id',
collection_one: 'blog_tags',
field_one: 'blog',
junction_field: 'blog_id' },
{ id: 19,
collection_many: 'blog_post_tag_junction',
field_many: 'blog_id',
collection_one: 'blog',
field_one: 'tags',
junction_field: 'blog_tags_id' } ]
Since GSD7 "saw" #17
first, it would appear that it gave #17
control of the tags
variable in my blog
GQL query. So I was able to see blog
from tags
, but not the other way around. This is because GSD7 rightfully could not find any many-to-one relations between blog
and blog_tags
, so it returned nothing. If you examine the console output, you can see this:
GSD7: info Found Many-To-One relation: blog -> blog_tags
GSD7: warning Missing One-To-Many relation in 'blog'. The relation
GSD7: warning will be called 'blog_tags' in GraphQL as a best guess.
GSD7: warning Could not find an Many-To-One match in 'blog' for item in 'blog_tags'
GSD7: warning with id '1'. The field value will be left null.
GSD7: warning Could not find an Many-To-One match in 'blog' for item in 'blog_tags'
GSD7: warning with id '2'. The field value will be left null.
GSD7: warning Could not find an Many-To-One match in 'blog' for item in 'blog_tags'
GSD7: warning with id '3'. The field value will be left null.
GSD7: info Found Many-To-Many relation: blog_tags <-> blog
...where GSD7 cannot find the relations because the relations
table contained the invalid #17
. Deleting this from a SQL prompt solved the problem, however I believe that the error message needs to be more clear. I believe that an additional check should be added for relations with the same two sets that would end up conflicting. Something like this would do:
GSD7: warning There are multiple relations in the same direction between 'blog' and 'blog_tags"
In short, I think that this is exclusively an issue of having helpful error messages for certain edge cases, so it shouldn't be super high on anyone's priority list. I'll look into doing this and submitting a PR.
Trying to deploy my Gatsby project on Heroku but it fails. Seems like it even can't log in.
-----> Build
Running build (yarn)
yarn run v1.17.2
$ gatsby build
╔════════════════════════════════════════════════════════════════════════╗
║ ║
║ Gatsby has started collecting anonymous usage analytics ║
║ to help improve Gatsby for all users. ║
║ ║
║ If you'd like to opt-out, you can use `gatsby telemetry --disable` ║
║ To learn more, checkout https://gatsby.dev/telemetry ║
║ ║
╚════════════════════════════════════════════════════════════════════════╝
lscpu: failed to determine number of CPUs: /sys/devices/system/cpu/possible: No such file or directory
�[2K�[1A�[2K�[G⠋ open and validate gatsby-configs
�[2K�[1A�[2K�[Gsuccess open and validate gatsby-configs - 0.008 s
⠋ open and validate gatsby-configs
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ load plugins
�[2K�[1A�[2K�[Gsuccess load plugins - 0.740 s
⠋ load plugins
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ onPreInit
�[2K�[1A�[2K�[Gsuccess onPreInit - 0.008 s
⠋ onPreInit
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ delete html and css files from previous builds
�[2K�[1A�[2K�[Gsuccess delete html and css files from previous builds - 0.010 s
⠋ delete html and css files from previous builds
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ initialize cache
�[2K�[1A�[2K�[Gsuccess initialize cache - 0.010 s
⠋ initialize cache
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ copy gatsby files
�[2K�[1A�[2K�[Gsuccess copy gatsby files - 0.031 s
⠋ copy gatsby files
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ onPreBootstrap
�[2K�[1A�[2K�[Gsuccess onPreBootstrap - 0.015 s
⠋ onPreBootstrap
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ source and transform nodes
�[2K�[1A�[2K�[G⠙ source and transform nodes
�[2K�[1A�[2K�[G⠹ source and transform nodes
�[2K�[1A�[2K�[G⠸ source and transform nodes
�[2K�[1A�[2K�[G⠼ source and transform nodes
�[2K�[1A�[2K�[G⠴ source and transform nodes
�[2K�[1A�[2K�[G⠦ source and transform nodes
�[2K�[1A�[2K�[G⠧ source and transform nodes
�[2K�[1A�[2K�[G⠇ source and transform nodes
�[2K�[1A�[2K�[G⠏ source and transform nodes
�[2K�[1A�[2K�[G⠋ source and transform nodes
�[2K�[1A�[2K�[G⠙ source and transform nodes
�[2K�[1A�[2K�[G⠹ source and transform nodes
�[2K�[1A�[2K�[G⠸ source and transform nodes
�[2K�[1A�[2K�[G⠼ source and transform nodes
�[2K�[1A�[2K�[G⠴ source and transform nodes
�[2K�[1A�[2K�[G⠦ source and transform nodes
�[2K�[1A�[2K�[G⠧ source and transform nodes
�[2K�[1A�[2K�[G⠇ source and transform nodes
�[2K�[1A�[2K�[G⠏ source and transform nodes
�[2K�[1A�[2K�[G⠋ source and transform nodes
�[2K�[1A�[2K�[G⠙ source and transform nodes
�[2K�[1A�[2K�[G⠹ source and transform nodes
�[2K�[1A�[2K�[G⠸ source and transform nodes
�[2K�[1A�[2K�[G⠼ source and transform nodes
�[2K�[1A�[2K�[G⠴ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Started logging for gatsby-source-directus7.
⠴ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Directus data fetcher initializing...
⠴ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info targetStatus is: draft
⠴ source and transform nodes
�[2K�[1A�[2K�[GGSD7: success Connected to Directus!
⠴ source and transform nodes
�[2K�[1A�[2K�[G⠦ source and transform nodes
�[2K�[1A�[2K�[G⠧ source and transform nodes
�[2K�[1A�[2K�[GGSD7: error Error logging in to Directus: { code: 6, message: 'Method Not Allowed' }
⠧ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Failed to log in. Attempting to use public permission for Directus API...
⠧ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Fetching Directus file data...
⠧ source and transform nodes
�[2K�[1A�[2K�[G⠇ source and transform nodes
�[2K�[1A�[2K�[G⠏ source and transform nodes
�[2K�[1A�[2K�[G⠋ source and transform nodes
�[2K�[1A�[2K�[GGSD7: error gatsby-source-directus: Error while fetching files: { code: 300,
message: 'Reading items from "directus_files" collection was denied' }
⠋ source and transform nodes
�[2K�[1A�[2K�[GGSD7: success Found 0 files from Directus.
⠋ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Downloading Directus files to Gatsby build cache...
⠋ source and transform nodes
�[2K�[1A�[2K�[GGSD7: success Downloaded all 0 files from Directus!
⠋ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Fetching Directus Collection data...
⠋ source and transform nodes
�[2K�[1A�[2K�[G⠙ source and transform nodes
�[2K�[1A�[2K�[G⠹ source and transform nodes
�[2K�[1A�[2K�[GError fetching Collections: { code: 300,
message:
'Reading items from "directus_collections" collection was denied' }
⠹ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Fetching Directus Items data...
⠹ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Fetching Directus Relations data...
⠹ source and transform nodes
�[2K�[1A�[2K�[G⠸ source and transform nodes
�[2K�[1A�[2K�[G⠼ source and transform nodes
�[2K�[1A�[2K�[GGSD7: error Error fetching Relations: { code: 300,
message:
'Reading items from "directus_relations" collection was denied' }
⠼ source and transform nodes
�[2K�[1A�[2K�[GGSD7: success Retrieved all data from Directus!
⠼ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Directus data processing starting...
⠼ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Mapping Directus relations to Items...
⠼ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Cleaning junction collections...
⠼ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Mapping Directus files to Items...
⠼ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Generating GraphQL nodes...
⠼ source and transform nodes
�[2K�[1A�[2K�[GGSD7: success All done!
⠼ source and transform nodes
�[2K�[1A�[2K�[GGSD7: info Ended logging for gatsby-source-directus7.
⠼ source and transform nodes
�[2K�[1A�[2K�[Gwarn The gatsby-source-directus7 plugin has generated no Gatsby nodes. Do you need it?
⠼ source and transform nodes
�[2K�[1A�[2K�[Gsuccess source and transform nodes - 3.127 s
⠼ source and transform nodes
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ building schema
�[2K�[1A�[2K�[G⠙ building schema
�[2K�[1A�[2K�[G⠹ building schema
�[2K�[1A�[2K�[Gsuccess building schema - 0.449 s
⠹ building schema
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ createPages
�[2K�[1A�[2K�[GGraphQL query returned error: TypeError: Cannot read property 'allDirectusJob' of undefined
⠋ createPages
�[2K�[1A�[2K�[Gsuccess createPages - 0.025 s
⠋ createPages
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ createPagesStatefully
�[2K�[1A�[2K�[G⠙ createPagesStatefully
�[2K�[1A�[2K�[Gsuccess createPagesStatefully - 0.098 s
⠙ createPagesStatefully
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ onPreExtractQueries
�[2K�[1A�[2K�[Gsuccess onPreExtractQueries - 0.006 s
⠋ onPreExtractQueries
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ update schema
�[2K�[1A�[2K�[Gsuccess update schema - 0.166 s
⠋ update schema
�[2K�[1A�[2K�[G
�[2K�[1A�[2K�[G⠋ extract queries from components
�[2K�[1A�[2K�[G⠙ extract queries from components
�[2K�[1A�[2K�[G⠹ extract queries from components
�[2K�[1A�[2K�[G
ERROR
GraphQL Error Encountered 3 error(s):
- Unknown field 'allDirectusJob' on type 'Query'. Source: document `tmpBuild9Ac0F1E943686D286E71E4881394D538SrcSectionsCareerOpenPositionsIndexJs4246648944` file: `GraphQL request`
GraphQL request:3:15
2 | query {
3 | allDirectusJob {
| ^
4 | edges {
- Unknown field 'allDirectusTeam' on type 'Query'. Source: document `tmpBuild9Ac0F1E943686D286E71E4881394D538SrcSectionsCompanyOurTeamIndexJs2571343049` file: `GraphQL request`
GraphQL request:3:11
2 | query {
3 | allDirectusTeam {
| ^
4 | edges {
- Unknown field 'directusJob' on type 'Query'.
file: /tmp/build_9ac0f1e943686d286e71e4881394d538/src/templates/career/index.js
⠹ extract queries from components
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
here is an example: https://github.com/Steven-Harris/gatsby-starter-default-directus-issue
error: Could not find field type. DirectusFile.childImageSharp
Hey.
Is there a possibility to rebuild the Gatsby site if there is new content? For example I have a collection for Team
where the team in our agency will be added. Now if a new teammate has been added, the site does not automatically update, I always have to rebuild the Gatsby site by myself.
Maybe there is a webhook of some kind hidden, which I have not yet seen.
There appears to be an issue with the gatsby source plugin for Directus 7 if the table has a 'file' field and it is an optional field e.g. the row doesn't need to have an image (file) but can.
I connected the plugin to my directus api and get an error while the plugin is mapping (o2m / m2o) relationships.
Could this happen because not all relationships I defined in directus are filled with data?
The error happens in process.js
in the mapRelations
function. The id in line 129 is not defined.
I will try to investigate a bit more.
Error:
error Plugin gatsby-source-directus7 returned an error
TypeError: Cannot read property 'id' of undefined
- process.js:161 mappedEntities.(anonymous function).mappedEntities.(anonymous function).map.entity
/Users/pgegenfurtner/Projekte/opensource/gatsby-source-directus7/process.js:161:86
- Array.map
- process.js:159 relations.forEach.relation
/Users/pgegenfurtner/Projekte/opensource/gatsby-source-directus7/process.js:159:47
- Array.forEach
- process.js:145 mapRelations
/Users/pgegenfurtner/Projekte/opensource/gatsby-source-directus7/process.js:145:13
- gatsby-node.js:70 Object.exports.sourceNodes
/Users/pgegenfurtner/Projekte/opensource/gatsby-source-directus7/gatsby-node.js:70:60
Hey.
When requesting an article with a translations filter, to only get e.g. en
, it doesn't work. It still returns all articles.
query {
allDirectusArticle(filter: {translations: {elemMatch: {language: {eq: "en"}}}}) {
edges {
node {
translations {
title
slug
excerpt
language
}
}
}
}
}
{
"data": {
"allDirectusArticle": {
"edges": [
{
"node": {
"translations": [
{
"title": "10 tips to manage your finances",
"slug": "10-tips-to-manage-your-finances",
"excerpt": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Qui est in parvis malis.",
"language": "en"
},
{
"title": "10 Tipps, wie Sie Ihre Finanzen verwalten können",
"slug": "10-tipps-wie-sie-ihre-finanzen-verwalten-konnen",
"excerpt": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Qui est in parvis malis.",
"language": "de"
}
]
}
}
]
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.