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): support named splats in functions #33301

Merged
merged 8 commits into from
Oct 12, 2021
Merged

Conversation

KyleAMathews
Copy link
Contributor

@KyleAMathews KyleAMathews commented Sep 24, 2021

Switch from using path-to-regexp to @reach/router to do matches so we're we use the same route matching lib as the client and to add support for named splats e.g. /foo/[...bar].js (path-to-regexp nameless splats like /foo/[...].js.

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 24, 2021
@KyleAMathews KyleAMathews added type: feature or enhancement Issue that is not a bug and requests the addition of a new feature or enhancement. and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Sep 24, 2021
exports[`develop dynamic routes unnamed wildcard routes 1`] = `
Object {
"*": "super",
"0": "super",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

send the path-to-regexp param style route so we avoid a breaking change until v5.

@LekoArts
Copy link
Contributor

Can you please also update any relevant documentation for this? I think we somewhere note that we don't support this and/or the syntax needs change.

@KyleAMathews
Copy link
Contributor Author

We never did support dynamic routing for functions in cloud so we removed the docs for launch — @dmccraw is working on adding that which actually is what prompted noticing that we were missing support for named splats in the framework. When we add back the docs, let's make sure to add docs for this too.

@njbmartin
Copy link
Contributor

Great to see this being supported! I tried using dynamic routing in my entry for the FuncJam.
https://github.com/njbmartin/gatsby-funcjam-21#dynamic-api-routing

TLDR;

I misread the documentation (https://www.gatsbyjs.com/docs/reference/functions/routing/) ("Function routing shares the same syntax as page routing."). Oddly enough, it worked locally, even when serving a build, but doesn't work in Gatsby Cloud... sad face emoji

@wardpeet
Copy link
Contributor

Seems like a valid error in the integration tests. I would also suggest moving to inlineSnapshot for the one small snapshots, it will make the tests a little bit more clear

@KyleAMathews
Copy link
Contributor Author

Turns out I'd just missed committing my new function file 🤦

@LekoArts LekoArts added the topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters) label Oct 12, 2021
KyleAMathews and others added 8 commits October 12, 2021 17:35
Switch from using path-to-regexp to @reach/router to do matches
so we're we use the same route matching lib as elsewhere + to add support for named splats (path-to-regexp only support `/foo/*` not `/foo/*bar`.
@wardpeet wardpeet added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Oct 12, 2021
@wardpeet wardpeet merged commit 018c041 into master Oct 12, 2021
@wardpeet wardpeet deleted the match-functions branch October 12, 2021 18:58
@KyleAMathews
Copy link
Contributor Author

Thanks for finishing this out @wardpeet !

vladar pushed a commit that referenced this pull request Oct 13, 2021
Co-authored-by: Ward Peeters <[email protected]>
(cherry picked from commit 018c041)
vladar pushed a commit that referenced this pull request Oct 14, 2021
Co-authored-by: Ward Peeters <[email protected]>
(cherry picked from commit 018c041)

Co-authored-by: Kyle Mathews <[email protected]>
wardpeet added a commit to herecydev/gatsby that referenced this pull request Oct 29, 2021
axe312ger pushed a commit that referenced this pull request Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters) type: feature or enhancement Issue that is not a bug and requests the addition of a new feature or enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants