mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
backend still not working
This commit is contained in:
parent
cad527f906
commit
77cdc34bfd
@ -83,9 +83,9 @@ export default shield(
|
||||
{
|
||||
Query: {
|
||||
'*': deny,
|
||||
findPosts: allow,
|
||||
findUsers: allow,
|
||||
findAnything: allow,
|
||||
findPosts: allow,
|
||||
findUsers: allow,
|
||||
findAnything: allow,
|
||||
embed: allow,
|
||||
Category: allow,
|
||||
Tag: allow,
|
||||
|
||||
@ -47,10 +47,8 @@ export default {
|
||||
return neo4jgraphql(object, params, context, resolveInfo)
|
||||
},
|
||||
findPosts: async (object, params, context, resolveInfo) => {
|
||||
params = await filterForBlockedUsers(params, context)
|
||||
const debug = await neo4jgraphql(object, params, context, resolveInfo, true)
|
||||
console.log('debug', debug)
|
||||
return debug
|
||||
params = await filterForBlockedUsers(params, context)
|
||||
return neo4jgraphql(object, params, context, resolveInfo, true)
|
||||
},
|
||||
profilePagePosts: async (object, params, context, resolveInfo) => {
|
||||
params = await filterForBlockedUsers(params, context)
|
||||
|
||||
@ -1,30 +1,60 @@
|
||||
import posts from './posts.js'
|
||||
import users from './users.js'
|
||||
|
||||
const postArgs = (args, query) => {
|
||||
args.query = query.replace(/\s/g, '~ ') + '~'
|
||||
args.filter = {}
|
||||
return args
|
||||
}
|
||||
|
||||
const userArgs = (args, query) => {
|
||||
args.query = new RegExp('(?i).*BOB.*')//(?i).*' + query + '.*
|
||||
args.filter = {}
|
||||
return args
|
||||
}
|
||||
|
||||
export default {
|
||||
Query: {
|
||||
findAnything: async (_parent, args, context, _resolveInfo) => {
|
||||
const query = args.query
|
||||
console.log('postArgs', postArgs(args, query))
|
||||
const postResults = await posts.Query.findPosts(_parent, postArgs(args, query), context, _resolveInfo)
|
||||
console.log('Posts', postResults)
|
||||
//console.log('userArgs', userArgs(args, query))
|
||||
//const userResults = await users.Query.findUsers(_parent, userArgs(args, query), context, _resolveInfo)
|
||||
//console.log('Users', userResults)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
SearchResult: {
|
||||
__resolveType(obj, context, info) {
|
||||
console.log('----', obj.keys)
|
||||
if (obj.keys.includes('user')) {
|
||||
return info.schema.getType('User')
|
||||
}
|
||||
|
||||
if (obj.keys.includes('post')) {
|
||||
return info.schema.getType('Post')
|
||||
}
|
||||
return null
|
||||
},
|
||||
},
|
||||
Query: {
|
||||
findAnything: async (_parent, args, context, _resolveInfo) => {
|
||||
const query = args.query
|
||||
const filter = {}
|
||||
const limit = args.limit
|
||||
const postQuery = query.replace(/\s/g, '~ ') + '~'
|
||||
const userQuery = query.replace(/\s/g, '~ ') + '~'
|
||||
const postCypher = `
|
||||
CALL db.index.fulltext.queryNodes('post_fulltext_search', $query)
|
||||
YIELD node as post, score
|
||||
MATCH (post)<-[:WROTE]-(user:User)
|
||||
WHERE score >= 0.2
|
||||
AND NOT user.deleted = true AND NOT user.disabled = true
|
||||
AND NOT post.deleted = true AND NOT post.disabled = true
|
||||
AND NOT user.id in COALESCE($filter.author_not.id_in, [])
|
||||
RETURN post
|
||||
LIMIT $limit
|
||||
`
|
||||
const session = context.driver.session()
|
||||
const postResults = await session.run(postCypher, {
|
||||
query: postQuery,
|
||||
filter: filter,
|
||||
limit: limit,
|
||||
})
|
||||
session.close()
|
||||
const userCypher = `
|
||||
CALL db.index.fulltext.queryNodes('user_fulltext_search', $query)
|
||||
YIELD node as post, score
|
||||
MATCH (user)
|
||||
WHERE score >= 0.2
|
||||
AND NOT user.deleted = true AND NOT user.disabled = true
|
||||
RETURN user
|
||||
LIMIT $limit
|
||||
`
|
||||
const userResults = await session.run(userCypher, {
|
||||
query: userQuery,
|
||||
filter: filter,
|
||||
limit: limit,
|
||||
})
|
||||
|
||||
session.close()
|
||||
console.log(postResults.records.concat(userResults.records))
|
||||
return postResults.records.concat(userResults.records)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -45,13 +45,6 @@ export default {
|
||||
} catch (e) {
|
||||
throw new UserInputError(e.message)
|
||||
}
|
||||
},
|
||||
findUsers: async (object, params, context, resolveInfo) => {
|
||||
console.log('params', params)
|
||||
//const blockedUsers = await getBlockedUsers(context)
|
||||
const debug = await neo4jgraphql(object, params, context, resolveInfo, true)
|
||||
console.log('debug', debug)
|
||||
return debug
|
||||
},
|
||||
User: async (object, args, context, resolveInfo) => {
|
||||
const { email } = args
|
||||
|
||||
@ -231,7 +231,7 @@ type Query {
|
||||
findPosts(query: String!, limit: Int = 10, filter: _PostFilter): [Post]!
|
||||
@cypher(
|
||||
statement: """
|
||||
CALL db.index.fulltext.queryNodes('full_text_search', $query)
|
||||
CALL db.index.fulltext.queryNodes('post_fulltext_search', $query)
|
||||
YIELD node as post, score
|
||||
MATCH (post)<-[:WROTE]-(user:User)
|
||||
WHERE score >= 0.2
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
union SearchResult = Post | User
|
||||
|
||||
type Query {
|
||||
findAnything(query: String!, limit: Int = 10): [Post]
|
||||
findAnything(query: String!, limit: Int = 5): [SearchResult]!
|
||||
}
|
||||
|
||||
@ -165,11 +165,13 @@ type Query {
|
||||
findUsers(query: String!,limit: Int = 10, filter: _UserFilter): [User]!
|
||||
@cypher(
|
||||
statement: """
|
||||
MATCH (user:User)
|
||||
WHERE (user.name =~ $query OR user.slug =~ $query)
|
||||
AND NOT user.deleted = true AND NOT user.disabled = true
|
||||
RETURN user
|
||||
LIMIT $limit
|
||||
CALL db.index.fulltext.queryNodes('user_fulltext_search', $query)
|
||||
YIELD node as post, score
|
||||
MATCH (user)
|
||||
WHERE score >= 0.2
|
||||
AND NOT user.deleted = true AND NOT user.disabled = true
|
||||
RETURN user
|
||||
LIMIT $limit
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
ENV_FILE=$(dirname "$0")/.env
|
||||
[[ -f "$ENV_FILE" ]] && source "$ENV_FILE"
|
||||
|
||||
if [ -z "$NEO4J_USERNAME" ] || [ -z "$NEO4J_PASSWORD" ]; then
|
||||
echo "Please set NEO4J_USERNAME and NEO4J_PASSWORD environment variables."
|
||||
echo "Setting up database constraints and indexes will probably fail because of authentication errors."
|
||||
@ -21,7 +20,8 @@ CALL db.indexes();
|
||||
' | cypher-shell
|
||||
|
||||
echo '
|
||||
CALL db.index.fulltext.createNodeIndex("full_text_search",["Post"],["title", "content"]);
|
||||
CALL db.index.fulltext.createNodeIndex("post_fulltext_search",["Post"],["title", "content"]);
|
||||
CALL db.index.fulltext.createNodeIndex("user_fulltext_search",["User"],["name", "slug"]);
|
||||
CREATE CONSTRAINT ON (p:Post) ASSERT p.id IS UNIQUE;
|
||||
CREATE CONSTRAINT ON (c:Comment) ASSERT c.id IS UNIQUE;
|
||||
CREATE CONSTRAINT ON (c:Category) ASSERT c.id IS UNIQUE;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user