Skip to content

Commit

Permalink
graphql api
Browse files Browse the repository at this point in the history
  • Loading branch information
kingRayhan committed May 18, 2019
1 parent 07eef45 commit 3a6d0b8
Show file tree
Hide file tree
Showing 42 changed files with 800 additions and 10,965 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions db-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require('fs')

const dir = fs.readdirSync(__dirname + '/database')

let npmScripts = ''

dir.forEach(file => {
if (file.split('.')[1] === 'bson') {
let name = file.split('.')[0]

npmScripts += `npm run import-${name} && `

console.log(
`"import-${name}":"mongorestore -d quran -c ${name} database/${file}",`
)
}
})

console.log(npmScripts)
24 changes: 24 additions & 0 deletions gql-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { GraphQLServer } = require('graphql-yoga')

require('dotenv').config()
require('./dbconnect')
const Ayah = require('./resolvers/Ayah')
const Query = require('./resolvers/Query')
const Word = require('./resolvers/Word')
const server = new GraphQLServer({
typeDefs: __dirname + '/schema.graphql',
resolvers: {
Query,
Ayah,
Word,
},
})

server.start(
{
port: 5000,
},
({ port }) => {
console.log('Server working at http://localhost:' + port)
}
)
16 changes: 9 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ require('./dbconnect')

app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.use(expressSession({
secret: process.env.SECRET,
resave: true,
saveUninitialized: true
}))
app.use(
expressSession({
secret: process.env.SECRET,
resave: true,
saveUninitialized: true,
})
)
app.use(cookieParser())

app.listen(process.env.PORT, () => {
console.log(`Server is running at http://localhost:${process.env.PORT}`);
console.log(`Server is running at http://localhost:${process.env.PORT}`)
})

app.use(express.static(__dirname + '/public'))

const quranRouter = require('./routes/quran')
const noteRouter = require('./routes/note')
app.use(quranRouter)
app.use('/note', noteRouter)
app.use('/note', noteRouter)
24 changes: 24 additions & 0 deletions models/Corpus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const mongoose = require('mongoose')

let suraScheema = mongoose.Schema({
ar1: String,
ar2: String,
ar3: String,
ar4: String,
ar5: String,
ayah: String,
count: String,
lemma: String,
pos1: String,
pos2: String,
pos3: String,
pos4: String,
pos5: String,
root_ar: String,
surah: String,
verb_type: String,
verf_form: String,
word: String,
})

module.exports = mongoose.model('Corpus', suraScheema)
10 changes: 10 additions & 0 deletions models/Translation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const mongoose = require('mongoose')

let suraScheema = mongoose.Schema({
ayah: String,
primary: String,
sura: String,
text: String,
})

module.exports = mongoose.model('Translation', suraScheema, 'tr_en_sahih')
12 changes: 12 additions & 0 deletions models/Word.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const mongoose = require('mongoose')

let suraScheema = mongoose.Schema({
ayah: String,
bn: String,
en: String,
in: String,
sura: String,
word: String,
})

module.exports = mongoose.model('Word', suraScheema)
5 changes: 4 additions & 1 deletion now.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{"version":2,"name":"quran","builds":[{"src":"**/*.js","use":"@now/node"}]}
{
"version": 1,
"name": "quran-graphql-api"
}
60 changes: 37 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
{
"name": "express-basic",
"version": "1.0.0",
"description": "hello world",
"main": "true",
"author": "anwarulislam",
"license": "MIT",
"scripts": {
"start": "nodemon index.js"
},
"dependencies": {
"bcryptjs": "^2.4.3",
"colors": "^1.3.3",
"cookie-parser": "^1.4.4",
"dotenv": "^8.0.0",
"express": "^4.16.4",
"express-graphql": "^0.8.0",
"express-session": "^1.16.1",
"express-validator": "^5.3.1",
"graphql": "^14.3.0",
"mongoose": "^5.5.7",
"mongoose-paginate-v2": "^1.2.1",
"nodemon": "^1.19.0"
}
"name": "quran-project-backend-api",
"version": "1.0.0",
"description": "quran-project-backend-api",
"main": "true",
"author": "anwarulislam",
"license": "MIT",
"scripts": {
"start": "nodemon index.js",
"import-ayah": "mongorestore -d quran -c ayah database/ayah.bson",
"import-bookmarks": "mongorestore -d quran -c bookmarks database/bookmarks.bson",
"import-corpus": "mongorestore -d quran -c corpus database/corpus.bson",
"import-footnotes_mhk": "mongorestore -d quran -c footnotes_mhk database/footnotes_mhk.bson",
"import-notes": "mongorestore -d quran -c notes database/notes.bson",
"import-quran_index": "mongorestore -d quran -c quran_index database/quran_index.bson",
"import-surah": "mongorestore -d quran -c surah database/surah.bson",
"import-tafsir_kathir": "mongorestore -d quran -c tafsir_kathir database/tafsir_kathir.bson",
"import-tafsir_kathir_segment": "mongorestore -d quran -c tafsir_kathir_segment database/tafsir_kathir_segment.bson",
"import-tr_en_sahih": "mongorestore -d quran -c tr_en_sahih database/tr_en_sahih.bson",
"import-verb_with_forms": "mongorestore -d quran -c verb_with_forms database/verb_with_forms.bson",
"import-words": "mongorestore -d quran -c words database/words.bson",
"seed-data": "npm run import-ayah && npm run import-bookmarks && npm run import-corpus && npm run import-footnotes_mhk && npm run import-notes && npm run import-quran_index && npm run import-surah && npm run import-tafsir_kathir && npm run import-tafsir_kathir_segment && npm run import-tr_en_sahih && npm run import-verb_with_forms && npm run import-words"
},
"dependencies": {
"bcryptjs": "^2.4.3",
"colors": "^1.3.3",
"cookie-parser": "^1.4.4",
"dotenv": "^8.0.0",
"express": "^4.16.4",
"express-graphql": "^0.8.0",
"express-session": "^1.16.1",
"express-validator": "^5.3.1",
"graphql": "^14.3.0",
"graphql-yoga": "^1.17.4",
"mongoose": "^5.5.7",
"mongoose-paginate-v2": "^1.2.1",
"nodemon": "^1.19.0"
}
}
Loading

1 comment on commit 3a6d0b8

@vercel
Copy link

@vercel vercel bot commented on 3a6d0b8 May 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment failed with the following error:

You tried to create a Now 1.0 deployment. Please use Now 2.0 instead: https://zeit.co/upgrade

Please sign in to comment.