Skip to content

Commit 539c946

Browse files
committed
Prisma
1 parent 9986f2b commit 539c946

11 files changed

+932
-693
lines changed

.env

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SERVER_ENDPOINT="http://localhost:5000"
2-
GRAPHCOOL_ENDPOINT="http://localhost:60000/graphql-server-file-upload-example/dev"
3-
GRAPHCOOL_SECRET="so-secret"
2+
PRISMA_ENDPOINT="http://localhost:4466/graphql-server-file-upload-example/dev"
3+
PRISMA_SECRET="so-secret"
44
S3_BUCKET=""
55
S3_KEY=""
6-
S3_SECRET=""
6+
S3_SECRET=""

.graphqlconfig.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ projects:
55
endpoints:
66
default: "${env:SERVER_ENDPOINT}"
77
database:
8-
schemaPath: "src/generated/database.graphql"
8+
schemaPath: "src/generated/database.graphql" # Where to put generated schema
99
extensions:
10-
graphcool: graphcool.yml
10+
prisma: database/prisma.yml # Prisma config file path
1111
binding:
12-
output: src/generated/graphcool.ts
13-
generator: graphcool-ts
12+
output: src/generated/prisma.ts # Where to put generated files
13+
generator: prisma-ts # Which binding generator should be used

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ This example illustrates the implementation of File API with GraphQL Server patt
44

55
## Getting Started
66

7-
### Initializing the Graphcool Database Service
7+
### Initializing Prisma Database Service
88
```sh
99
graphcool deploy # choose local cluster
10-
# copy API endpoint into the `GRAPHCOOL_ENPOINT` env var in .env
10+
# copy API endpoint into the `PRISMA_ENPOINT` env var in .env
1111
```
1212

1313
To get `GRAPHCOOL_SECRET` visit http://jwtbuilder.jamiekurtz.com and scroll to the bottom where you can hash your secret from `graphcool.yml` and get the hashed output. (`sssh` is used in the example.)
@@ -37,7 +37,7 @@ It's important to use the form parameter `data` as seen in the example below.
3737

3838
### Uploading workflow
3939

40-
Everytime you upload a file to Graphcool, a new `File` node is created that contains information about that file.
40+
Everytime you upload a file to Prisma, a new `File` node is created that contains information about that file.
4141

4242
* `id`: the [familiar system field](!alias-eiroozae8u#id-field)
4343
* `secret`: a unique, unguessable secret that allows access to the file

database/prisma.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
service: graphql-server-file-upload-example
2+
3+
stage: dev
4+
cluster: local
5+
6+
datamodel:
7+
- datamodel/types.graphql
8+
9+
secret: ${env:PRISMA_SECRET}

graphcool.yml

-10
This file was deleted.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "graphql-server-file-upload-example",
33
"version": "1.0.0",
4-
"license": "MIT",
54
"scripts": {
65
"start": "dotenv -- nodemon -x ts-node -e ts,graphql src/index.ts",
76
"debug": "dotenv -- nodemon -x 'ts-node --inspect' -e ts,graphql src/index.ts",
@@ -14,20 +13,21 @@
1413
"dependencies": {
1514
"aws-sdk": "^2.167.0",
1615
"express": "^4.16.2",
17-
"graphcool-binding": "^1.3.3",
1816
"graphql": "^0.12.0",
1917
"graphql-import": "^0.1.5",
2018
"graphql-yoga": "^1.1.4",
2119
"mime-types": "^2.1.17",
2220
"multiparty": "^4.1.3",
21+
"prisma-binding": "^1.3.8",
2322
"uuid": "^3.1.0"
2423
},
2524
"devDependencies": {
2625
"dotenv-cli": "^1.4.0",
2726
"graphql-cli": "^2.0.5",
28-
"graphql-cli-prepare": "1.4.6",
27+
"graphql-cli-prepare": "^1.4.11",
2928
"nodemon": "^1.12.5",
3029
"ts-node": "^3.3.0",
3130
"typescript": "^2.6.2"
32-
}
31+
},
32+
"license": "MIT"
3333
}

src/modules/fileAPI.ts src/files.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { v4 as uuid } from 'uuid'
33
import * as mime from 'mime-types'
44
import * as multiparty from 'multiparty'
55

6-
export default ({graphcool, s3}) => (req, res) => {
6+
export const files = ({graphcool, s3}) => (req, res) => {
77
let form = new multiparty.Form()
88

99
form.on('part', async function(part) {

src/generated/database.graphql

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# THIS FILE HAS BEEN AUTO-GENERATED BY THE "GRAPHCOOL DEPLOY"
1+
# THIS FILE HAS BEEN AUTO-GENERATED BY "PRISMA DEPLOY"
22
# DO NOT EDIT THIS FILE DIRECTLY
33

44
#
@@ -21,6 +21,10 @@ type File implements Node {
2121
# Other Types
2222
#
2323

24+
type AggregateFile {
25+
count: Int!
26+
}
27+
2428
type BatchPayload {
2529
count: Long!
2630
}
@@ -30,6 +34,7 @@ scalar DateTime
3034
type FileConnection {
3135
pageInfo: PageInfo!
3236
edges: [FileEdge]!
37+
aggregate: AggregateFile!
3338
}
3439

3540
input FileCreateInput {
@@ -214,7 +219,6 @@ type Mutation {
214219
upsertFile(where: FileWhereUniqueInput!, create: FileCreateInput!, update: FileUpdateInput!): File!
215220
updateManyFiles(data: FileUpdateInput!, where: FileWhereInput!): BatchPayload!
216221
deleteManyFiles(where: FileWhereInput!): BatchPayload!
217-
resetData: Boolean
218222
}
219223

220224
enum MutationType {

src/generated/graphcool.ts src/generated/prisma.ts

+46-39
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Graphcool as BaseGraphcool, BaseGraphcoolOptions } from 'graphcool-binding'
1+
import { Prisma as BasePrisma, BasePrismaOptions } from 'prisma-binding'
22
import { GraphQLResolveInfo } from 'graphql'
33

44
const typeDefs = `
5-
# THIS FILE HAS BEEN AUTO-GENERATED BY THE "GRAPHCOOL DEPLOY"
5+
# THIS FILE HAS BEEN AUTO-GENERATED BY "PRISMA DEPLOY"
66
# DO NOT EDIT THIS FILE DIRECTLY
77
88
#
@@ -25,6 +25,10 @@ type File implements Node {
2525
# Other Types
2626
#
2727
28+
type AggregateFile {
29+
count: Int!
30+
}
31+
2832
type BatchPayload {
2933
count: Long!
3034
}
@@ -34,6 +38,7 @@ scalar DateTime
3438
type FileConnection {
3539
pageInfo: PageInfo!
3640
edges: [FileEdge]!
41+
aggregate: AggregateFile!
3742
}
3843
3944
input FileCreateInput {
@@ -218,7 +223,6 @@ type Mutation {
218223
upsertFile(where: FileWhereUniqueInput!, create: FileCreateInput!, update: FileUpdateInput!): File!
219224
updateManyFiles(data: FileUpdateInput!, where: FileWhereInput!): BatchPayload!
220225
deleteManyFiles(where: FileWhereInput!): BatchPayload!
221-
resetData: Boolean
222226
}
223227
224228
enum MutationType {
@@ -408,17 +412,6 @@ export interface Node {
408412
id: ID_Output
409413
}
410414

411-
export interface PageInfo {
412-
hasNextPage: Boolean
413-
hasPreviousPage: Boolean
414-
startCursor?: String
415-
endCursor?: String
416-
}
417-
418-
export interface BatchPayload {
419-
count: Long
420-
}
421-
422415
export interface FilePreviousValues {
423416
id: ID_Output
424417
name: String
@@ -430,16 +423,15 @@ export interface FilePreviousValues {
430423
url: String
431424
}
432425

433-
export interface FileConnection {
434-
pageInfo: PageInfo
435-
edges: FileEdge[]
426+
export interface BatchPayload {
427+
count: Long
436428
}
437429

438-
export interface FileSubscriptionPayload {
439-
mutation: MutationType
440-
node?: File
441-
updatedFields?: String[]
442-
previousValues?: FilePreviousValues
430+
export interface PageInfo {
431+
hasNextPage: Boolean
432+
hasPreviousPage: Boolean
433+
startCursor?: String
434+
endCursor?: String
443435
}
444436

445437
export interface File extends Node {
@@ -453,35 +445,52 @@ export interface File extends Node {
453445
url: String
454446
}
455447

448+
export interface AggregateFile {
449+
count: Int
450+
}
451+
456452
export interface FileEdge {
457453
node: File
458454
cursor: String
459455
}
460456

461-
/*
462-
The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
463-
*/
464-
export type String = string
457+
export interface FileSubscriptionPayload {
458+
mutation: MutationType
459+
node?: File
460+
updatedFields?: String[]
461+
previousValues?: FilePreviousValues
462+
}
463+
464+
export interface FileConnection {
465+
pageInfo: PageInfo
466+
edges: FileEdge[]
467+
aggregate: AggregateFile
468+
}
469+
470+
export type DateTime = string
465471

466472
/*
467-
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
473+
The `Boolean` scalar type represents `true` or `false`.
468474
*/
469-
export type Int = number
470-
471-
export type Long = string
475+
export type Boolean = boolean
472476

473477
/*
474478
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
475479
*/
476480
export type ID_Input = string | number
477481
export type ID_Output = string
478482

479-
export type DateTime = string
483+
/*
484+
The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
485+
*/
486+
export type String = string
480487

481488
/*
482-
The `Boolean` scalar type represents `true` or `false`.
489+
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
483490
*/
484-
export type Boolean = boolean
491+
export type Int = number
492+
493+
export type Long = string
485494

486495
export interface Schema {
487496
query: Query
@@ -503,16 +512,15 @@ export type Mutation = {
503512
upsertFile: (args: { where: FileWhereUniqueInput, create: FileCreateInput, update: FileUpdateInput }, info?: GraphQLResolveInfo | string) => Promise<File>
504513
updateManyFiles: (args: { data: FileUpdateInput, where: FileWhereInput }, info?: GraphQLResolveInfo | string) => Promise<BatchPayload>
505514
deleteManyFiles: (args: { where: FileWhereInput }, info?: GraphQLResolveInfo | string) => Promise<BatchPayload>
506-
resetData: (args: {}, info?: GraphQLResolveInfo | string) => Promise<Boolean | null>
507515
}
508516

509517
export type Subscription = {
510518
file: (args: { where?: FileSubscriptionWhereInput }, infoOrQuery?: GraphQLResolveInfo | string) => Promise<AsyncIterator<FileSubscriptionPayload>>
511519
}
512520

513-
export class Graphcool extends BaseGraphcool {
521+
export class Prisma extends BasePrisma {
514522

515-
constructor({ endpoint, secret, fragmentReplacements, debug }: BaseGraphcoolOptions) {
523+
constructor({ endpoint, secret, fragmentReplacements, debug }: BasePrismaOptions) {
516524
super({ typeDefs, endpoint, secret, fragmentReplacements, debug });
517525
}
518526

@@ -533,11 +541,10 @@ export class Graphcool extends BaseGraphcool {
533541
deleteFile: (args, info): Promise<File | null> => super.delegate('mutation', 'deleteFile', args, {}, info),
534542
upsertFile: (args, info): Promise<File> => super.delegate('mutation', 'upsertFile', args, {}, info),
535543
updateManyFiles: (args, info): Promise<BatchPayload> => super.delegate('mutation', 'updateManyFiles', args, {}, info),
536-
deleteManyFiles: (args, info): Promise<BatchPayload> => super.delegate('mutation', 'deleteManyFiles', args, {}, info),
537-
resetData: (args, info): Promise<Boolean | null> => super.delegate('mutation', 'resetData', args, {}, info)
544+
deleteManyFiles: (args, info): Promise<BatchPayload> => super.delegate('mutation', 'deleteManyFiles', args, {}, info)
538545
}
539546

540547
subscription: Subscription = {
541-
file: (args, infoOrQuery): Promise<AsyncIterator<FileSubscriptionPayload>> => super.delegateSubscription('file', args, infoOrQuery)
548+
file: (args, infoOrQuery): Promise<AsyncIterator<FileSubscriptionPayload>> => super.delegateSubscription('file', args, {}, infoOrQuery)
542549
}
543550
}

src/index.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Graphcool } from "./generated/graphcool"
2-
import { importSchema } from "graphql-import"
31
import { GraphQLServer } from "graphql-yoga"
2+
import { importSchema } from "graphql-import"
43
import { S3 } from 'aws-sdk'
4+
import { Prisma } from "./generated/prisma"
55
import { resolvers } from "./resolvers"
6-
import fileApi from './modules/fileApi'
6+
import { files } from './files'
77

88
// Config --------------------------------------------------------------------
99

@@ -27,20 +27,20 @@ const server = new GraphQLServer({
2727
resolvers,
2828
context: req => ({
2929
...req,
30-
db: new Graphcool({
31-
endpoint: process.env.GRAPHCOOL_ENDPOINT,
32-
secret: process.env.GRAPHCOOL_SECRET,
30+
db: new Prisma({
31+
endpoint: process.env.PRISMA_ENDPOINT,
32+
secret: process.env.PRISMA_SECRET,
3333
}),
3434
}),
3535
})
3636

3737
// Middleware ----------------------------------------------------------------
3838

39-
server.express.post('/upload', fileApi({
39+
server.express.post('/upload', files({
4040
s3: s3client,
41-
graphcool: new Graphcool({
42-
endpoint: process.env.GRAPHCOOL_ENDPOINT,
43-
secret: process.env.GRAPHCOOL_SECRET,
41+
graphcool: new Prisma({
42+
endpoint: process.env.PRISMA_ENDPOINT,
43+
secret: process.env.PRISMA_SECRET,
4444
}),
4545
}))
4646

0 commit comments

Comments
 (0)