-
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
32 changed files
with
343 additions
and
176 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,9 @@ | ||
--- | ||
'@keystone-next/keystone': major | ||
--- | ||
|
||
Replaced `deploy`, `reset` and `generate` commands with `keystone-next prisma`. You can use these commands as replacements for the old commands: | ||
|
||
- `keystone-next deploy` -> `keystone-next prisma migrate deploy` | ||
- `keystone-next reset` -> `keystone-next prisma migrate reset` | ||
- `keystone-next generate` -> `keystone-next prisma migrate dev` |
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': major | ||
'@keystone-next/types': major | ||
--- | ||
|
||
Removed the `none` case in `MigrationAction` and require that the PrismaClient is passed to be able to connect to the database for the `none-skip-client-generation` case. |
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': major | ||
--- | ||
|
||
Updated `keystone-next build` command to validate that the GraphQL and Prisma schemas are up to date. |
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/adapter-prisma-legacy': minor | ||
--- | ||
|
||
Added `devMigrations` and `runPrototypeMigrations` exports. |
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': major | ||
--- | ||
|
||
Moved generated `schema.prisma` to the root of the project directory. Note that this also moves the location of migrations from `.keystone/prisma/migrations` to `migrations` at the root of the project. |
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': major | ||
'@keystone-next/test-utils-legacy': patch | ||
--- | ||
|
||
Removed `dotKeystonePath` argument from `createSystem` |
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/admin-ui': major | ||
--- | ||
|
||
Updated Next API route template to use `createSystem` without the `dotKeystonePath` argument and import from the new Prisma Client location. |
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 `keystone-next postinstall` command which verifies that the Prisma and GraphQL schemas are up to date with a `--fix` flag to automatically update them without a prompt. |
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': major | ||
--- | ||
|
||
Moved generated GraphQL schema to `schema.graphql` to the root of the project. We recommend that you commit this file to your repo. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import path from 'path'; | ||
import { printSchema, GraphQLSchema } from 'graphql'; | ||
import * as fs from 'fs-extra'; | ||
import type { BaseKeystone } from '@keystone-next/types'; | ||
import { getGenerator } from '@prisma/sdk'; | ||
import { confirmPrompt } from './prompts'; | ||
import { printGeneratedTypes } from './schema-type-printer'; | ||
|
||
export function getSchemaPaths(cwd: string) { | ||
return { | ||
prisma: path.join(cwd, 'schema.prisma'), | ||
graphql: path.join(cwd, 'schema.graphql'), | ||
}; | ||
} | ||
|
||
type CommittedArtifacts = { | ||
graphql: string; | ||
prisma: string; | ||
}; | ||
|
||
export async function getCommittedArtifacts( | ||
graphQLSchema: GraphQLSchema, | ||
keystone: BaseKeystone | ||
): Promise<CommittedArtifacts> { | ||
return { | ||
graphql: printSchema(graphQLSchema), | ||
prisma: await keystone.adapter._generatePrismaSchema({ | ||
rels: keystone._consolidateRelationships(), | ||
clientDir: 'node_modules/.prisma/client', | ||
}), | ||
}; | ||
} | ||
|
||
async function readFileButReturnNothingIfDoesNotExist(filename: string) { | ||
try { | ||
return await fs.readFile(filename, 'utf8'); | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return; | ||
} | ||
throw err; | ||
} | ||
} | ||
|
||
export async function validateCommittedArtifacts( | ||
graphQLSchema: GraphQLSchema, | ||
keystone: BaseKeystone, | ||
cwd: string | ||
) { | ||
const artifacts = await getCommittedArtifacts(graphQLSchema, keystone); | ||
const schemaPaths = getSchemaPaths(cwd); | ||
const [writtenGraphQLSchema, writtenPrismaSchema] = await Promise.all([ | ||
readFileButReturnNothingIfDoesNotExist(schemaPaths.graphql), | ||
readFileButReturnNothingIfDoesNotExist(schemaPaths.prisma), | ||
]); | ||
const outOfDateSchemas = (() => { | ||
if (writtenGraphQLSchema !== artifacts.graphql && writtenPrismaSchema !== artifacts.prisma) { | ||
return 'both'; | ||
} | ||
if (writtenGraphQLSchema !== artifacts.graphql) { | ||
return 'graphql'; | ||
} | ||
if (writtenPrismaSchema !== artifacts.prisma) { | ||
return 'prisma'; | ||
} | ||
})(); | ||
if (outOfDateSchemas) { | ||
const message = { | ||
both: 'Your Prisma and GraphQL schemas are not up to date', | ||
graphql: 'Your GraphQL schema is not up to date', | ||
prisma: 'Your GraphQL schema is not up to date', | ||
}[outOfDateSchemas]; | ||
console.log(message); | ||
const term = { | ||
both: 'Prisma and GraphQL schemas', | ||
prisma: 'Prisma schema', | ||
graphql: 'GraphQL schema', | ||
}[outOfDateSchemas]; | ||
if (process.stdout.isTTY && (await confirmPrompt(`Would you like to update your ${term}?`))) { | ||
await writeCommittedArtifacts(artifacts, cwd); | ||
} else { | ||
console.log(`Please run keystone-next postinstall --fix to update your ${term}`); | ||
process.exit(1); | ||
} | ||
} | ||
} | ||
|
||
export async function writeCommittedArtifacts(artifacts: CommittedArtifacts, cwd: string) { | ||
const schemaPaths = getSchemaPaths(cwd); | ||
await Promise.all([ | ||
fs.writeFile(schemaPaths.graphql, artifacts.graphql), | ||
fs.writeFile(schemaPaths.prisma, artifacts.prisma), | ||
]); | ||
} | ||
|
||
export async function generateCommittedArtifacts( | ||
graphQLSchema: GraphQLSchema, | ||
keystone: BaseKeystone, | ||
cwd: string | ||
) { | ||
const artifacts = await getCommittedArtifacts(graphQLSchema, keystone); | ||
await writeCommittedArtifacts(artifacts, cwd); | ||
return artifacts; | ||
} | ||
|
||
export async function generateNodeModulesArtifacts( | ||
graphQLSchema: GraphQLSchema, | ||
keystone: BaseKeystone, | ||
cwd: string | ||
) { | ||
const printedSchema = printSchema(graphQLSchema); | ||
|
||
await Promise.all([ | ||
generatePrismaClient(cwd), | ||
fs.outputFile( | ||
path.join(cwd, 'node_modules/.keystone/types.d.ts'), | ||
printGeneratedTypes(printedSchema, keystone, graphQLSchema) | ||
), | ||
fs.outputFile(path.join(cwd, 'node_modules/.keystone/types.js'), ''), | ||
]); | ||
} | ||
|
||
async function generatePrismaClient(cwd: string) { | ||
const generator = await getGenerator({ schemaPath: getSchemaPaths(cwd).prisma }); | ||
await generator.generate(); | ||
generator.stop(); | ||
} | ||
|
||
export function requirePrismaClient(cwd: string) { | ||
return require(path.join(cwd, 'node_modules/.prisma/client')).PrismaClient; | ||
} |
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,17 @@ | ||
import prompts from 'prompts'; | ||
|
||
// prompts is badly typed so we have some more specific typed APIs | ||
// prompts also returns an undefined value on SIGINT which we really just want to exit on | ||
|
||
export async function confirmPrompt(message: string): Promise<boolean> { | ||
const { value } = await prompts({ | ||
name: 'value', | ||
type: 'confirm', | ||
message, | ||
initial: true, | ||
}); | ||
if (value === undefined) { | ||
process.exit(1); | ||
} | ||
return value; | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
c28e765
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: