This file contains hidden or 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
// src/index.ts | |
import { S3 } from 'aws-sdk' | |
// Creates S3 client | |
const s3client = new S3({ | |
accessKeyId: process.env.S3_KEY, | |
secretAccessKey: process.env.S3_SECRET, | |
params: { | |
Bucket: process.env.S3_BUCKET | |
} |
This file contains hidden or 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
// src/modules/fileApi.ts | |
import * as multiparty from 'multiparty' | |
let form = new multiparty.Form() | |
form.on('part', async function(part) { | |
if (part.name !== 'data') { | |
return | |
} |
This file contains hidden or 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
# database/datamodel/types.graphql | |
type File { | |
id: ID! @unique | |
name: String! | |
size: Int! | |
secret: String! @unique | |
contentType: String! | |
createdAt: DateTime! | |
updatedAt: DateTime! |
This file contains hidden or 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
# prisma.yml | |
# Name of our project | |
service: graphql-server-file-upload-example | |
# Creates a development cluster on your local Docker instance | |
stage: dev | |
cluster: local | |
# Paths to our datamodel files |
This file contains hidden or 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
# src/schema.graphql | |
# import ID, File from "./generated/database.graphql" | |
# Everything user can read | |
type Query { | |
file(id: ID!): File # Takes id property as an argument and returns a File | |
files: [File!]! # Returns every file stored | |
} |
This file contains hidden or 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
// src/index.ts | |
import { Prisma } from "./generated/prisma" | |
const DATABASE_SCHEMA_PATH = './database/schema.graphql' | |
new Prisma({ | |
endpoint: process.env.PRISMA_ENDPOINT, | |
secret: process.env.PRISMA_SECRET, | |
}) |
This file contains hidden or 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
// src/files.ts | |
const data = { | |
name, | |
size, | |
secret, | |
contentType, | |
url | |
} |
This file contains hidden or 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
// src/resolvers/Mutation/file.ts | |
export const file = { | |
renameFile: async (parent, {id, name}, ctx: Context, info) => { | |
return ctx.db.mutation.updateFile({ data: { name }, where: { id } }, info) | |
}, | |
deleteFile: async (parent, { id }, ctx: Context, info) => { | |
return await ctx.db.mutation.deleteFile({ where: { id } }, info) | |
} | |
} |
This file contains hidden or 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
# database/schema.graphql | |
type Mutation { | |
... | |
# takes two arguments(data and where) and returns a File | |
updateFile(data: FileUpdateInput!, where: FileWhereUniqueInput!): File | |
... | |
} | |
# Tells us which properties can be given to data |
This file contains hidden or 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
const authLink = new ApolloLink(async (operation, forward) => { | |
const token = await AsyncStorage.getItem('token') | |
operation.setContext(({ headers = {} }) => ({ | |
headers: { | |
...headers, | |
Authorization: token ? `Bearer ${token}` : null | |
} | |
})) |