-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(basic-starter): upgrade starters to NextDrupal classes
Issue #601
- Loading branch information
Showing
24 changed files
with
266 additions
and
158 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,7 @@ | |
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# build/test artifacts | ||
/.turbo | ||
# testing | ||
/coverage | ||
|
||
# next.js | ||
|
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
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
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
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
starters/basic-starter/components/navigation/HeaderNav.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Link } from "@/components/navigation/Link" | ||
|
||
export function HeaderNav() { | ||
return ( | ||
<header> | ||
<div className="container flex items-center justify-between py-6 mx-auto"> | ||
<Link href="/" className="text-2xl font-semibold no-underline"> | ||
Next.js for Drupal | ||
</Link> | ||
<Link | ||
href="https://next-drupal.org/docs" | ||
target="_blank" | ||
rel="external" | ||
className="hover:text-blue-600" | ||
> | ||
Read the docs | ||
</Link> | ||
</div> | ||
</header> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { forwardRef } from "react" | ||
import NextLink from "next/link" | ||
import type { AnchorHTMLAttributes, ReactNode } from "react" | ||
import type { LinkProps as NextLinkProps } from "next/link" | ||
|
||
type LinkProps = NextLinkProps & | ||
Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof NextLinkProps> & { | ||
children?: ReactNode | ||
} | ||
|
||
export const Link = forwardRef<HTMLAnchorElement, LinkProps>( | ||
function LinkWithRef( | ||
{ | ||
// Turn next/link prefetching off by default. | ||
// @see https://github.com/vercel/next.js/discussions/24009 | ||
prefetch = false, | ||
...rest | ||
}, | ||
ref | ||
) { | ||
return <NextLink prefetch={prefetch} {...rest} ref={ref} /> | ||
} | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { DrupalClient } from "next-drupal" | ||
import { NextDrupalPages } from "next-drupal" | ||
|
||
const baseUrl: string = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL || "" | ||
const clientId = process.env.DRUPAL_CLIENT_ID || "" | ||
const clientSecret = process.env.DRUPAL_CLIENT_SECRET || "" | ||
const baseUrl = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL as string | ||
const clientId = process.env.DRUPAL_CLIENT_ID as string | ||
const clientSecret = process.env.DRUPAL_CLIENT_SECRET as string | ||
|
||
export const drupal = new DrupalClient(baseUrl, { | ||
export const drupal = new NextDrupalPages(baseUrl, { | ||
auth: { | ||
clientId, | ||
clientSecret, | ||
}, | ||
useDefaultEndpoints: true, | ||
// debug: true, | ||
}) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,7 @@ | |
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# build/test artifacts | ||
/.turbo | ||
# testing | ||
/coverage | ||
|
||
# next.js | ||
|
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
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
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
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
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
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
starters/graphql-starter/components/navigation/HeaderNav.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Link } from "@/components/navigation/Link" | ||
|
||
export function HeaderNav() { | ||
return ( | ||
<header> | ||
<div className="container flex items-center justify-between py-6 mx-auto"> | ||
<Link href="/" className="text-2xl font-semibold no-underline"> | ||
Next.js for Drupal | ||
</Link> | ||
<Link | ||
href="https://next-drupal.org/docs" | ||
target="_blank" | ||
rel="external" | ||
className="hover:text-blue-600" | ||
> | ||
Read the docs | ||
</Link> | ||
</div> | ||
</header> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { forwardRef } from "react" | ||
import NextLink from "next/link" | ||
import type { AnchorHTMLAttributes, ReactNode } from "react" | ||
import type { LinkProps as NextLinkProps } from "next/link" | ||
|
||
type LinkProps = NextLinkProps & | ||
Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof NextLinkProps> & { | ||
children?: ReactNode | ||
} | ||
|
||
export const Link = forwardRef<HTMLAnchorElement, LinkProps>( | ||
function LinkWithRef( | ||
{ | ||
// Turn next/link prefetching off by default. | ||
// @see https://github.com/vercel/next.js/discussions/24009 | ||
prefetch = false, | ||
...rest | ||
}, | ||
ref | ||
) { | ||
return <NextLink prefetch={prefetch} {...rest} ref={ref} /> | ||
} | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,13 @@ | ||
import { DrupalClient } from "next-drupal" | ||
import { NextDrupalGraphQL } from "./next-drupal-graphql" | ||
|
||
const baseUrl: string = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL || "" | ||
const clientId = process.env.DRUPAL_CLIENT_ID || "" | ||
const clientSecret = process.env.DRUPAL_CLIENT_SECRET || "" | ||
const baseUrl = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL as string | ||
const clientId = process.env.DRUPAL_CLIENT_ID as string | ||
const clientSecret = process.env.DRUPAL_CLIENT_SECRET as string | ||
|
||
export const drupal = new DrupalClient(baseUrl, { | ||
export const drupal = new NextDrupalGraphQL(baseUrl, { | ||
auth: { | ||
clientId, | ||
clientSecret, | ||
}, | ||
// debug: true, | ||
}) | ||
|
||
export const graphqlEndpoint = drupal.buildUrl("/graphql") | ||
|
||
type QueryPayload = { | ||
query: string | ||
variables?: Record<string, string> | ||
} | ||
|
||
type QueryJsonResponse<DataType> = { | ||
data?: DataType | ||
errors?: { message: string }[] | ||
} | ||
|
||
// This is a wrapper around drupal.fetch. | ||
// Acts as a query helper. | ||
export async function query<DataType>(payload: QueryPayload) { | ||
const response = await drupal.fetch(graphqlEndpoint.toString(), { | ||
method: "POST", | ||
body: JSON.stringify(payload), | ||
withAuth: true, // Make authenticated requests using OAuth. | ||
headers: { | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
}, | ||
}) | ||
|
||
if (!response?.ok) { | ||
throw new Error(response.statusText) | ||
} | ||
|
||
const { data, errors }: QueryJsonResponse<DataType> = await response.json() | ||
|
||
if (errors) { | ||
console.log(errors) | ||
throw new Error(errors?.map((e) => e.message).join("\n") ?? "unknown") | ||
} | ||
|
||
return data | ||
} |
Oops, something went wrong.