Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
neo4j_for_dbas
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marc Feger
neo4j_for_dbas
Commits
9ef1da53
Commit
9ef1da53
authored
6 years ago
by
Marc Feger
Browse files
Options
Downloads
Patches
Plain Diff
Refactor GraphQl by abstracting a Adapter class
parent
66bbd08a
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/graph.py
+1
-1
1 addition, 1 deletion
api/graph.py
api/interface/__init__.py
+0
-0
0 additions, 0 deletions
api/interface/__init__.py
api/interface/graphql.py
+21
-15
21 additions, 15 deletions
api/interface/graphql.py
api/server.py
+3
-2
3 additions, 2 deletions
api/server.py
with
25 additions
and
18 deletions
api/graph.py
+
1
−
1
View file @
9ef1da53
from
neo4j
import
GraphDatabase
import
time
from
api.
graphql
.graphql
import
Discussion
from
api.
interface
.graphql
import
Discussion
URL
=
'
jdbc:postgresql://db/discussion?user=postgres&password=FooBar
'
...
...
This diff is collapsed.
Click to expand it.
api/
graphql
/__init__.py
→
api/
interface
/__init__.py
+
0
−
0
View file @
9ef1da53
File moved
This diff is collapsed.
Click to expand it.
api/
graphql
/graphql.py
→
api/
interface
/graphql.py
+
21
−
15
View file @
9ef1da53
...
...
@@ -6,12 +6,9 @@ import requests
from
neo4j
import
GraphDatabase
class
GraphQl
(
object
):
def
__init__
(
self
,
protocol
,
host
,
port
):
self
.
protocol
=
protocol
self
.
host
=
host
self
.
port
=
port
class
Adapter
(
object
):
def
__init__
(
self
,
url
):
self
.
url
=
url
@staticmethod
def
_json_to_dict
(
col
):
...
...
@@ -21,10 +18,9 @@ class GraphQl(object):
col
=
col
.
decode
(
"
utf-8
"
)
return
json
.
loads
(
col
)
def
request
(
self
,
query
):
url
=
"
{}://{}:{}/api/v2/query?q={}
"
.
format
(
self
.
protocol
,
self
.
host
,
self
.
port
,
query
)
def
request
(
self
):
try
:
response
=
requests
.
get
(
url
)
response
=
requests
.
get
(
self
.
url
)
except
requests
.
exceptions
.
ConnectionError
:
logging
.
error
(
"
Connection Error
"
)
return
{}
...
...
@@ -33,10 +29,20 @@ class GraphQl(object):
return
ret
class
GraphQl
(
Adapter
):
def
__init__
(
self
,
protocol
,
host
,
port
,
query
):
self
.
protocol
=
protocol
self
.
host
=
host
self
.
port
=
port
self
.
query
=
query
super
().
__init__
(
"
{}://{}:{}/api/v2/query?q={}
"
.
format
(
self
.
protocol
,
self
.
host
,
self
.
port
,
query
))
class
Discussion
(
GraphQl
):
def
__init__
(
self
,
protocol
,
host
,
port
,
uri
,
user
,
password
):
super
().
__init__
(
protocol
,
host
,
port
)
def
__init__
(
self
,
protocol
,
host
,
port
,
uri
,
user
,
password
,
slug
):
super
().
__init__
(
protocol
,
host
,
port
,
query
=
self
.
_cypher_query
(
slug
)
)
self
.
_driver
=
GraphDatabase
.
driver
(
uri
,
auth
=
(
user
,
password
))
def
close
(
self
):
...
...
@@ -52,8 +58,8 @@ class Discussion(GraphQl):
}}
"""
.
format
(
slug
)
def
to_cypher
(
self
,
slug
):
result
=
super
().
request
(
query
=
self
.
_cypher_query
(
slug
)
)
def
to_cypher
(
self
):
result
=
super
().
request
()
return
result
[
'
issue
'
][
'
completeGraphCypher
'
]
@staticmethod
...
...
@@ -63,9 +69,9 @@ class Discussion(GraphQl):
)
return
result
def
inject_to_neo
(
self
,
slug
):
def
inject_to_neo
(
self
):
t1
=
time
.
time
()
query
=
self
.
to_cypher
(
slug
)
query
=
self
.
to_cypher
()
with
self
.
_driver
.
session
()
as
session
:
session
.
write_transaction
(
self
.
_create_discussion
,
query
)
...
...
This diff is collapsed.
Click to expand it.
api/server.py
+
3
−
2
View file @
9ef1da53
...
...
@@ -2,7 +2,7 @@ from flask import Flask, render_template, jsonify
from
flask_cors
import
CORS
from
api.graph
import
Graph
from
api.
graphql
.graphql
import
Discussion
from
api.
interface
.graphql
import
Discussion
app
=
Flask
(
__name__
,
template_folder
=
'
.
'
)
CORS
(
app
)
...
...
@@ -25,7 +25,8 @@ def load_discussion(slug):
port
=
'
443
'
,
uri
=
'
bolt://neo:7687
'
,
user
=
'
neo4j
'
,
password
=
'
neo4j
'
).
inject_to_neo
(
slug
)
password
=
'
neo4j
'
,
slug
=
slug
).
inject_to_neo
()
return
jsonify
(
result
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment