Skip to content

Commit 79f4de1

Browse files
committed
Import internal code
1 parent ec16e98 commit 79f4de1

20 files changed

+3574
-48516
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"@babel/preset-react"
4+
]
5+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
}
88
],
99
"require": {
10-
"webonyx/graphql-php": "dev-master"
10+
"webonyx/graphql-php": "dev-master",
11+
"symfony/var-dumper": "*"
1112
}
1213
}

css/graphqleditor.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
#graphqleditor {
1+
#graphql-api-graphiql {
22
top: 0;
33
left: 0;
44
position: fixed;
55
bottom: 0;
66
right: 0;
7+
}
8+
9+
body.toolbar #graphql-api-graphiql {
10+
top: 30px;
711
}

css/voyager.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#graphql-api-voyager {
2+
position: fixed;
3+
top: 0;
4+
bottom: 0;
5+
left: 0;
6+
right: 0;
7+
background: #fff;
8+
}

graphql_api.api.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,12 @@
55
*/
66

77
/**
8-
* Register new GraphQL interface type, object type.
8+
* Implements hook_graphql_api_info().
99
*/
1010
function hook_graphql_api_info() {
1111
return [
1212
'types' => [
13-
'text_formatted' => new ObjectType([
14-
'name' => 'text_formatted',
15-
'fields' => [
16-
'value' => array(
17-
'type' => Type::string(),
18-
'description' => t('Text'),
19-
),
20-
'summary' => array(
21-
'type' => Type::string(),
22-
'description' => t('Summary'),
23-
),
24-
'format' => array(
25-
'type' => Type::string(),
26-
'description' => t('Text format'),
27-
),
28-
]
29-
]),
13+
'token' => ['']
3014
]
3115
];
3216
}

graphql_api.drush.inc

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Implements hook_drush_command().
4+
*/
5+
function graphql_api_drush_command() {
6+
$items['graphql-dump-introspection'] = [
7+
'description' => "Dump introspect result",
8+
'arguments' => [],
9+
'aliases' => ['gadi'],
10+
'examples' => [
11+
'drush graphql-api-dump-introspect' => 'Dump introspect result',
12+
],
13+
];
14+
$items['graphql-dump-schema'] = [
15+
'description' => "Dump schema to schema.graphql",
16+
'arguments' => [],
17+
'aliases' => ['gds'],
18+
'examples' => [
19+
'drush graphql-dump-schema' => 'Dump schema.graphql',
20+
],
21+
];
22+
$items['graphql-dump-ast'] = [
23+
'description' => "Dump ast to schema.ast.php",
24+
'arguments' => [],
25+
'aliases' => ['gds'],
26+
'examples' => [
27+
'drush graphql-dump-ast' => 'Dump schema.ast.php',
28+
],
29+
];
30+
return $items;
31+
}
32+
33+
function _drush_graphql_api_get_schema() {
34+
$is_mutation = true;
35+
$typeLoader = function($typeName) use($is_mutation) {
36+
$schemaBuilder = graphql_api();
37+
$type = $schemaBuilder->buildType($typeName, $is_mutation);
38+
if ($type) {
39+
return $type;
40+
}
41+
return null;
42+
};
43+
$schemaBuilder = graphql_api();
44+
$schema = $schemaBuilder->build([
45+
'typeLoader' => $typeLoader
46+
], $is_mutation);
47+
return $schema;
48+
}
49+
50+
function drush_graphql_api_graphql_dump_introspection() {
51+
$result = graphql_api_query_file(GRAPHQL_API_PATH . '/tests/fixtures/instrospec.graphql');
52+
file_unmanaged_save_data(json_encode($result), GRAPHQL_API_PATH . '/introspection.json', FILE_EXISTS_OVERWRITE);
53+
}
54+
55+
function drush_graphql_api_graphql_dump_schema() {
56+
$schema_file = GRAPHQL_API_PATH . '/schema.graphql';
57+
$schema = _drush_graphql_api_get_schema();
58+
59+
$schema_graphql = GraphQL\Utils\SchemaPrinter::doPrint($schema);
60+
file_unmanaged_save_data($schema_graphql, $schema_file, FILE_EXISTS_OVERWRITE);
61+
drush_print('schema.graphql ready');
62+
}
63+
64+
function drush_graphql_api_graphql_dump_ast() {
65+
$schema_file = __DIR__ . '/schema.graphql';
66+
$ast_file = __DIR__ . '/schema.ast.php';
67+
if (!file_exists($schema_file)) {
68+
return drush_log("$schema_file is missing.", 'error');
69+
}
70+
$schema_content = file_get_contents($schema_file);
71+
$ast = GraphQL\Language\Parser::parse($schema_content);
72+
$ast_array = GraphQL\Utils\AST::toArray($ast);
73+
$ast_data = "<?php\nreturn " . var_export(GraphQL\Utils\AST::toArray($ast_array), true);
74+
file_put_contents($ast_file, $ast_data);
75+
drush_print('schema.ast.php ready');
76+
}
77+

graphql_api.graphql.inc

Lines changed: 92 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -13,151 +13,104 @@ use GraphQL\Type\Definition\ObjectType;
1313
function graphql_api_graphql_api_info() {
1414
return [
1515
'types' => [
16-
'text_formatted' => new ObjectType([
17-
'name' => 'text_formatted',
18-
'fields' => [
19-
'value' => array(
20-
'type' => Type::string(),
21-
'description' => t('Text'),
22-
),
23-
'summary' => array(
24-
'type' => Type::string(),
25-
'description' => t('Summary'),
26-
),
27-
'format' => array(
28-
'type' => Type::string(),
29-
'description' => t('Text format'),
30-
),
31-
]
32-
]),
33-
'field_item_file' => new ObjectType([
34-
'name' => 'field_item_file',
35-
'fields' => function () {
36-
$schema = graphql_api();
37-
$file_type = $schema->getObjectType('file_file');
38-
if (module_exists('file_entity')) {
39-
$file_type = $schema->getInterfaceType('file');
40-
}
41-
return [
42-
'description' => [
43-
'type' => Type::string(),
44-
'description' => t('Alt')
16+
'text_formatted' => new ObjectType(
17+
[
18+
'name' => 'text_formatted',
19+
'fields' => [
20+
'value' => [
21+
'type' => Type::string(),
22+
'description' => t('Text'),
4523
],
46-
'display' => [
47-
'type' => Type::string(),
48-
'description' => t('Display')
24+
'summary' => [
25+
'type' => Type::string(),
26+
'description' => t('Summary'),
4927
],
50-
'file' => [
51-
'type' => $file_type,
52-
'description' => t('File')
53-
]
54-
];
55-
}
56-
]),
57-
'field_item_image' => new ObjectType([
58-
'name' => 'field_item_image',
28+
'format' => [
29+
'type' => Type::string(),
30+
'description' => t('Text format'),
31+
],
32+
],
33+
]
34+
),
35+
'image_styles' => new ObjectType([
36+
'name' => 'image_styles',
5937
'fields' => function () {
60-
$schema = graphql_api();
61-
$file_type = $schema->getObjectType('file_file');
62-
if (module_exists('file_entity')) {
63-
$file_type = $schema->getInterfaceType('file');
38+
$fields = [];
39+
foreach (image_styles() as $style_name => $info) {
40+
$field_name = preg_replace('/[^_a-zA-Z0-9]/', '_', $style_name);
41+
if (preg_match('/^[_a-zA-Z][_a-zA-Z0-9]*$/', $field_name)) {
42+
$fields[$field_name] = [
43+
'type' => Type::string(),
44+
'description' => $info['label']
45+
];
46+
} else {
47+
watchdog('GraphQL', "image_styles '{$style_name}' is ignored, not match pattern /^[_a-zA-Z][_a-zA-Z0-9]*$/");
48+
}
6449
}
65-
return [
66-
'description' => [
67-
'type' => Type::string(),
68-
'description' => t('Alt')
69-
],
70-
'display' => [
71-
'type' => Type::string(),
72-
'description' => t('Display')
73-
],
74-
'alt' => [
75-
'type' => Type::string(),
76-
'description' => t('Alt')
77-
],
78-
'title' => [
79-
'type' => Type::string(),
80-
'description' => t('Title')
81-
],
82-
'width' => [
83-
'type' => Type::float(),
84-
'description' => t('Width')
85-
],
86-
'height' => [
87-
'type' => Type::float(),
88-
'description' => t('Height')
89-
],
90-
'file' => [
91-
'type' => $file_type,
92-
'description' => t('File')
93-
]
94-
];
50+
return $fields;
9551
}
9652
]),
97-
'socialfield' => Type::listOf(new ObjectType([
98-
'name' => 'socialfield',
99-
'fields' => [
100-
'service' => [
101-
'type' => Type::string(),
102-
'description' => t('Service')
103-
],
104-
'url' => [
105-
'type' => Type::string(),
106-
'description' => t('URL')
107-
],
108-
'weight' => [
109-
'type' => Type::int(),
110-
'description' => t('Weight')
111-
]
53+
'field_item_file' => new ObjectType(
54+
[
55+
'name' => 'field_item_file',
56+
'fields' => function () {
57+
graphql_api()->addEntityGqlDefinition('file');
58+
$type = graphql_api()->getInterfaceType('file');
59+
return [
60+
'file' => [
61+
'type' => $type,
62+
'description' => t('File'),
63+
'resolve' => function ($value) {
64+
if ($value) {
65+
$file = file_load($value['fid']);
66+
return entity_metadata_wrapper('file', $file);
67+
}
68+
return NULL;
69+
},
70+
],
71+
'description' => [
72+
'type' => Type::string(),
73+
'description' => t('Alt'),
74+
],
75+
'display' => [
76+
'type' => Type::string(),
77+
'description' => t('Display'),
78+
],
79+
];
80+
},
11281
]
113-
])),
114-
'field_item_name' => new ObjectType([
115-
'name' => 'field_item_name',
116-
'fields' => [
117-
'title' => [
118-
'type' => Type::string(),
119-
'description' => t('The title of the name.')
120-
],
121-
'given' => [
122-
'type' => Type::string(),
123-
'description' => t('The given name.')
124-
],
125-
'middle' => [
126-
'type' => Type::string(),
127-
'description' => t('The middle of the name.')
128-
],
129-
'family' => [
130-
'type' => Type::string(),
131-
'description' => t('The family of the name.')
132-
],
133-
'generational' => [
134-
'type' => Type::string(),
135-
'description' => t('The generational of the name.')
136-
],
137-
'credentials' => [
138-
'type' => Type::string(),
139-
'description' => t('The credentials of the name.')
140-
]
141-
]
142-
]),
143-
'field_item_link' => new ObjectType([
144-
'name' => 'field_item_link',
145-
'fields' => [
146-
'title' => [
147-
'type' => Type::string(),
148-
'description' => t('The title of the link.')
149-
],
150-
'url' => [
151-
'type' => Type::string(),
152-
'description' => t('The URL of the link.')
153-
],
154-
// @todo convert attributes to JSON?
155-
// 'attributes' => [
156-
// 'type' => Type::string(),
157-
// 'description' => t('The attributes of the link.')
158-
// ],
82+
),
83+
'field_item_image' => new ObjectType(
84+
[
85+
'name' => 'field_item_image',
86+
'fields' => function () {
87+
// graphql_api()->addEntityGqlDefinition('file');
88+
// $type = graphql_api()->getObjectType('file');
89+
return [
90+
'fid' => [
91+
'type' => Type::string(),
92+
'description' => t('File ID'),
93+
],
94+
'description' => [
95+
'type' => Type::string(),
96+
'description' => t('Alt'),
97+
],
98+
'display' => [
99+
'type' => Type::string(),
100+
'description' => t('Display'),
101+
],
102+
'alt' => [
103+
'type' => Type::string(),
104+
'description' => t('Alt'),
105+
],
106+
'title' => [
107+
'type' => Type::string(),
108+
'description' => t('Title'),
109+
],
110+
];
111+
},
159112
]
160-
])
161-
]
113+
),
114+
],
162115
];
163-
}
116+
}

0 commit comments

Comments
 (0)