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

Enhanced support for page queries/components #74

Open
cometkim opened this issue Apr 15, 2020 · 4 comments
Open

Enhanced support for page queries/components #74

cometkim opened this issue Apr 15, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@cometkim
Copy link
Owner

  • Codegen for page context (that provided in createPage)
  • Design DX for auto-fixing page queries.
  • more use cases in page component
@cometkim cometkim added the enhancement New feature or request label Apr 15, 2020
@cometkim cometkim self-assigned this Apr 15, 2020
@cometkim cometkim changed the title Enhanced support for page components Enhanced support for page queries/components Apr 15, 2020
@cometkim cometkim mentioned this issue Apr 19, 2020
6 tasks
@sanjaypojo
Copy link

sanjaypojo commented Jun 27, 2020

Hi @cometkim, thanks for a great library 😄

I was curious if there's any way to type the data prop from a page query automatically at the moment? And whether there's some workaround for this until the actual you ship this feature?

EDIT: I realized I can just type the components as React.FC<{data: GatsbyTypes.PageQuery}>. Might be cool to include this in the docs. Happy to write it up if you think that makes sense!

@cometkim
Copy link
Owner Author

Hi @sanjaypojo, thanks for your interest in this issue :)

The data fields can easily be typed with the query type already generated, as you mentioned.

Actually, pageContext also has a generated type, but the problem is that all page contexts are merged into one single type; SitePageContext.

So it needs some static analysis of the createPage call to extract the subtypes it needs.

@cometkim
Copy link
Owner Author

And, I found it inconvenient to include a lot of nullability in the generated type because the Gatsby schema is inferred fields as Nullable if not explicitly declared as non-null.

For now, the best way to solve this is to write a type guard user self, but it is too cumbersome.

And it is not an option to manipulate the schema arbitrarily or to cheat the type.

To do this, I first aim to create a type guard function that can be used in general. And then provide a basic practice for typing page queries through it.

@cometkim cometkim pinned this issue Jul 2, 2020
@cometkim
Copy link
Owner Author

cometkim commented Jul 7, 2020

Oh, I just realized gatsby already provides some utility types for page props

https://github.com/gatsbyjs/gatsby/blob/a72caa67f8/packages/gatsby/index.d.ts#L33-L120

@cometkim cometkim added this to the v3 milestone Oct 27, 2020
@cometkim cometkim unpinned this issue Jan 29, 2021
@cometkim cometkim removed this from the v3 milestone May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants