-
Notifications
You must be signed in to change notification settings - Fork 176
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
Add methods to support App Router #716
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
JohnAlbin
force-pushed
the
665-app-router-methods
branch
from
March 8, 2024 10:00
3796ef2
to
661cae1
Compare
Closed
JohnAlbin
force-pushed
the
665-app-router-methods
branch
2 times, most recently
from
March 8, 2024 17:30
1107112
to
bcc17d4
Compare
5 tasks
JohnAlbin
force-pushed
the
665-app-router-methods
branch
4 times, most recently
from
March 11, 2024 11:51
149cab0
to
e3ea377
Compare
2 tasks
JohnAlbin
force-pushed
the
665-app-router-methods
branch
5 times, most recently
from
April 2, 2024 01:58
56d03c6
to
1bd09ff
Compare
JohnAlbin
force-pushed
the
665-app-router-methods
branch
2 times, most recently
from
April 14, 2024 10:34
6b47ab2
to
9856af9
Compare
JohnAlbin
force-pushed
the
665-app-router-methods
branch
6 times, most recently
from
April 15, 2024 17:16
e582f5b
to
177c4a7
Compare
And… unblocked now. |
JohnAlbin
force-pushed
the
665-app-router-methods
branch
from
April 18, 2024 01:37
177c4a7
to
d7928ce
Compare
JohnAlbin
force-pushed
the
665-app-router-methods
branch
from
April 18, 2024 10:23
d7928ce
to
db8d28f
Compare
JohnAlbin
force-pushed
the
665-app-router-methods
branch
from
April 18, 2024 12:11
db8d28f
to
eb9c74c
Compare
The DrupalClient class has been renamed to NextDrupalPages and has been refactored to inherit from the NextDrupalBase (base class) and NextDrupal (JsonAPI/App Router class). NextDrupalPages class contains the methods that are only needed to support Next.js' Pages Router. NextDrupalPages is also available as "DrupalClient" for backwards-compatibility. The getPathFromContext() method has been replaced with the constructPathFromSegment() method for App Router usages. Issue #665
…ticParams() The App Router's new generateStaticParams() replaces Pages Router's getStaticProps(). The new getResourceCollectionPathSegments() method supports generateStaticParams() by returning a list of path segments. This new method replaces the old getStaticPathsFromContext() method. Fixes #665
…ctionPathSegments() Issue #665
JohnAlbin
force-pushed
the
665-app-router-methods
branch
from
April 18, 2024 12:23
eb9c74c
to
f533335
Compare
robdecker
approved these changes
Apr 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request is for:
packages/next-drupal
GitHub Issue: #665
Describe your changes
The
DrupalClient
class has been renamed toNextDrupalPages
and refactored to inherit from 2 base classes. All the methods that were inDrupalClient
have been distributed amongst these 3 classes.NextDrupalPages
(includes Pages Router methods)inherits from
NextDrupal
(includes App Router methods and JSON:API methods)inherits from
NextDrupalBase
(includes Fetch method, authentication methods and basic helper methods)fetch()
NextDrupalBase
The
FetchOptions
Type definition said that aHeaders
object could be passed toheaders
but this wasn't true in v1.6. This has been fixed in v2.0.buildUrl()
NextDrupalBase
private _debug()
NextDrupalBase
Renamed to
debug()
and made public. See #668getAccessToken()
NextDrupalBase
private handleJsonApiErrors()
NextDrupalBase
Made public and renamed to
throwIfJsonErrors()
since it handles both regular JSON error messages and JSON:API errors. It's included inNextDrupalBase
since it is used bygetAccessToken()
.private getErrorsFromResponse()
NextDrupalBase
To support inheritance, this method is now public. It's included in
NextDrupalBase
since it is used bygetAccessToken()
.createResource()
NextDrupal
createFileResource()
NextDrupal
updateResource()
NextDrupal
deleteResource()
NextDrupal
getResource()
NextDrupal
getResourceByPath()
NextDrupal
getResourceCollection()
NextDrupal
translatePath()
NextDrupal
getIndex()
NextDrupal
getMenu()
NextDrupal
buildMenuTree()
NextDrupalPages
This method has been refactored to be a wrapper around
new DrupalMenuTree(items)
.getView()
NextDrupal
getSearchIndex()
NextDrupal
deserialize()
NextDrupal
private throwError()
NextDrupal
Made public and renamed to
logOrThrowError
to better reflect its purpose.getEntryForResourceType()
NextDrupalPages
getResourceFromContext()
NextDrupalPages
getResourceCollectionFromContext()
NextDrupalPages
getPathsFromContext()
NextDrupalPages
getStaticPathsFromContext()
NextDrupalPages
buildStaticPathsFromResources()
NextDrupalPages
buildStaticPathsParamsFromPaths()
NextDrupalPages
translatePathFromContext()
NextDrupalPages
getPathFromContext()
NextDrupalPages
preview()
NextDrupalPages
getSearchIndexFromContext()
NextDrupalPages
private formatJsonApiErrors()
Removed; any internal usage was replaced with the public static method
JsonApiErrors.formatMessage()
private getAuthFromContextAndOptions()
NextDrupalPages
Made public.
The following new methods are available. New methods that don't mention a separate issue number were added with this PR.
buildEndpoint()
NextDrupalBase
andNextDrupal
Builds an endpoint URL using
apiPrefix
. TheNextDrupal
version adds additional JSON:API-specific options. This method is a better version of the oldgetEntryForResourceType()
method.fetchResourceEndpoint()
NextDrupal
Helper method to lookup the endpoint URL instead of constructing it.
getAuthorizationHeader()
NextDrupalBase
See #707.
constructPathFromSegment()
NextDrupalBase
Replaces the
getPathFromContext()
method for App Router use cases.getResourceCollectionPathSegments()
NextDrupal
For use with Next.js'
generateStaticParams()
. Replaces Pages Router'sgetStaticProps()
andDrupalClient.getStaticPathsFromContext()
method.addLocalePrefix()
NextDrupalBase
Helper method that conditionally adds a locale prefix to a Drupal path.
validateDraftUrl()
NextDrupalBase
Helper method used by the
"next-drupal/draft"
functions andDrupalClient.preview()
. See #670.getResourceCollectionPathSegments()
The new
getResourceCollectionPathSegments()
method supports Next.js'generateStaticParams()
function. It returns an array of Drupal path-related data that can be used to provide a static list for use in Next.js Dynamic Segments.Each item in the returned array looks like this:
In many cases, the
segments
array will the only item needed. But the other properties of the object will allow more advanced use-cases.Examples:
When used in a
app/[...slug]/page.tsx
file, the[...slug]
Dynamic Segment indicates thatgenerateStaticParams()
is expected to return an array of objects with aslug
property containing an array of strings.When used in a
app/[lang]/blog/[category]/[...slug]/page.tsx
file,generateStaticParams()
is expected to return an array of objects with alang
string, acategory
string and aslug
array of strings.