Skip to content

Commit

Permalink
Added async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce Ingalls committed Oct 4, 2020
1 parent 03cd2fe commit 42f4aae
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
node_modules
build
coverage
.vscode
.DS_STORE
.env
tmp
.idea/
.vscode
build
coverage
node_modules
tmp
2 changes: 1 addition & 1 deletion build/.adonisrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
".env",
".adonisrc.json"
],
"lastCompiledAt": "2020-10-02T00:37:05.260Z"
"lastCompiledAt": "2020-10-04T19:46:24.661Z"
}
14 changes: 7 additions & 7 deletions build/start/routes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/start/routes.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions start/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,13 @@
import Route from '@ioc:Adonis/Core/Route'

Route.get('/', async () => {
return { hello: 'world' }
return 'Did you mean to open /graphiql'
})

const { graphiqlAdonis, graphqlAdonis } = require('apollo-server-adonis')

const { makeExecutableSchema } = require('graphql-tools')

// database without async/await in router is too slow
// move this code into a controller
import Database from '@ioc:Adonis/Lucid/Database'
let careers = Database.query().from('careers')

// GraphQL schema in string form
const typeDefs = `
type Career {
Expand All @@ -49,18 +44,22 @@ const typeDefs = `
`

import Career from 'App/Models/Career'
// move this code into a controller
import Database from '@ioc:Adonis/Lucid/Database'

const resolvers = {
Query: {
careers: () => careers,
career: () => careers.paginate(1, 1),
careers: async () => await Database.query().from('careers'),
career: async () => await Database.query().from('careers').limit(1),
},
Mutation: {
createCareer: (root, args) => { //(root, args, context, info)
createCareer: async (root, args) => { //(root, args, context, info)
void(root) // syntax sugar to lint unused param
const career = new Career()
career.email = args.email.toString()
career.description = args.description.toString()
career.save()
const result = await career.save()
return result.toString()
},
},
}
Expand Down

0 comments on commit 42f4aae

Please sign in to comment.