-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #898 from Shopify/enable-remove-rest-future-flag
Enable remove rest future flag
- Loading branch information
1 parent
11f70c5
commit 456e5fe
Showing
18 changed files
with
880 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import fs from "fs"; | ||
import { LATEST_API_VERSION } from "@shopify/shopify-api"; | ||
import { shopifyApiProject, ApiType } from "@shopify/api-codegen-preset"; | ||
import type { IGraphQLConfig } from "graphql-config"; | ||
|
||
function getConfig() { | ||
const config: IGraphQLConfig = { | ||
projects: { | ||
default: shopifyApiProject({ | ||
apiType: ApiType.Admin, | ||
apiVersion: LATEST_API_VERSION, | ||
documents: ["./app/**/*.{js,ts,jsx,tsx}", "./app/.server/**/*.{js,ts,jsx,tsx}"], | ||
outputDir: "./app/types", | ||
}), | ||
}, | ||
}; | ||
|
||
let extensions: string[] = []; | ||
try { | ||
extensions = fs.readdirSync("./extensions"); | ||
} catch { | ||
// ignore if no extensions | ||
} | ||
|
||
for (const entry of extensions) { | ||
const extensionPath = `./extensions/${entry}`; | ||
const schema = `${extensionPath}/schema.graphql`; | ||
if (!fs.existsSync(schema)) { | ||
continue; | ||
} | ||
config.projects[entry] = { | ||
schema, | ||
documents: [`${extensionPath}/**/*.graphql`], | ||
}; | ||
} | ||
|
||
return config; | ||
} | ||
|
||
module.exports = getConfig(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
declare global { | ||
var prisma: PrismaClient; | ||
} | ||
|
||
if (process.env.NODE_ENV !== "production") { | ||
if (!global.prisma) { | ||
global.prisma = new PrismaClient(); | ||
} | ||
} | ||
|
||
const prisma: PrismaClient = global.prisma || new PrismaClient(); | ||
|
||
export default prisma; |
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,59 @@ | ||
import { PassThrough } from "stream"; | ||
import { renderToPipeableStream } from "react-dom/server"; | ||
import { RemixServer } from "@remix-run/react"; | ||
import { | ||
createReadableStreamFromReadable, | ||
type EntryContext, | ||
} from "@remix-run/node"; | ||
import { isbot } from "isbot"; | ||
import { addDocumentResponseHeaders } from "./shopify.server"; | ||
|
||
export const streamTimeout = 5000; | ||
|
||
export default async function handleRequest( | ||
request: Request, | ||
responseStatusCode: number, | ||
responseHeaders: Headers, | ||
remixContext: EntryContext | ||
) { | ||
addDocumentResponseHeaders(request, responseHeaders); | ||
const userAgent = request.headers.get("user-agent"); | ||
const callbackName = isbot(userAgent ?? '') | ||
? "onAllReady" | ||
: "onShellReady"; | ||
|
||
return new Promise((resolve, reject) => { | ||
const { pipe, abort } = renderToPipeableStream( | ||
<RemixServer | ||
context={remixContext} | ||
url={request.url} | ||
/>, | ||
{ | ||
[callbackName]: () => { | ||
const body = new PassThrough(); | ||
const stream = createReadableStreamFromReadable(body); | ||
|
||
responseHeaders.set("Content-Type", "text/html"); | ||
resolve( | ||
new Response(stream, { | ||
headers: responseHeaders, | ||
status: responseStatusCode, | ||
}) | ||
); | ||
pipe(body); | ||
}, | ||
onShellError(error) { | ||
reject(error); | ||
}, | ||
onError(error) { | ||
responseStatusCode = 500; | ||
console.error(error); | ||
}, | ||
} | ||
); | ||
|
||
// Automatically timeout the React renderer after 6 seconds, which ensures | ||
// React has enough time to flush down the rejected boundary contents | ||
setTimeout(abort, streamTimeout + 1000); | ||
}); | ||
} |
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 @@ | ||
declare module "*.css"; |
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,30 @@ | ||
import { | ||
Links, | ||
Meta, | ||
Outlet, | ||
Scripts, | ||
ScrollRestoration, | ||
} from "@remix-run/react"; | ||
|
||
export default function App() { | ||
return ( | ||
<html> | ||
<head> | ||
<meta charSet="utf-8" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1" /> | ||
<link rel="preconnect" href="https://cdn.shopify.com/" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdn.shopify.com/static/fonts/inter/v4/styles.css" | ||
/> | ||
<Meta /> | ||
<Links /> | ||
</head> | ||
<body> | ||
<Outlet /> | ||
<ScrollRestoration /> | ||
<Scripts /> | ||
</body> | ||
</html> | ||
); | ||
} |
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,3 @@ | ||
import { flatRoutes } from "@remix-run/fs-routes"; | ||
|
||
export default flatRoutes(); |
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,58 @@ | ||
import type { LoaderFunctionArgs } from "@remix-run/node"; | ||
import { redirect } from "@remix-run/node"; | ||
import { Form, useLoaderData } from "@remix-run/react"; | ||
|
||
import { login } from "../../shopify.server"; | ||
|
||
import styles from "./styles.module.css"; | ||
|
||
export const loader = async ({ request }: LoaderFunctionArgs) => { | ||
const url = new URL(request.url); | ||
|
||
if (url.searchParams.get("shop")) { | ||
throw redirect(`/app?${url.searchParams.toString()}`); | ||
} | ||
|
||
return { showForm: Boolean(login) }; | ||
}; | ||
|
||
export default function App() { | ||
const { showForm } = useLoaderData<typeof loader>(); | ||
|
||
return ( | ||
<div className={styles.index}> | ||
<div className={styles.content}> | ||
<h1 className={styles.heading}>A short heading about [your app]</h1> | ||
<p className={styles.text}> | ||
A tagline about [your app] that describes your value proposition. | ||
</p> | ||
{showForm && ( | ||
<Form className={styles.form} method="post" action="/auth/login"> | ||
<label className={styles.label}> | ||
<span>Shop domain</span> | ||
<input className={styles.input} type="text" name="shop" /> | ||
<span>e.g: my-shop-domain.myshopify.com</span> | ||
</label> | ||
<button className={styles.button} type="submit"> | ||
Log in | ||
</button> | ||
</Form> | ||
)} | ||
<ul className={styles.list}> | ||
<li> | ||
<strong>Product feature</strong>. Some detail about your feature and | ||
its benefit to your customer. | ||
</li> | ||
<li> | ||
<strong>Product feature</strong>. Some detail about your feature and | ||
its benefit to your customer. | ||
</li> | ||
<li> | ||
<strong>Product feature</strong>. Some detail about your feature and | ||
its benefit to your customer. | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.