File tree Expand file tree Collapse file tree 2 files changed +21
-18
lines changed Expand file tree Collapse file tree 2 files changed +21
-18
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,11 @@ function graphql_api_permission() {
50
50
return array(
51
51
'use graphql_api query' => array(
52
52
'title' => t('Use GraphQL query'),
53
- 'description' => t('Perform query on graphql endpoint.'),
53
+ 'description' => t('Perform query on GraphQL endpoint.'),
54
+ ),
55
+ 'use graphql_api introspection' => array(
56
+ 'title' => t('Browse GraphQL schema'),
57
+ 'description' => t('Perform introspection query on GraphQL endpoint.'),
54
58
),
55
59
);
56
60
}
@@ -150,4 +154,4 @@ function graphql_api() {
150
154
$obj = new Schema;
151
155
}
152
156
return $obj;
153
- }
157
+ }
Original file line number Diff line number Diff line change @@ -15,23 +15,22 @@ function graphql_api_page_callback() {
15
15
$ data = $ _POST ;
16
16
}
17
17
18
- if (!empty ($ data )) {
19
- if (empty ($ data ['variables ' ])) {
20
- $ data ['variables ' ] = [];
21
- }
22
- }
23
-
24
- if (empty ($ data ['query ' ])) {
25
- $ data ['query ' ] = file_get_contents (__DIR__ . '/../tests/fixtures/instrospec.graphql ' );
26
- $ is_introspec = TRUE ;
27
- }
28
-
29
18
$ requestString = isset ($ data ['query ' ]) ? $ data ['query ' ] : null ;
30
19
$ operationName = isset ($ data ['operation ' ]) ? $ data ['operation ' ] : null ;
31
- $ variableValues = isset ($ data ['variables ' ]) ? $ data ['variables ' ] : null ;
20
+ $ variableValues = isset ($ data ['variables ' ]) ? $ data ['variables ' ] : [] ;
32
21
33
- $ is_introspec = FALSE ;
34
22
try {
23
+ if (empty ($ requestString )) {
24
+ if ( user_access ('use graphql_api introspection ' ) ) {
25
+ $ requestString = file_get_contents (__DIR__ . '/../tests/fixtures/instrospec.graphql ' );
26
+ $ is_introspec = TRUE ;
27
+
28
+ } else {
29
+ throw new Exception (t ("User without permission `use graphql_api introspection` cannot browse the schema " ));
30
+ }
31
+ }
32
+
33
+ $ is_introspec = FALSE ; // @FIXME
35
34
if ($ is_introspec && $ cache = cache_get ('graphql_api_introspec ' ) && empty ($ _GET ['nocache ' ])) {
36
35
$ result = $ cache ->data ;
37
36
} else {
@@ -47,7 +46,7 @@ function graphql_api_page_callback() {
47
46
$ variableValues ,
48
47
$ operationName
49
48
);
50
-
49
+
51
50
if (!empty ($ schemaBuilder ->errors )) {
52
51
$ result ['schema_errors ' ] = $ schemaBuilder ->errors ;
53
52
}
@@ -63,7 +62,7 @@ function graphql_api_page_callback() {
63
62
]
64
63
];
65
64
}
66
-
65
+
67
66
drupal_json_output ($ result );
68
67
exit ;
69
- }
68
+ }
You can’t perform that action at this time.
0 commit comments