Created
February 13, 2020 16:41
-
-
Save stemmlerjs/fb4288de76449ef221c6ae024112d491 to your computer and use it in GitHub Desktop.
Another Apollo Server but with uploads enabled
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
| import { ApolloServer, gql } from 'apollo-server' | |
| const server = new ApolloServer({ | |
| typeDefs: gql` | |
| type Query { | |
| hello: String! | |
| } | |
| type UploadedFileResponse { | |
| filename: String! | |
| mimetype: String! | |
| encoding: String! | |
| url: String! | |
| } | |
| type Mutation { | |
| singleUpload(file: Upload!): UploadedFileResponse! | |
| } | |
| `, | |
| resolvers: { | |
| Query: { | |
| hello: () => "Hey!" | |
| }, | |
| Mutation: { | |
| singleUpload: async (parent, { file }) => { | |
| const { stream, filename, mimetype, encoding } = await file; | |
| // Do work 💪 | |
| return { filename, mimetype, encoding, url: '' } | |
| } | |
| } | |
| } | |
| }); | |
| server.listen().then(({ url }) => { | |
| console.log(`🚀 Server ready at ${url}`); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment