Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-source-strapi): Generated Types #433

Open
nimame opened this issue Jun 4, 2023 · 7 comments
Open

feat(gatsby-source-strapi): Generated Types #433

nimame opened this issue Jun 4, 2023 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@nimame
Copy link

nimame commented Jun 4, 2023

The Readme states the following limitation:

At the moment, fields that do not have at least one populated instance will not be created in the GraphQL schema. This can break your site when field values get removed. You may workaround with an extra content entry with all fields filled out.

The fact that a site can break (does not build successfully) in those situations has turned out to be very annoying to me, even if it can be avoided by the mentioned workaround. And it makes optional fields on single types practically infeasible.

I think it should be feasible and would greatly improve the quality of the plugin. I didn't find any feature request or discussion on this topic, so I am raising it here.

Describe the solution you'd like

The plugin could explicitly generate data types based on the strapi schemas (which are already fetched here I think) before generating the nodes, e.g. using the createTypes hook (see Gatsby docs).

Describe alternatives you've considered

The alternative suggested in the Readme (create "an extra content entry with all fields filled out") feels like a hack. It doesn't work for single-types. It would feel more intuitive, if an optional field in Strapi, could be treated as an optional field in Gatsby, too.

@nimame nimame added the enhancement New feature or request label Jun 4, 2023
@moonmeister moonmeister changed the title feat(gatsby-source-strapi): Remove limitation feat(gatsby-source-strapi): Generated Types Jun 4, 2023
@moonmeister
Copy link
Contributor

We'd love to see this, and agree it can be very annoying. A PR is welcome.

@fgroenendijk
Copy link

I also did not like to add extra content, and found a workable solution @nimame.
The first step is filling in all the fields once.
Then, using the code below, generate a typeDefs.txt file.
Copy and paste everything, or just problematic ones, from the typeDefs.txt file in the const typeDefs.

import * as fs from 'fs';
exports.sourceNodes = ({ actions }) => {
	if (fs.existsSync('./typeDefs.txt')) {
		fs.rmSync('./typeDefs.txt');
	}
	actions.printTypeDefinitions({ path: './typeDefs.txt' });

	const { createTypes } = actions;
	const typeDefs = ``;
	createTypes(typeDefs);
}

Works with gatsby 5.7.0

@nimame
Copy link
Author

nimame commented Jun 20, 2023

Thanks for the suggestion @fgroenendijk. Would be cool if something like that could be integrated into the plugin and handled behind the scenes automatically. I had a look at the source of the plugin but I don't think I'm smart enough to do a PR myself :)

@laurenskling
Copy link
Contributor

Myself, I actually manually create all the types via createSchemaCustomization. The "just create extra content" is extremely hacky.
I would also love to see the schema auto generated fully. Im pretty sure its possible from Strapi. If anyone is up for the job to create something like this I would be happy to get it merged in

@laurenskling laurenskling added the help wanted Extra attention is needed label Jul 2, 2023
@robclancy
Copy link

I've used a lot of source plugins that use graphql. This is the first one that does this. I don't know how it ever got released in this state...

@robclancy
Copy link

Honestly the strapi plugin is so bad for so many different reasons it would probably be easier to fork the directus plugin and adapt the API.

@moonmeister
Copy link
Contributor

moonmeister commented Oct 2, 2023

Any and all contributions would be welcome @robclancy. Strapi has passed the buck on maintenance and donated the plugin to us so folks could make improvements as needed. If you want to take charge on a major update I'm happy to support that effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants