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

Finish docgen plugin #928

Merged
merged 7 commits into from
May 11, 2017
Merged

Finish docgen plugin #928

merged 7 commits into from
May 11, 2017

Conversation

jquense
Copy link
Contributor

@jquense jquense commented May 6, 2017

ok mostly correct now. I haven’t completely tested it yet but should be 90% done at least :P

@@ -0,0 +1,126 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops new in npm5

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

Could we ignore it like we do yarn.lock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I think so. I'll remove it anyway.

@@ -36,6 +36,7 @@ module.exports = async function onNodeCreate({
content: data.content,
}
markdownNode.frontmatter = {
title: ``, // always include a title
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh, you get errors otherwise :/

@gatsbybot
Copy link
Collaborator

gatsbybot commented May 6, 2017

Deploy preview failed.

Built with commit b1a6d0a

https://app.netlify.com/sites/using-drupal/deploys/5913589f8ebdd970d0abb531

@gatsbybot
Copy link
Collaborator

gatsbybot commented May 6, 2017

Deploy preview failed.

Built with commit b1a6d0a

https://app.netlify.com/sites/gatsbyjs/deploys/5913a6dd424ef2062e402a3a

@gatsbybot
Copy link
Collaborator

gatsbybot commented May 6, 2017

Deploy preview failed.

Built with commit b1a6d0a

https://app.netlify.com/sites/gatsbygram/deploys/5913589f8ebdd970d0abb52f

},
composes: {
type: new GraphQLList(GraphQLString),
resolve: resolve(`composes`),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why you're doing this here vs. letting Gatsby handle creating the schema for them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I think you should only explicitly create GraphQL schema bits when a) transforming the data is pretty expensive as with markdown or b) you want to give the user control over the transformation of the data e.g. image transformation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally I couldn't because of that bug in the input generation... Also I was worried that they wouldn't always be there depending on the sites components. Other than that tho I was just being explicit since I know the shape.

Honestly for the simpler ones here there isn't any good reason it's this way :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, I noticed a bug in the inputs the arguments are getting created for description___NODE not description

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool :-) a bug in input generation is a good reason!

You want to try removing this stuff real quick to see if everything works? Really want transformation/sourcing to be just a "throw data at Gatsby and you're done" type experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be near a computer for a while (heading out for the weekend), happy to change it tho. But if you wanna get it out feel free to jump in, or merge and we can change it later

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be mostly gone for the weekend too! So if you could jump on it Monday that'd be great. Have some paid work I need to do early next week.

@KyleAMathews
Copy link
Contributor

This looks so cool! Looking forward to trying it out.

@jquense
Copy link
Contributor Author

jquense commented May 10, 2017

think I'm done here 👍

// TODO: if you want to support infering Union types this should be handled
// differently. Maybe merge all like types into examples for each type?
// e.g. union: [1, { foo: true }, ['brown']] -> Union Int|Object|List
if (!isSameType(obj, next)) return null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it bails on this branch if the values are polymorphic

@jquense
Copy link
Contributor Author

jquense commented May 10, 2017

why is it it failing!

// TODO: if you want to support infering Union types this should be handled
// differently. Maybe merge all like types into examples for each type?
// e.g. union: [1, { foo: true }, ['brown']] -> Union Int|Object|List
if (!isSameType(obj, next)) return INVALID_VALUE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is better. The other option is if the types are different just use the first one we saw.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think union types are what we want. They're a lot less discoverable IMO. I think we should just want and say, "hey data provider! Group your different types under their own keys or node types."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you prefer to throw here then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let's. The vast majority of Gatsby users will never see it think about these issues. They'll just add source and transformer plugins and get going. So it's important that for the few creating plugins that we insist they get things right so little mistakes made there don't reverberate across everyone downstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually as I'm thinking about it, its tough to throw...A plugin author would most likely "fix" this during the extendNodes phase which is after example gathering and not accessible for input inference.

In the specific case here the union type is component.props[].type.value You could "fix" that in the node creation bit, but actually I just want to make that JSON scalar rather then split that out into 5 different fields, arrayValue, enumValue, shapeValue, customValue, etc. For one it differs fairly dramatically from the underlying source format and would require a bunch of documentation apart from react-docgen, I also think it's less ergonomic in this case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm ok. Can definitely see that union types make sense here. No need to figure out everything right now though. After a few more dozen source and transformer plugins the patterns will be a lot more clear. A bit busy today but will try to merge this later along with getting my rr V4 PR in.

Copy link
Contributor Author

@jquense jquense May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can always revisit, at the moment it's just not breaking on mixed types and leaving it to the plugin author to address. I'm not sure if stuff is still not building tho looking at the PR checks....stuff is running locally for me.

@KyleAMathews
Copy link
Contributor

Oh... realized why the build is failing. I published a canary from my RR v4 branch to test something which means that's what your builds are building from so of course failing. I played loose and free with canary releases, etc. when I was the only one basically working on 1.0 but I need to be more careful with that now.

@KyleAMathews
Copy link
Contributor

It'd be nice too if the Netlify build logs were public...

@KyleAMathews KyleAMathews merged commit 5f9232d into 1.0 May 11, 2017
@KyleAMathews
Copy link
Contributor

Thanks for the really nice PR!

@KyleAMathews KyleAMathews deleted the docgen branch May 11, 2017 05:59
@KyleAMathews
Copy link
Contributor

Oh actually I published the canary so my builds would succeed :-)

Hmmm... this needs fixed somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants