Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
mavilein committed Oct 9, 2018
2 parents 5a81e21 + 498ff69 commit 287dabd
Show file tree
Hide file tree
Showing 122 changed files with 5,995 additions and 2,830 deletions.
2 changes: 2 additions & 0 deletions cli/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ $ cd ../prisma-db-introspection
$ yarn install && yarn build
$ cd ../prisma-cli-core
$ yarn install && yarn build
$ cd ../prisma-generate-schema
$ yarn install && yarn build
$ cd ../prisma-cli
$ yarn install && yarn build
$ node dist/index.js
Expand Down
2 changes: 1 addition & 1 deletion cli/packages/prisma-cli-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"opn": "^5.1.0",
"pause": "^0.1.0",
"portfinder": "^1.0.13",
"prisma-client-lib": "0.2.58",
"prisma-client-lib": "1.17.1",
"prisma-db-introspection": "0.0.7",
"prisma-generate-schema": "0.0.8",
"prisma-json-schema": "0.1.2",
Expand Down
66 changes: 51 additions & 15 deletions cli/packages/prisma-cli-core/src/commands/generate/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from 'prisma-client-lib'
import { spawnSync } from 'npm-run'
import generateCRUDSchemaString from 'prisma-generate-schema'
import { fetchAndPrintSchema } from '../deploy/printSchema'

export default class GenereateCommand extends Command {
static topic = 'generate'
Expand All @@ -22,6 +23,10 @@ export default class GenereateCommand extends Command {
description: 'Path to .env file to inject env vars',
char: 'e',
}),
['endpoint']: flags.boolean({
description: 'Use a specific endpoint for schema generation or pick endpoint from prisma.yml',
required: false
}),
}
async run() {
const envFile = this.flags['env-file']
Expand All @@ -34,19 +39,48 @@ export default class GenereateCommand extends Command {
this.definition.definition!.generate!.length > 0
) {
const before = Date.now()
this.out.action.start(`Generating schema`)

if (!this.definition.definition!.datamodel) {
await this.out.error(
`The property ${chalk.bold(
'datamodel',
)} is missing in your prisma.yml`,
let schemaString;
if (this.flags.endpoint) {
this.out.action.start(`Downloading schema`)
const serviceName = this.definition.service!
const stageName = this.definition.stage!
const token = this.definition.getToken(serviceName, stageName)
const cluster = this.definition.getCluster()
const workspace = this.definition.getWorkspace()
this.env.setActiveCluster(cluster!)
await this.client.initClusterClient(
cluster!,
serviceName,
stageName,
workspace,
)
schemaString = await fetchAndPrintSchema(
this.client,
serviceName,
stageName!,
token,
workspace!,
)
} else {
this.out.action.start(`Generating schema`)
if (!this.definition.definition!.datamodel) {
await this.out.error(
`The property ${chalk.bold(
'datamodel',
)} is missing in your prisma.yml`,
)
}
schemaString = generateCRUDSchemaString(
this.definition.typesString!,
)
}

const schemaString = generateCRUDSchemaString(
this.definition.typesString!,
)
if (!schemaString) {
await this.out.error(
chalk.red(`Failed to download/generate the schema`),
)
}

this.out.action.stop(prettyTime(Date.now() - before))

Expand Down Expand Up @@ -206,15 +240,17 @@ export default class GenereateCommand extends Command {
}

replaceEnv(str) {
const regex = /\${env:(.*?)}/
const match = regex.exec(str)
const regex = /\${env:(.*?)}/;
const match = regex.exec(str);
// tslint:disable-next-line:prefer-conditional-expression
if (match) {
return `\`${str.slice(0, match.index)}$\{process.env['${
match[1]
}']}${str.slice(match[0].length + match.index)}\``
return this.replaceEnv(
`${str.slice(0, match.index)}$\{process.env['${match[1]}']}${str.slice(
match[0].length + match.index
)}`
);
} else {
return `'${str}'`
return `\`${str}\``;
}
}
}
35 changes: 18 additions & 17 deletions cli/packages/prisma-cli-core/src/utils/EndpointDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,23 +642,22 @@ export class EndpointDialog {
}

private async askForDemoCluster(): Promise<Cluster> {
const clusters = this.getCloudClusters().slice(0, 2)
const eu1Cluster = clusters.find(c => c.name === 'prisma-eu1')!
const us1Cluster = clusters.find(c => c.name === 'prisma-us1')!
const eu1Ping = await getPing('EU_WEST_1')
const us1Ping = await getPing('US_WEST_2')
const eu1Name = this.getClusterName(eu1Cluster)
const us1Name = this.getClusterName(us1Cluster)
const eu1Choice = [
eu1Name,
`Hosted on AWS in eu-west-1 using MySQL [${eu1Ping.toFixed()}ms latency]`,
]
const us1Choice = [
us1Name,
`Hosted on AWS in us-west-2 using MySQL [${us1Ping.toFixed()}ms latency]`,
]
const rawChoices =
eu1Ping < us1Ping ? [eu1Choice, us1Choice] : [us1Choice, eu1Choice]
const clusters = this.getCloudClusters().filter(
c => c.name === 'prisma-eu1' || c.name === 'prisma-us1',
)

const rawChoices = clusters.map(c => {
const clusterName = this.getClusterName(c)
const clusterRegion = c.name === 'prisma-eu1' ? `eu-west-1` : `us-west-2`
const pingTime =
c.name === 'prisma-eu1' ? eu1Ping.toFixed() : us1Ping.toFixed()
return [
clusterName,
`Hosted on AWS in ${clusterRegion} using MySQL [${pingTime}ms latency]`,
]
})
const choices = this.convertChoices(rawChoices)

const { cluster } = await this.out.prompt({
Expand All @@ -667,8 +666,10 @@ export class EndpointDialog {
message: `Choose the region of your demo server`,
choices,
})

return eu1Name === cluster ? eu1Cluster : us1Cluster
return clusters.find(c => {
const clusterName = this.getClusterName(c)
return clusterName === cluster
})!
}

private getClusterDescription(c: Cluster) {
Expand Down
2 changes: 1 addition & 1 deletion cli/packages/prisma-cli-engine/src/StatusChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class StatusChecker {
globalBin,
hashDate,
})
const secret = 'Shaenuteebaiweivoh4Shai2a'
const secret = 'ouZaquauXeiPh3xeiNaogh5na'

const hash = crypto
.createHmac('sha256', secret)
Expand Down
81 changes: 41 additions & 40 deletions cli/packages/prisma-db-introspection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ The Prisma GraphQL API provides powerful abstractions and building blocks to dev
<img align="right" width="400" src="https://imgur.com/EsopgE3.gif" />
-->

* [Quickstart](#quickstart)
* [Examples](#examples)
* [Architecture](#architecture)
* [Supported Databases](#supported-databases)
* [GraphQL API](#graphql-api)
* [Community](#community)
* [Contributing](#contributing)
- [Quickstart](#quickstart)
- [Examples](#examples)
- [Architecture](#architecture)
- [Supported Databases](#supported-databases)
- [GraphQL API](#graphql-api)
- [Community](#community)
- [Contributing](#contributing)

## Quickstart

Expand Down Expand Up @@ -92,13 +92,13 @@ Use the endpoint from the previous step in your frontend (or backend) applicatio

## Examples

* [demo-application](https://github.com/graphcool/graphql-server-example)
* [auth](examples/auth)
* [file-handling-s3](examples/file-handling-s3)
* [github-auth](examples/github-auth)
* [permissions](examples/permissions)
* [resolver-forwarding](examples/resolver-forwarding)
* [subscriptions](examples/subscriptions)
- [demo-application](https://github.com/graphcool/graphql-server-example)
- [auth](examples/auth)
- [file-handling-s3](examples/file-handling-s3)
- [github-auth](examples/github-auth)
- [permissions](examples/permissions)
- [resolver-forwarding](examples/resolver-forwarding)
- [subscriptions](examples/subscriptions)

## Architecture

Expand All @@ -110,45 +110,46 @@ Prisma is a secure API layer that sits in front of your database. Acting as a pr

Prisma can be used for MySQL Databases out of the box. More database connectors will follow

* [PostgreSQL Connector](https://github.com/graphcool/prisma/issues/1641)
* [MS SQL Connector](https://github.com/graphcool/prisma/issues/1642)
* [MongoDB Connector](https://github.com/graphcool/prisma/issues/1643)
* [Oracle Connector](https://github.com/graphcool/prisma/issues/1644)
* [ArangoDB Connector](https://github.com/graphcool/prisma/issues/1645)
* [Neo4j Connector](https://github.com/graphcool/prisma/issues/1646)
* [Druid Connector](https://github.com/graphcool/prisma/issues/1647)
* [Dgraph Connector](https://github.com/graphcool/prisma/issues/1648)
* [DynamoDB Connector](https://github.com/graphcool/prisma/issues/1655)
* [Elastic Search Connector](https://github.com/graphcool/prisma/issues/1665)
* [Cloud Firestore Connector](https://github.com/graphcool/prisma/issues/1660)
* [CockroachDB Connector](https://github.com/graphcool/prisma/issues/1705)
* [Cassandra Connector](https://github.com/graphcool/prisma/issues/1750)
* [Redis Connector](https://github.com/graphcool/prisma/issues/1722)
* [AWS Neptune Connector](https://github.com/graphcool/prisma/issues/1752)
* [CosmosDB Connector](https://github.com/graphcool/prisma/issues/1663)
* [Influx Connector](https://github.com/graphcool/prisma/issues/1857)
- [PostgreSQL Connector](https://github.com/graphcool/prisma/issues/1641)
- [MS SQL Connector](https://github.com/graphcool/prisma/issues/1642)
- [MongoDB Connector](https://github.com/graphcool/prisma/issues/1643)
- [Oracle Connector](https://github.com/graphcool/prisma/issues/1644)
- [ArangoDB Connector](https://github.com/graphcool/prisma/issues/1645)
- [Neo4j Connector](https://github.com/graphcool/prisma/issues/1646)
- [Druid Connector](https://github.com/graphcool/prisma/issues/1647)
- [Dgraph Connector](https://github.com/graphcool/prisma/issues/1648)
- [DynamoDB Connector](https://github.com/graphcool/prisma/issues/1655)
- [Elastic Search Connector](https://github.com/graphcool/prisma/issues/1665)
- [Cloud Firestore Connector](https://github.com/graphcool/prisma/issues/1660)
- [CockroachDB Connector](https://github.com/graphcool/prisma/issues/1705)
- [Cassandra Connector](https://github.com/graphcool/prisma/issues/1750)
- [Redis Connector](https://github.com/graphcool/prisma/issues/1722)
- [AWS Neptune Connector](https://github.com/graphcool/prisma/issues/1752)
- [CosmosDB Connector](https://github.com/graphcool/prisma/issues/1663)
- [Influx Connector](https://github.com/graphcool/prisma/issues/1857)

Join the discussion or contribute to influence which we'll work on next!

## GraphQL API

The most important component in Prisma is the GraphQL API:

* Query, mutate & stream data via GraphQL CRUD API
* Define and evolve your data model using GraphQL SDL
- Query, mutate & stream data via GraphQL CRUD API
- Define and evolve your data model using GraphQL SDL

Try the online demo: [open GraphQL Playground](https://www.prismagraphql.com/features)

## Community

Prisma has a community of thousands of amazing developers and contributors. Welcome, please join us! 👋
Prisma has a community of thousands of amazing developers and contributors.
Welcome, please join us! 👋

* [Forum](https://www.graph.cool/forum)
* [Slack](https://slack.graph.cool/)
* [Twitter](https://twitter.com/graphcool)
* [Facebook](https://www.facebook.com/GraphcoolHQ)
* [Meetup](https://www.meetup.com/graphql-berlin)
* [Email](hello@graph.cool)
- [Forum](https://www.graph.cool/forum)
- [Slack](https://slack.graph.cool/)
- [Twitter](https://twitter.com/graphcool)
- [Facebook](https://www.facebook.com/GraphcoolHQ)
- [Meetup](https://www.meetup.com/graphql-berlin)
- [Email](hello@graph.cool)

## Contributing

Expand Down
1 change: 0 additions & 1 deletion cli/packages/prisma-generate-schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ This section is intended for maintainers.
First, a datamodel is parsed using the [`DatamodelParser`](src/datamodel/parser.ts). Then, an OpenCRUD schema is created using the [`SchemaGenerator`](src/generator/schemaGenerator.ts).

The schema generator utilizes several other generators to generate the `mutation`, `query` and `subscription` objects and all corresponding types. A [`Generator`](src/generator/generator.ts) is usually responsible for a single type only but will access other generators to recursively build the schema. All generators which return object types implement lazy evaluation and caching of generated types via their base class. The generators can be configured using dependency injection, if needed, to switch out the implementation for certain types in the schema. All default generators, one for each type that can occur in an OpenCRUD schema, can ge found in the [`DefaultGenerators`](src/generator/defaultGenerators.ts) class.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type Story {
id: ID! @unique
}

type UserSpace {
id: ID! @unique
stories: [Story!]! @relation(name: "StoriesByUserSpace", onDelete: SET_NULL)
}
Loading

0 comments on commit 287dabd

Please sign in to comment.