Skip to content

Instantly share code, notes, and snippets.

@stemmlerjs
Created February 13, 2020 16:41
Show Gist options
  • Select an option

  • Save stemmlerjs/fb4288de76449ef221c6ae024112d491 to your computer and use it in GitHub Desktop.

Select an option

Save stemmlerjs/fb4288de76449ef221c6ae024112d491 to your computer and use it in GitHub Desktop.
Another Apollo Server but with uploads enabled
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