Revisions for untitled paste

View the changes made to this paste.

unlisted ⁨1⁩ ⁨file⁩ 2021-06-19 14:51:36 UTC

pastefile1

@@ -0,0 +1,36 @@

+const { graphqlHTTP } = require('express-graphql');
+const { buildSchema } = require('graphql');
+const { createServer } = require('./api/servers');
+const { GraphQLUpload, graphqlUploadExpress } = require('graphql-upload');
+
+const schema = buildSchema(`
+    scalar Upload
+    type Server {
+        id: ID!,
+        // stuff...
+    }
+    input ServerInput {
+        bannerFile: Upload,
+        name: String!,
+        address: String!,
+        description: String!
+    }
+    type Mutation {
+        createServer(input: ServerInput!): Server
+    }
+`);
+
+// The root provides a resolver function for each API endpoint
+const root = {
+    createServer,
+    Upload: GraphQLUpload
+};
+
+module.exports = function(app) {
+    app.use('/api', graphqlUploadExpress({ maxFileSize: 1000000, maxFiles: 1 }), graphqlHTTP({
+        schema: schema,
+        rootValue: root,
+        graphiql: true,
+        customFormatErrorFn: err => ({ message: err.message })
+    }));
+};
\ No newline at end of file