-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathuploads.ts
More file actions
29 lines (25 loc) · 793 Bytes
/
uploads.ts
File metadata and controls
29 lines (25 loc) · 793 Bytes
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
import { g, InferResolvers, buildSchema } from './../src/index'
import { createYoga } from 'graphql-yoga'
import { createServer } from 'http'
const file = g.scalarType<File, never>('File')
const mutationType = g.type('Mutation', {
readTextFile: g.string()
.args({
file: g.ref(file),
})
.description('Greets a person')
})
const resolvers: InferResolvers<{ Mutation: typeof mutationType }, {}> = {
Mutation: {
readTextFile: async (parent, { file }, context, info) => {
const textContent = await file.text()
return textContent
}
}
}
const schema = buildSchema({ g, resolvers })
const yoga = createYoga({ schema })
const server = createServer(yoga)
server.listen(4000, () => {
console.info('Server is running on http://localhost:4000/graphql')
})