mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
refactored backend structure
This commit is contained in:
parent
04110866b9
commit
f78c54a3e8
@ -4,7 +4,7 @@ NEO4J_PASSWORD=letmein
|
||||
GRAPHQL_PORT=4000
|
||||
GRAPHQL_URI=http://localhost:4000
|
||||
CLIENT_URI=http://localhost:3000
|
||||
MOCK=false
|
||||
MOCKS=false
|
||||
|
||||
JWT_SECRET="b/&&7b78BF&fv/Vd"
|
||||
MAPBOX_TOKEN="pk.eyJ1IjoiaHVtYW4tY29ubmVjdGlvbiIsImEiOiJjajl0cnBubGoweTVlM3VwZ2lzNTNud3ZtIn0.KZ8KK9l70omjXbEkkbHGsQ"
|
||||
|
||||
26
backend/src/config/index.js
Normal file
26
backend/src/config/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const requiredConfigs = {
|
||||
MAPBOX_TOKEN: process.env.MAPBOX_TOKEN,
|
||||
JWT_SECRET: process.env.JWT_SECRET,
|
||||
PRIVATE_KEY_PASSPHRASE: process.env.PRIVATE_KEY_PASSPHRASE,
|
||||
}
|
||||
|
||||
const developmentConfigs = {
|
||||
DEBUG: process.env.NODE_ENV !== 'production' && process.env.DEBUG === 'true',
|
||||
MOCKS: process.env.MOCKS === 'true',
|
||||
}
|
||||
|
||||
// check required configs and throw error
|
||||
Object.entries(requiredConfigs).map(entry => {
|
||||
if (!entry[1]) {
|
||||
throw new Error(`ERROR: "${entry[0]}" env variable is missing.`)
|
||||
}
|
||||
})
|
||||
|
||||
export default {
|
||||
...requiredConfigs,
|
||||
...developmentConfigs,
|
||||
}
|
||||
@ -1,2 +0,0 @@
|
||||
export { default as typeDefs } from './types'
|
||||
export { default as resolvers } from './resolvers'
|
||||
24
backend/src/schema/index.js
Normal file
24
backend/src/schema/index.js
Normal file
@ -0,0 +1,24 @@
|
||||
import { makeAugmentedSchema } from 'neo4j-graphql-js'
|
||||
import CONFIG from './../config'
|
||||
import applyScalars from './../bootstrap/scalars'
|
||||
import applyDirectives from './../bootstrap/directives'
|
||||
import typeDefs from './types'
|
||||
import resolvers from './resolvers'
|
||||
|
||||
export default applyScalars(
|
||||
applyDirectives(
|
||||
makeAugmentedSchema({
|
||||
typeDefs,
|
||||
resolvers,
|
||||
config: {
|
||||
query: {
|
||||
exclude: ['Notfication', 'Statistics', 'LoggedInUser'],
|
||||
},
|
||||
mutation: {
|
||||
exclude: ['Notfication', 'Statistics', 'LoggedInUser'],
|
||||
},
|
||||
debug: CONFIG.DEBUG,
|
||||
},
|
||||
}),
|
||||
),
|
||||
)
|
||||
@ -1,4 +1,4 @@
|
||||
import encode from '../jwt/encode'
|
||||
import encode from '../../jwt/encode'
|
||||
import bcrypt from 'bcryptjs'
|
||||
import { AuthenticationError } from 'apollo-server'
|
||||
import { neo4jgraphql } from 'neo4j-graphql-js'
|
||||
@ -1,48 +1,19 @@
|
||||
import { GraphQLServer } from 'graphql-yoga'
|
||||
import { makeAugmentedSchema } from 'neo4j-graphql-js'
|
||||
import { typeDefs, resolvers } from './graphql-schema'
|
||||
import express from 'express'
|
||||
import dotenv from 'dotenv'
|
||||
import helmet from 'helmet'
|
||||
import { GraphQLServer } from 'graphql-yoga'
|
||||
import CONFIG from './config'
|
||||
import mocks from './mocks'
|
||||
import middleware from './middleware'
|
||||
import applyDirectives from './bootstrap/directives'
|
||||
import applyScalars from './bootstrap/scalars'
|
||||
import { getDriver } from './bootstrap/neo4j'
|
||||
import helmet from 'helmet'
|
||||
import decode from './jwt/decode'
|
||||
|
||||
dotenv.config()
|
||||
// check env and warn
|
||||
const requiredEnvVars = ['MAPBOX_TOKEN', 'JWT_SECRET', 'PRIVATE_KEY_PASSPHRASE']
|
||||
requiredEnvVars.forEach(env => {
|
||||
if (!process.env[env]) {
|
||||
throw new Error(`ERROR: "${env}" env variable is missing.`)
|
||||
}
|
||||
})
|
||||
import schema from './schema'
|
||||
|
||||
const driver = getDriver()
|
||||
const debug = process.env.NODE_ENV !== 'production' && process.env.DEBUG === 'true'
|
||||
|
||||
let schema = makeAugmentedSchema({
|
||||
typeDefs,
|
||||
resolvers,
|
||||
config: {
|
||||
query: {
|
||||
exclude: ['Notfication', 'Statistics', 'LoggedInUser'],
|
||||
},
|
||||
mutation: {
|
||||
exclude: ['Notfication', 'Statistics', 'LoggedInUser'],
|
||||
},
|
||||
debug: debug,
|
||||
},
|
||||
})
|
||||
schema = applyScalars(applyDirectives(schema))
|
||||
|
||||
const createServer = options => {
|
||||
const defaults = {
|
||||
context: async ({ request }) => {
|
||||
const authorizationHeader = request.headers.authorization || ''
|
||||
const user = await decode(driver, authorizationHeader)
|
||||
const user = await decode(driver, request.headers.authorization)
|
||||
return {
|
||||
driver,
|
||||
user,
|
||||
@ -52,11 +23,11 @@ const createServer = options => {
|
||||
},
|
||||
}
|
||||
},
|
||||
schema: schema,
|
||||
debug: debug,
|
||||
tracing: debug,
|
||||
schema,
|
||||
debug: CONFIG.DEBUG,
|
||||
tracing: CONFIG.DEBUG,
|
||||
middlewares: middleware(schema),
|
||||
mocks: process.env.MOCK === 'true' ? mocks : false,
|
||||
mocks: CONFIG.MOCKS ? mocks : false,
|
||||
}
|
||||
const server = new GraphQLServer(Object.assign({}, defaults, options))
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
data:
|
||||
GRAPHQL_PORT: "4000"
|
||||
GRAPHQL_URI: "http://nitro-backend.human-connection:4000"
|
||||
MOCK: "false"
|
||||
MOCKS: "false"
|
||||
NEO4J_URI: "bolt://nitro-neo4j.human-connection:7687"
|
||||
NEO4J_USER: "neo4j"
|
||||
NEO4J_AUTH: "none"
|
||||
|
||||
@ -19,7 +19,7 @@ services:
|
||||
- GRAPHQL_URI=http://localhost:4000
|
||||
- CLIENT_URI=http://localhost:3000
|
||||
- JWT_SECRET=b/&&7b78BF&fv/Vd
|
||||
- MOCK=false
|
||||
- MOCKS=false
|
||||
- MAPBOX_TOKEN=pk.eyJ1IjoiaHVtYW4tY29ubmVjdGlvbiIsImEiOiJjajl0cnBubGoweTVlM3VwZ2lzNTNud3ZtIn0.KZ8KK9l70omjXbEkkbHGsQ
|
||||
- PRIVATE_KEY_PASSPHRASE=a7dsf78sadg87ad87sfagsadg78
|
||||
- NEO4J_apoc_import_file_enabled=true
|
||||
|
||||
@ -32,7 +32,7 @@ services:
|
||||
- GRAPHQL_URI=http://localhost:4000
|
||||
- CLIENT_URI=http://localhost:3000
|
||||
- JWT_SECRET=b/&&7b78BF&fv/Vd
|
||||
- MOCK=false
|
||||
- MOCKS=false
|
||||
- MAPBOX_TOKEN=pk.eyJ1IjoiaHVtYW4tY29ubmVjdGlvbiIsImEiOiJjajl0cnBubGoweTVlM3VwZ2lzNTNud3ZtIn0.KZ8KK9l70omjXbEkkbHGsQ
|
||||
- PRIVATE_KEY_PASSPHRASE=a7dsf78sadg87ad87sfagsadg78
|
||||
neo4j:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user