Skip to content

Commit a10387a

Browse files
committed
Update doc
1 parent eb73ac4 commit a10387a

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ This module attempt bring GraphQL to Drupal 7.
1414

1515
For Drupal 8, you should use <http://drupal.org/project/graphql>
1616

17+
18+
Requirements
19+
------------
20+
21+
- PHP 5.4+
22+
23+
Installation
24+
------------
25+
26+
- Install `xautoload` http://drupal.org/project/xautoload
27+
- Install `entity` http://drupal.org/project/entity
28+
- Install `composer_manager` http://drupal.org/project/composer_manager
29+
- Install `graphql_api`
30+
- Update composer requirement's https://www.drupal.org/node/2405805
31+
32+
Usages
33+
------
34+
35+
- `/graphqleditor` explore your Drupal 7 site's GraphQL schema
36+
- `/graphql` use your favorite GraphQL client (Apollo http://www.apollodata.com/) to begin query
37+
- `graphql_api_query_file()` execute .GrahpQL query from file
38+
1739
The tools
1840
---------
1941

@@ -28,8 +50,8 @@ The tools
2850
The plans
2951
---------
3052

31-
1. Create module graphql\_api
32-
2. Create class `Drupal\grapql\_api\Schema` to build GraphQL schema
53+
1. [x] Create module graphql\_api
54+
2. [x] Create class `Drupal\grapql\_api\Schema` to build GraphQL schema
3355
- use `hook_entity_info()`, `hook_entity_property_info()` to build GraphQL schema
3456
- map Drupal concept to GraphQL concept
3557
- Entity type -> Interface
@@ -42,7 +64,7 @@ The plans
4264
- Field API: term_reference -> Interface: term
4365
- Field API: entityreference -> Interface/Object target entity
4466
- Field API: relation -> Interface/Object target entity
45-
3. Create GraphQL endpoint `/graphql`
67+
3. [x] Create GraphQL endpoint `/graphql`
4668
- receive POST content with GraphQL query and variables
4769
- query using Drupal's `EntityFieldQuery`
4870
- check entity access using `entity_access`
@@ -55,5 +77,5 @@ The plans
5577
Notes
5678
-----
5779

58-
1. Field will be shortened `field_tags` -> `tags`
59-
2. If entity type have single bundle, we skip GraphQL interface and just use GraphQL object. Eg: user, file, ...
80+
1. ~~Field will be shortened `field_tags` -> `tags`~~ Shortened field name can be duplicate with base table's column or other property. Keep field name intact.
81+
2. ~~If entity type have single bundle, we skip GraphQL interface and just use GraphQL object. Eg: user, file, ...~~ Entity reference field will resolve to Entity type, not bundle.

graphql_api.api.php

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

77
/**
8-
*
8+
* Register new GraphQL interface type, object type.
99
*/
1010
function hook_graphql_api_info() {
1111
return [
1212
'types' => [
13-
'token' => ['']
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+
]),
1430
]
1531
];
1632
}

graphql_api.module

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ function graphql_api_query_file($file, $args = []) {
123123
$query_task = file_get_contents($file);
124124
$shema = new Schema();
125125
$schema_build = $shema->build();
126-
$task_form_data = GraphQL::execute(
126+
$data = GraphQL::execute(
127127
$schema_build,
128128
$query_task,
129129
null,
130130
null,
131131
$args
132132
);
133-
return $task_form_data;
133+
return $data;
134134
}
135135

136136
/**

0 commit comments

Comments
 (0)