gatsby-source-strapi
gatsby-source-strapi copied to clipboard
Support plugin prefixes
This PR fixes issue #288 by looking at plugin names in the schema and prepending them to endpoint urls.
Ignoring admin types (uid starting with admin::
) and handling the exceptional case of the user type which comes from the plugin users-permissions
but is available via the /api/users/
endpoint.
A simple test to get a list of all locales:
//gatsby-config.js
{
resolve: 'gatsby-source-strapi',
options: {
collectionTypes: ['locale']
}
}
Just also tested with collectionTypes: ['file']
to get a list of all files but this fails due to another issue that is unrelated to this PR. In the files schema there is an attribute (relation) related
with a targetAttribute: null
. This leads to an error in makeParentNodeName
called from prepareRelationNode
.
I'm not sure if that's a Strapi issue and the targetAttribute
shouldn't be null
or if there's a check missing somewhere in prepareRelationNode
.
@mwoelk the file model cannot be queried at the moment in the Gatsby source plugin primarily because the API response is different than the content API one. So if we want to include this model we need to treat it differently.
I just started trying to upgrade my codebase to strapi 4 and running into this issue. All my content types are in plugins. So the endpoint would be /api/pages/pages
(/api/${pluginName}/${pluralName}
). I cannot set this endpoint, since the endpoints do not take plugin names into consideration at: https://github.com/strapi/gatsby-source-strapi/blob/48fa72d8f20a1d8cf168db34015397a368faacd9/src/helpers.js#L122
On the strapi side, I see no way to tell the routes not to take the pluginName into the endpoint. So I'm stuck right now without this fix. I cannot use source-strapi to fetch my content, so I cannot upgrade to v4 right now :(
This PR would fix my use case. I understand it won't work for things like file
, but you cannot query them right now either. So it's not breaking anything.
This is actually blocking me getting my new Strapi4 Gatsby project live. It would be great if it could be looked at. Please let me know how I can assist.
@remidej I read you are planning v2.1. Could you please look into this? Without this, I cannot deploy my site to Gatsby Cloud. I've been running this code as a patch-package
for a while now, but Gatsby Cloud's system don't let me use patch-package (because they do a yarn add
after the yarn install
)
Please let me know if you have any doubts about the code, I will try to look into it.
@mwoelk thanks for the PR. I needed this myself actually as you may have read before. Since I'm not a co-maintainer, I went ahead and merged this. The release will have to wait until I've transferred the code into the User Collective monorepo.