-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraphql.js
52 lines (44 loc) · 1009 Bytes
/
graphql.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const { ApolloServer, gql } = require("./apollo-server-lambda/dist");
const files = [
{ id: 1, name: "file1.txt" },
{ id: 2, name: "file2.zip" },
{ id: 3, name: "file3.doc" }
];
const typeDefs = gql`
# scalar for file Upload
scalar Upload
type File {
id: Int!
name: String
}
type Query {
files: [File]
}
type Mutation {
uploadFiles(files: [Upload!]!): Boolean
}
`;
const resolvers = {
Query: {
files: () => files
},
Mutation: {
uploadFiles: async (parent, { files }) => {
console.log('files', files);
const { createReadStream, filename, mimetype, encoding } = await files[0];
console.log(filename);
console.log(createReadStream());
//TODO: Stream file contents into cloud storage such as s3
return true;
}
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
formatError: error => {
console.log(error);
return new Error(error.message);
}
});
exports.handler = server.createHandler();