Skip to content

Commit 283090c

Browse files
authored
Merge pull request #6 from Enliven-se/master
2 parents 4e1230f + d6763b0 commit 283090c

File tree

10 files changed

+10270
-17941
lines changed

10 files changed

+10270
-17941
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
vendor/

graphql_api.module

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ function graphql_api_permission() {
5050
return array(
5151
'use graphql_api query' => array(
5252
'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.'),
5458
),
5559
);
5660
}
@@ -150,4 +154,4 @@ function graphql_api() {
150154
$obj = new Schema;
151155
}
152156
return $obj;
153-
}
157+
}

includes/graphql_api_page_callback.inc

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,22 @@ function graphql_api_page_callback() {
1515
$data = $_POST;
1616
}
1717

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-
2918
$requestString = isset($data['query']) ? $data['query'] : null;
3019
$operationName = isset($data['operation']) ? $data['operation'] : null;
31-
$variableValues = isset($data['variables']) ? $data['variables'] : null;
20+
$variableValues = isset($data['variables']) ? $data['variables'] : [];
3221

33-
$is_introspec = FALSE;
3422
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
3534
if ($is_introspec && $cache = cache_get('graphql_api_introspec') && empty($_GET['nocache'])) {
3635
$result = $cache->data;
3736
} else {
@@ -47,7 +46,7 @@ function graphql_api_page_callback() {
4746
$variableValues,
4847
$operationName
4948
);
50-
49+
5150
if (!empty($schemaBuilder->errors)) {
5251
$result['schema_errors'] = $schemaBuilder->errors;
5352
}
@@ -63,7 +62,7 @@ function graphql_api_page_callback() {
6362
]
6463
];
6564
}
66-
65+
6766
drupal_json_output($result);
6867
exit;
69-
}
68+
}

0 commit comments

Comments
 (0)