mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
added softdelete and image fix middleware
This commit is contained in:
parent
71b7623601
commit
2105b4d4aa
34
src/index.js
34
src/index.js
@ -5,7 +5,9 @@ import { augmentSchema } from 'neo4j-graphql-js'
|
|||||||
import { typeDefs, resolvers } from './graphql-schema'
|
import { typeDefs, resolvers } from './graphql-schema'
|
||||||
import { v1 as neo4j } from 'neo4j-driver'
|
import { v1 as neo4j } from 'neo4j-driver'
|
||||||
import passwordMiddleware from './middleware/passwordMiddleware'
|
import passwordMiddleware from './middleware/passwordMiddleware'
|
||||||
|
import softDeleteMiddleware from './middleware/softDeleteMiddleware'
|
||||||
import sluggifyMiddleware from './middleware/sluggifyMiddleware'
|
import sluggifyMiddleware from './middleware/sluggifyMiddleware'
|
||||||
|
import fixImageUrlsMiddleware from './middleware/fixImageUrlsMiddleware'
|
||||||
import excerptMiddleware from './middleware/excerptMiddleware'
|
import excerptMiddleware from './middleware/excerptMiddleware'
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
import {
|
import {
|
||||||
@ -44,42 +46,12 @@ const driver = neo4j.driver(
|
|||||||
const MOCK = (process.env.MOCK === 'true')
|
const MOCK = (process.env.MOCK === 'true')
|
||||||
console.log('MOCK:', MOCK)
|
console.log('MOCK:', MOCK)
|
||||||
|
|
||||||
/* const logInput = async (resolve, root, args, context, info) => {
|
|
||||||
console.log(args)
|
|
||||||
if (args.email) {
|
|
||||||
args.email = args.email.toLowerCase()
|
|
||||||
}
|
|
||||||
console.log(`1. logInput: ${JSON.stringify(args)}`)
|
|
||||||
const result = await resolve(root, args, context, info)
|
|
||||||
console.log(`5. logInput`)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
const logResult = async (resolve, root, args, context, info) => {
|
|
||||||
console.log(`2. logResult`)
|
|
||||||
let result = await resolve(root, args, context, info)
|
|
||||||
console.log('RESULT:', result)
|
|
||||||
if (Array.isArray(result)) {
|
|
||||||
result.forEach(res => {
|
|
||||||
if (res.email) {
|
|
||||||
res.email = '******'
|
|
||||||
// res.email = res.email.toLowerCase()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else if (typeof result === 'string' && info.fieldName === 'email') {
|
|
||||||
result = '******'
|
|
||||||
// result = result.toLowerCase()
|
|
||||||
}
|
|
||||||
console.log(`4. logResult: ${JSON.stringify(result)}`)
|
|
||||||
return result
|
|
||||||
} */
|
|
||||||
|
|
||||||
const server = new ApolloServer({
|
const server = new ApolloServer({
|
||||||
context: {
|
context: {
|
||||||
driver
|
driver
|
||||||
},
|
},
|
||||||
tracing: true,
|
tracing: true,
|
||||||
schema: applyMiddleware(augmentedSchema, passwordMiddleware, sluggifyMiddleware, excerptMiddleware),
|
schema: applyMiddleware(augmentedSchema, passwordMiddleware, sluggifyMiddleware, excerptMiddleware, fixImageUrlsMiddleware, softDeleteMiddleware),
|
||||||
mocks: MOCK ? {
|
mocks: MOCK ? {
|
||||||
User: () => ({
|
User: () => ({
|
||||||
name: () => `${faker.name.firstName()} ${faker.name.lastName()}`,
|
name: () => `${faker.name.firstName()} ${faker.name.lastName()}`,
|
||||||
|
|||||||
24
src/middleware/fixImageUrlsMiddleware.js
Normal file
24
src/middleware/fixImageUrlsMiddleware.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
const replaceURL = (url) => {
|
||||||
|
return url.replace('https://api-alpha.human-connection.org/uploads', 'http://localhost:3000/uploads')
|
||||||
|
}
|
||||||
|
const fixImageURLs = (result, resolve, root, args, context, info) => {
|
||||||
|
|
||||||
|
if (result && typeof result === 'string' && result.indexOf('https://api-alpha.human-connection.org/uploads') === 0) {
|
||||||
|
result = replaceURL(result)
|
||||||
|
} else if (result && typeof result === 'object') {
|
||||||
|
Object.keys(result).forEach(key => {
|
||||||
|
result[key] = fixImageURLs(result[key])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
Query: async (resolve, root, args, context, info) => {
|
||||||
|
let result = await resolve(root, args, context, info)
|
||||||
|
|
||||||
|
return fixImageURLs(result, resolve, root, args, context, info)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/middleware/softDeleteMiddleware.js
Normal file
26
src/middleware/softDeleteMiddleware.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
export default {
|
||||||
|
Query: {
|
||||||
|
Post: async (resolve, root, args, context, info) => {
|
||||||
|
if (typeof args.deleted !== 'boolean') {
|
||||||
|
args.deleted = false
|
||||||
|
}
|
||||||
|
const result = await resolve(root, args, context, info)
|
||||||
|
return result
|
||||||
|
},
|
||||||
|
Comment: async (resolve, root, args, context, info) => {
|
||||||
|
if (typeof args.deleted !== 'boolean') {
|
||||||
|
args.deleted = false
|
||||||
|
}
|
||||||
|
const result = await resolve(root, args, context, info)
|
||||||
|
return result
|
||||||
|
},
|
||||||
|
User: async (resolve, root, args, context, info) => {
|
||||||
|
// console.log('ROOT', root)
|
||||||
|
// console.log('ARGS', args)
|
||||||
|
// console.log('CONTEXT', context)
|
||||||
|
// console.log('info', info.fieldNodes[0].arguments)
|
||||||
|
const result = await resolve(root, args, context, info)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user