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
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
Branches
Branches containing commit
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
from
neo4j
import
GraphDatabase
import
time
import
time
from
api.
graphql
.graphql
import
Discussion
from
api.
interface
.graphql
import
Discussion
URL
=
'
jdbc:postgresql://db/discussion?user=postgres&password=FooBar
'
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
...
@@ -6,12 +6,9 @@ import requests
from
neo4j
import
GraphDatabase
from
neo4j
import
GraphDatabase
class
GraphQl
(
object
):
class
Adapter
(
object
):
def
__init__
(
self
,
url
):
def
__init__
(
self
,
protocol
,
host
,
port
):
self
.
url
=
url
self
.
protocol
=
protocol
self
.
host
=
host
self
.
port
=
port
@staticmethod
@staticmethod
def
_json_to_dict
(
col
):
def
_json_to_dict
(
col
):
...
@@ -21,10 +18,9 @@ class GraphQl(object):
...
@@ -21,10 +18,9 @@ class GraphQl(object):
col
=
col
.
decode
(
"
utf-8
"
)
col
=
col
.
decode
(
"
utf-8
"
)
return
json
.
loads
(
col
)
return
json
.
loads
(
col
)
def
request
(
self
,
query
):
def
request
(
self
):
url
=
"
{}://{}:{}/api/v2/query?q={}
"
.
format
(
self
.
protocol
,
self
.
host
,
self
.
port
,
query
)
try
:
try
:
response
=
requests
.
get
(
url
)
response
=
requests
.
get
(
self
.
url
)
except
requests
.
exceptions
.
ConnectionError
:
except
requests
.
exceptions
.
ConnectionError
:
logging
.
error
(
"
Connection Error
"
)
logging
.
error
(
"
Connection Error
"
)
return
{}
return
{}
...
@@ -33,10 +29,20 @@ class GraphQl(object):
...
@@ -33,10 +29,20 @@ class GraphQl(object):
return
ret
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
):
class
Discussion
(
GraphQl
):
def
__init__
(
self
,
protocol
,
host
,
port
,
uri
,
user
,
password
):
def
__init__
(
self
,
protocol
,
host
,
port
,
uri
,
user
,
password
,
slug
):
super
().
__init__
(
protocol
,
host
,
port
)
super
().
__init__
(
protocol
,
host
,
port
,
query
=
self
.
_cypher_query
(
slug
)
)
self
.
_driver
=
GraphDatabase
.
driver
(
uri
,
auth
=
(
user
,
password
))
self
.
_driver
=
GraphDatabase
.
driver
(
uri
,
auth
=
(
user
,
password
))
def
close
(
self
):
def
close
(
self
):
...
@@ -52,8 +58,8 @@ class Discussion(GraphQl):
...
@@ -52,8 +58,8 @@ class Discussion(GraphQl):
}}
}}
"""
.
format
(
slug
)
"""
.
format
(
slug
)
def
to_cypher
(
self
,
slug
):
def
to_cypher
(
self
):
result
=
super
().
request
(
query
=
self
.
_cypher_query
(
slug
)
)
result
=
super
().
request
()
return
result
[
'
issue
'
][
'
completeGraphCypher
'
]
return
result
[
'
issue
'
][
'
completeGraphCypher
'
]
@staticmethod
@staticmethod
...
@@ -63,9 +69,9 @@ class Discussion(GraphQl):
...
@@ -63,9 +69,9 @@ class Discussion(GraphQl):
)
)
return
result
return
result
def
inject_to_neo
(
self
,
slug
):
def
inject_to_neo
(
self
):
t1
=
time
.
time
()
t1
=
time
.
time
()
query
=
self
.
to_cypher
(
slug
)
query
=
self
.
to_cypher
()
with
self
.
_driver
.
session
()
as
session
:
with
self
.
_driver
.
session
()
as
session
:
session
.
write_transaction
(
self
.
_create_discussion
,
query
)
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
...
@@ -2,7 +2,7 @@ from flask import Flask, render_template, jsonify
from
flask_cors
import
CORS
from
flask_cors
import
CORS
from
api.graph
import
Graph
from
api.graph
import
Graph
from
api.
graphql
.graphql
import
Discussion
from
api.
interface
.graphql
import
Discussion
app
=
Flask
(
__name__
,
template_folder
=
'
.
'
)
app
=
Flask
(
__name__
,
template_folder
=
'
.
'
)
CORS
(
app
)
CORS
(
app
)
...
@@ -25,7 +25,8 @@ def load_discussion(slug):
...
@@ -25,7 +25,8 @@ def load_discussion(slug):
port
=
'
443
'
,
port
=
'
443
'
,
uri
=
'
bolt://neo:7687
'
,
uri
=
'
bolt://neo:7687
'
,
user
=
'
neo4j
'
,
user
=
'
neo4j
'
,
password
=
'
neo4j
'
).
inject_to_neo
(
slug
)
password
=
'
neo4j
'
,
slug
=
slug
).
inject_to_neo
()
return
jsonify
(
result
)
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