Coverage report: /development/source/library/org/datagraph/spocq-shard/src/extensions/graphql/graphql.lisp
| Kind | Covered | All | % |
| expression | 0 | 117 | 0.0 |
| branch | 0 | 10 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; -*- Mode: lisp; Syntax: ansi-common-lisp; Base: 10; Package: org.datagraph.spocq.implementation; -*-
3
;;; (load "patches/graphql.lisp")
5
(in-package :org.datagraph.spocq.implementation)
7
(defmacro graphql::|graphqlFile| (&rest definitions)
8
`(progn ,@definitions))
10
(defmacro graphql::|definition| (fragment_definition operation_definition type_definition)
11
`(or ,fragment_definition ,operation_definition ,type_definition))
13
(defun graphql::compute-selection-variables (form)
15
((graphql::|selection_set| graphql::|field|)
16
(loop for selection in (rest form)
17
append (graphql::compute-selection-variables selection)))
18
(graphql::|selection| (graphql::compute-selection-variables (second form)))
19
(graphql::|field_name| (list (make-variable (second form))))))
21
(defun graphql::compute-selection-patterns (form &optional (subject nil))
22
"This is appied to a top-level selection form to translate it into a basic graph pattern.
23
The root element serves as a type qualification and the components as property and variable
25
;; (print (list 'graphql::compute-selection-patterns (base-iri)))
26
(labels ((expand-selection-set (selection-set subject-variable)
27
(loop for selection in (rest selection-set)
28
for operation = (first selection)
29
append (let* ((field (assoc 'graphql::|field| (rest selection)))
30
(name (second (assoc 'graphql::|field_name| (rest field))))
31
(sub-selection (assoc 'graphql::|selection_set| (rest field)))
32
(field-variable (make-variable name))
33
(property (merge-and-intern-iri name)))
34
(append (if sub-selection
35
(cons `(spocq.a:|triple| ,subject ,property ,field-variable)
36
(expand-selection-set sub-selection field-variable))
37
`((spocq.a:|triple| ,subject-variable ,property ,field-variable)))
38
(expand-arguments (rest (assoc 'graphql::|arguments-Constructor| (rest field)))
40
(expand-arguments (arguments subject)
41
(loop for argument in arguments
42
for argument-name = (second (assoc 'graphql::|argument_name| (rest argument)))
43
for argument-value = (second (assoc 'graphql::|argument_value| (rest argument)))
44
when (and argument-name argument-value)
45
append `((spocq.a:|triple| ,subject ,(merge-and-intern-iri argument-name) ,argument-value)))))
47
(graphql::|selection_set|
48
(loop for selection in (rest form)
49
for operation = (first selection)
50
append (case operation
52
(let* ((field (assoc 'graphql::|field| (rest selection)))
53
(name (second (assoc 'graphql::|field_name| (rest field))))
54
(sub-selection (assoc 'graphql::|selection_set| (rest field)))
55
(field-variable (or subject (make-variable name)))
56
(type (merge-and-intern-iri name))
57
(kernel `((spocq.a:|triple| ,field-variable <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ,type))))
60
(expand-selection-set sub-selection field-variable))
61
(expand-arguments (rest (assoc 'graphql::|arguments-Constructor| (rest field)))
62
field-variable))))))))))
67
(defmacro graphql::|operation_definition| (operation_type operation_name? variable_definitions? directive? selection_set)
68
(declare (ignore variable_definitions? directive?))
69
(let ((type (second operation_type))
70
(name (second operation_name?)))
71
(declare (ignore name))
72
;; the name is just an individual request identifier.
73
;; the type is limited to known forms
77
(spocq.a:|bgp| ,@(graphql::compute-selection-patterns selection_set))
78
,(graphql::compute-selection-variables selection_set))))))
80
(defgeneric run-graphql (query &rest args &key user-id repository-id base-iri)
81
(:method ((query string) &rest args &key ((:base-iri *base-iri*) *base-iri*) user-id repository-id)
82
(declare (ignore user-id repository-id))
83
(let ((sse (parse-graphql query )))
84
(apply #'run-sparql sse args))))
87
((ORG.DATAGRAPH.SPOCQ.GRAPHQL::|operation_type|
88
ORG.DATAGRAPH.SPOCQ.GRAPHQL::|query|)
89
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|operation_name| "movies") NIL NIL
90
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|selection_set|
91
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|selection|
92
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|field| NIL
93
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|field_name| "movie")
94
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|arguments-Constructor|
95
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|argument|
96
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|argument_name| "id")
97
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|argument_value| "tt0068646")))
98
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|directives| NIL)
99
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|selection_set|
100
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|selection|
101
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|field| NIL
102
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|field_name| "name") NIL
103
(ORG.DATAGRAPH.SPOCQ.GRAPHQL::|directives| NIL) NIL)))))))