-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
336 additions
and
9 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,6 @@ | ||
--- | ||
'@keystone-next/keystone': minor | ||
'@keystone-next/types': minor | ||
--- | ||
|
||
Added `generateNextGraphqlAPI` and `generateNodeAPI` experimental options |
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,5 @@ | ||
--- | ||
'@keystone-next/keystone': minor | ||
--- | ||
|
||
Added `withKeystone` in `next` entrypoint |
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,12 @@ | ||
import { config } from '@keystone-next/keystone/schema'; | ||
|
||
import { Post } from './schema'; | ||
|
||
export default config({ | ||
db: { adapter: 'prisma_sqlite', url: 'file:./app.db' }, | ||
experimental: { | ||
generateNextGraphqlAPI: true, | ||
generateNodeAPI: true, | ||
}, | ||
lists: { Post }, | ||
}); |
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,2 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> |
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 @@ | ||
const { withKeystone } = require('@keystone-next/keystone/next'); | ||
|
||
module.exports = withKeystone(); |
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,27 @@ | ||
{ | ||
"name": "@keystone-next/example-next-lite", | ||
"version": "1.0.3", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "next dev", | ||
"start": "next start", | ||
"build": "next build" | ||
}, | ||
"dependencies": { | ||
"@keystone-next/admin-ui": "^12.0.0", | ||
"@keystone-next/fields": "^5.3.0", | ||
"@keystone-next/keystone": "^14.0.0", | ||
"dotenv": "^8.2.0", | ||
"next": "^10.0.9", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.2.3" | ||
}, | ||
"engines": { | ||
"node": ">=10.0.0" | ||
}, | ||
"repository": "https://github.com/keystonejs/keystone/tree/master/examples-next/next-lite" | ||
} |
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,2 @@ | ||
// eslint-disable-next-line import/no-unresolved | ||
export { default, config } from '.keystone/graphql'; |
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,26 @@ | ||
import React from 'react'; | ||
import Link from 'next/link'; | ||
// eslint-disable-next-line import/no-unresolved | ||
import { lists } from '.keystone/api'; | ||
|
||
export default function HomePage({ posts }) { | ||
return ( | ||
<div> | ||
<h1>Welcome to my blog</h1> | ||
<ul> | ||
{posts.map((post, i) => ( | ||
<li key={i}> | ||
<Link href={`/post/${post.slug}`}> | ||
<a>{post.title}</a> | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
|
||
export async function getStaticProps() { | ||
const posts = await lists.Post.findMany({ resolveFields: 'slug title' }); | ||
return { props: { posts } }; | ||
} |
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,33 @@ | ||
import React from 'react'; | ||
|
||
// eslint-disable-next-line import/no-unresolved | ||
import { lists } from '.keystone/api'; | ||
|
||
export default function PostPage({ post }) { | ||
return ( | ||
<div> | ||
<h1>{post.title}</h1> | ||
<div>{post.content}</div> | ||
</div> | ||
); | ||
} | ||
|
||
export async function getStaticPaths() { | ||
const posts = await lists.Post.findMany({ | ||
resolveFields: 'slug', | ||
}); | ||
|
||
const paths = posts.map(post => post.slug).map(slug => `/post/${slug}`); | ||
return { | ||
paths, | ||
fallback: false, | ||
}; | ||
} | ||
|
||
export async function getStaticProps({ params: { slug } }) { | ||
const [post] = await lists.Post.findMany({ | ||
where: { slug: slug }, | ||
resolveFields: 'title content', | ||
}); | ||
return { props: { post } }; | ||
} |
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,10 @@ | ||
import { list } from '@keystone-next/keystone/schema'; | ||
import { text } from '@keystone-next/fields'; | ||
|
||
export const Post = list({ | ||
fields: { | ||
title: text({ isRequired: true }), | ||
slug: text(), | ||
content: text(), | ||
}, | ||
}); |
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,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve" | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], | ||
"exclude": ["node_modules"] | ||
} |
4 changes: 4 additions & 0 deletions
4
packages-next/keystone/___internal-do-not-use-will-break-in-patch/next-graphql/package.json
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,4 @@ | ||
{ | ||
"main": "dist/keystone.cjs.js", | ||
"module": "dist/keystone.esm.js" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages-next/keystone/___internal-do-not-use-will-break-in-patch/node-api/package.json
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,4 @@ | ||
{ | ||
"main": "dist/keystone.cjs.js", | ||
"module": "dist/keystone.esm.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"main": "dist/keystone.cjs.js", | ||
"module": "dist/keystone.esm.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
22 changes: 22 additions & 0 deletions
22
packages-next/keystone/src/___internal-do-not-use-will-break-in-patch/next-graphql.ts
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,22 @@ | ||
import { KeystoneConfig } from '@keystone-next/types'; | ||
import { initConfig } from '../lib/initConfig'; | ||
import { createSystem } from '../lib/createSystem'; | ||
import { createApolloServerMicro } from '../lib/createApolloServer'; | ||
|
||
export function nextGraphQLAPIRoute(keystoneConfig: KeystoneConfig, prismaClient: any) { | ||
const initializedKeystoneConfig = initConfig(keystoneConfig); | ||
const { graphQLSchema, keystone, createContext } = createSystem( | ||
initializedKeystoneConfig, | ||
prismaClient | ||
); | ||
|
||
const apolloServer = createApolloServerMicro({ | ||
graphQLSchema, | ||
createContext, | ||
sessionStrategy: initializedKeystoneConfig.session?.(), | ||
apolloConfig: initializedKeystoneConfig.graphql?.apolloConfig, | ||
connectionPromise: keystone.connect(), | ||
}); | ||
|
||
return apolloServer.createHandler({ path: '/api/graphql' }); | ||
} |
9 changes: 9 additions & 0 deletions
9
packages-next/keystone/src/___internal-do-not-use-will-break-in-patch/node-api.ts
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,9 @@ | ||
import { KeystoneConfig } from '@keystone-next/types'; | ||
import { createSystem } from '../lib/createSystem'; | ||
import { initConfig } from '../lib/initConfig'; | ||
|
||
export function createListsAPI(config: KeystoneConfig, prismaClient: any) { | ||
const { createContext, keystone } = createSystem(initConfig(config), prismaClient); | ||
keystone.connect(); | ||
return createContext().sudo().lists; | ||
} |
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,55 @@ | ||
import execa from 'execa'; | ||
// @ts-ignore | ||
import withPreconstruct from '@preconstruct/next'; | ||
|
||
let hasAlreadyStarted = false; | ||
|
||
export const withKeystone = (internalConfig: any = {}) => ( | ||
phase: | ||
| 'phase-export' | ||
| 'phase-production-build' | ||
| 'phase-production-server' | ||
| 'phase-development-server', | ||
thing: any | ||
) => { | ||
if (phase === 'phase-production-build') { | ||
execa.sync('node', [require.resolve('@keystone-next/keystone/bin/cli.js'), 'postinstall'], { | ||
stdio: 'inherit', | ||
}); | ||
} | ||
if (phase === 'phase-development-server' && !hasAlreadyStarted) { | ||
hasAlreadyStarted = true; | ||
|
||
const cliPath = require.resolve('@keystone-next/keystone/bin/cli.js'); | ||
|
||
execa.sync('node', [cliPath, 'postinstall', '--fix'], { | ||
stdio: 'inherit', | ||
}); | ||
// for some reason things blow up with EADDRINUSE if the dev call happens synchronously here | ||
// so we wait a sec and then do it | ||
setTimeout(() => { | ||
execa('node', [cliPath], { | ||
stdio: 'inherit', | ||
env: { ...process.env, PORT: process.env.PORT || '8000' }, | ||
}); | ||
}, 100); | ||
} | ||
let internalConfigObj = | ||
typeof internalConfig === 'function' ? internalConfig(phase, thing) : internalConfig; | ||
|
||
let originalWebpack = internalConfigObj.webpack; | ||
internalConfigObj.webpack = (webpackConfig: any, options: any) => { | ||
if (options.isServer) { | ||
webpackConfig.externals = [ | ||
...webpackConfig.externals, | ||
'@keystone-next/keystone/___internal-do-not-use-will-break-in-patch/api', | ||
'@keystone-next/keystone/___internal-do-not-use-will-break-in-patch/next-graphql', | ||
'@keystone-next/keystone/next', | ||
'@keystone-next/keystone', | ||
'.prisma/client', | ||
]; | ||
} | ||
return originalWebpack ? originalWebpack(webpackConfig, options) : webpackConfig; | ||
}; | ||
return withPreconstruct(internalConfigObj); | ||
}; |
Oops, something went wrong.
1886b43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: