Skip to content

Commit 997caee

Browse files
Cryt1cfubhy
authored andcommitted
Update the docs to reflect the newest changes. (#839)
1 parent 9663a46 commit 997caee

9 files changed

Lines changed: 45 additions & 44 deletions

File tree

doc/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Anyone who wants to get JSON data out of Drupal.
1010

1111
A few examples of where the GraphQL module could be used:
1212

13-
* Decoupled Drupal applications with a javascript front-end \(React, Angular, Ember, etc\),
13+
* Decoupled Drupal applications with a javascript front-end \(React, Angular, Ember, etc\),
1414
* Twig Templates \(Drupal theming\)
1515
* Mobile applications that need a persistent data store
1616
* IOT data storage
@@ -23,14 +23,14 @@ This trade-off does come with costs mostly around ease of use, where in the 3.x
2323

2424
## Hello World \(Quick Start\)
2525

26-
1. Familiarize yourself with the GraphQL language. The official GraphQL docs are very well written.
26+
1. Familiarize yourself with the GraphQL language. The official GraphQL docs are very well written.
2727

2828
[http://graphql.org/learn/](http://graphql.org/learn/)
2929

3030
2. Install the module and enable GraphQL.
31-
3. Login and navigate to `/admin/config/graphql` create a new server. You can use the Test schema that comes with the module to try out using GraphQL for the first time before making your own schema. Create the server and specify and endpoint such as `/graphql`. After creating the server click on `explorer` and this should bring you to the Graphiql explorer.
31+
3. Login and navigate to `/admin/config/graphql` create a new server. You can use the "Example schema" that comes with the graphql_examples module (comes with the graphql module but needs to be enabled separately) to try out using GraphQL for the first time before making your own schema. Create a server and specify an endpoint such as `/graphql`. After creating the server click on `explorer` and this should bring you to the Graphiql explorer.
3232

33-
For a query to work first you need to make an Article node. Create one with the title "Hello GraphQL" and save it.
33+
To be able to query something you first have to create an Article in the Drupal backend.
3434

3535
4. **Read the comments** and then enter the following query in the left pane:
3636

@@ -59,6 +59,6 @@ For a query to work first you need to make an Article node. Create one with the
5959
6060
**NOTES:**
6161
62-
* The GraphiQL explorer, included with the module, is your friend, it’s amazing. You will most likely use the GraphiQL explorer to build and test more complicated queries.
63-
* GraphQL is introspective, meaning that the entire schema \(data model\) is known up front. This is important as it allows tools like GraphiQL to implement autocompletion.
62+
* The GraphiQL explorer, included with the module, is your friend, it’s amazing. You will most likely use the GraphiQL explorer to build and test more complicated queries.
63+
* GraphQL is introspective, meaning that the entire schema \(data model\) is known up front. This is important as it allows tools like GraphiQL to implement autocompletion.
6464
* You can use GraphiQL to explore your way through the data and configuration, once you know the basic GraphQL syntax. You can use the tab key in the explorer like you would with autocompletion or intellisense in modern IDEs.

doc/producers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The following code is an example of how a data producer for a creator field on t
3838

3939
Essentially this is what you need to do every time you want to make a field available in the schema. We tell Drupal where and how to get the data and specify where this maps to.
4040

41-
This particular resolver uses the `property_path` data producer that comes with the GraphQL module. It's one of the most common ones and you will find yourself using often to resolve any kind of property on an entity. The module includes a lot more which we will see in the "Built in Data Producers" section.
41+
This particular resolver uses the `property_path` data producer that comes with the GraphQL module. It's one of the most common ones and you will find yourself using it often to resolve any kind of property on an entity. The module includes a lot more which we will see in the "Built in Data Producers" section.
4242

4343
## Notes
4444

doc/queries/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Queries
22

3-
Queries in Drupal GraphQL work by combining data producers in order to resolve values of fields added to the schema. As we have already seen in previous examples its in most cases a 2-step process of first adding the schema information and then resolving whatever we added in the schema to actual data.
3+
Queries in the graphql module work by combining data producers in order to resolve values of fields that are added to the schema. As we have already seen in previous examples, it's in most cases a 2-step process of first adding the schema information and then resolving whatever we added in the schema to actual data.
44

5-
In this section we will learn how to use the built-in data producers to resolve common data required by most websites or application that will use GraphQL. The code with all the demo queries and mutations in these docs can be found in [this repository](https://github.com/joaogarin/mydrupalgql).
5+
In this section we will learn how to use the built-in data producers to resolve common data as it is required by most web application that use GraphQL. The code with all the demo queries and mutations in these docs can be found in [this repository](https://github.com/joaogarin/mydrupalgql).
66

7-
Lets quickly look again at a simple field on an existing entity like the "Article" content type that comes with Drupal. First we make that field available in the schema, lets take as an example the title :
7+
Let's take a look at a simple field on an existing entity like the "Article" content type that comes with Drupal. As a first step, we include this field in the schema. Let's take the title as an example:
88

99
```
1010
type Article implements NodeInterface {
@@ -14,9 +14,9 @@ type Article implements NodeInterface {
1414
}
1515
```
1616

17-
We now need to resolve the title field via data producer provided by the module `entity_label` which will give us the label of an entity :
17+
We now need to resolve the title field via a data producer which is already provided by the `entity_label` module. This will give us the label of an entity:
1818

19-
```php
19+
```php
2020
$registry->addFieldResolver('Article', 'title',
2121
$builder->produce('entity_label', [
2222
'mapping' => [
@@ -26,15 +26,17 @@ We now need to resolve the title field via data producer provided by the module
2626
);
2727
```
2828

29-
We now can run a query like this :
29+
We can now run a query like this:
3030

3131
```graphql
32-
article(id:1) {
33-
title
32+
query {
33+
article(id:1) {
34+
title
35+
}
3436
}
3537
```
3638

37-
and get something like :
39+
and get the following result:
3840

3941
```json
4042
{
@@ -46,4 +48,4 @@ and get something like :
4648
}
4749
```
4850

49-
Next we will look at more complex scenarios like loading custom fields, menus and menu links, taxonomies and other kind of fields.
51+
Next, we will look at more complex scenarios like loading custom fields, menus, menu links, taxonomies and other kind of fields.

doc/queries/menus.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Querying menus
22

3-
Another common use case you will run need is to query a menu, this is particularly useful for use cases where you will want to control or add items via the backend in the drupal administration interface.
3+
Another common use case you will often need is to query a menu. This is particularly useful for use cases where you will want to control or add items via the backend in the Drupal administration interface.
44

55
## Add the schema declaration
66

7-
The first step as seen in the introduction is to add the types and fields in the schema. We can do this directly in the schema string in your own schema implementation.
7+
The first step, as seen in the introduction, is to add the types and fields in the schema. We can do this directly in the schema string in your own schema implementation (`src/Plugin/GraphQL/Schema/SdlSchemaMyDrupalGql.php`).
88

99
```
1010
...
@@ -124,4 +124,4 @@ To add the resolvers we go to our schema implementation and call the appropriate
124124
}
125125
```
126126

127-
As we see here we need to really provide all the fields with a resolver in order to have the data available, this can seem a bit unnecessary at first but its a crucial step towards a cleaner API. In this case we resolve the `menu` inside the `Query` type and from there we start resolving each field from `Menu` and also `MenuItem`.
127+
As we can see here we need to really provide all the fields with a resolver in order to have the data available, this can seem a bit unnecessary at first but it's a crucial step towards a cleaner API. In this case, we resolve the `menu` inside the `Query` type and from there we can start resolving each field from `Menu` and also `MenuItem`.

doc/queries/nodes.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Querying nodes
22

3-
One common scenarios you will run into is to query a node together with certain fields. We have seen already a couple of things that can give a good overview on how to do this, but lets take an example again of the "Article" type and get some fields out of it like the `id` and `label` but also a custom field `creator` which is just a normal text field in this content type.
3+
A common scenario into which you will run often is to query a node together with certain field. We have already seen a couple of things that can give a good overview on how to do this. Let's take our example of the "Article" type again and query some fields like the `id`, the `label` but also the custom field `creator` which is just a normal text field.
44

5-
Before this make sure to read the introduction and how to add you own custom schema, only after that you can start adding resolvers and extending your DSL with your own types.
5+
Before you start, make sure to read the introduction and how to add a custom schema, only after that you should start adding resolvers and extending your schema with your own types.
66

77
## Add the schema declaration
88

9-
The first step as seen in the introduction is to add the types and fields in the schema. We can do this directly in the schema string in your own schema implementation.
9+
The first step, as seen in the introduction, is to add the types and fields in the schema. You can add this directly into schema string in your own schema implementation (`src/Plugin/GraphQL/Schema/SdlSchemaMyDrupalGql.php`).
1010

1111
```
1212
schema {
@@ -31,7 +31,8 @@ interface NodeInterface {
3131
id: Int!
3232
}
3333
```
34-
Now we have an article in the schema with 3 fields `id`, `label` and our custom field `creator`. We can start adding resolvers for each of them.
34+
35+
Now we have an "Article" type in the schema with three fields `id`, `label` and our custom field `creator`. The next step is to add resolvers for each of them.
3536

3637
## Adding resolvers
3738

doc/queries/references.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Querying entity references
22

3-
Continuing on our previous example lets add a new field that in this case is an entity reference for example for a taxonomy term.
3+
Continuing on our previous example let's add a new field that is an entity reference for a taxonomy term.
44

5-
Again we need to do similar steps to add the field to the schema and add its resolver.
5+
We again need to do similar steps to add the field to the schema and add its resolver.
66

77
## Add the schema declaration
88

9-
The first step as seen in the introduction is to add the types and fields in the schema. We can do this directly in the schema string in your own schema implementation.
9+
The first step as seen in the introduction is to add the types and fields in the schema. We can do this directly in the schema string in your own schema implementation (`src/Plugin/GraphQL/Schema/SdlSchemaMyDrupalGql.php`).
1010

1111
```
1212
...
@@ -26,9 +26,9 @@ type TagTerm {
2626
...
2727
2828
```
29-
Now we have an article that also has a custom entity reference field to a taxonomy category (the field name in Drupal is `field_tags`) and we make a new type `TagTerm` that has the necessary information about this term.
29+
Now we have an article that also has a custom entity reference field to a taxonomy term (the field name in Drupal is `field_tags`) and we make a new type `TagTerm` that has the necessary information about this term.
3030

31-
We will need to resolve not only the `tags` field but also the `id` and `name` of the term.
31+
We will need to resolve not only the `tags` field but also the `id` and `name` of the term.
3232

3333
## Adding resolvers
3434

@@ -39,9 +39,9 @@ Again inside the `getResolverRegistry` method :
3939
* {@inheritdoc}
4040
*/
4141
protected function getResolverRegistry() {
42-
42+
4343
...
44-
44+
4545
$registry->addFieldResolver('Article', 'tags',
4646
$builder->produce('entity_reference', [
4747
'mapping' => [
@@ -69,4 +69,4 @@ Again inside the `getResolverRegistry` method :
6969
}
7070
```
7171

72-
Notice how again we are using common Data producers provided by the module like `entity_id`, `entity_label` and also `entity_reference` in this case.
72+
Notice how again we are using common data producers provided by the module like `entity_id`, `entity_label` and also `entity_reference` in this case.

doc/queries/routes.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Querying routes
22

3-
A very powerful feature of Drupal is the ability to manage paths in entities and using path alias to manage clean URL's. We can leverage Data producers provided by the GraphQL module to get that data out of Drupal.
3+
A very powerful feature of Drupal is the ability to manage paths in entities and using path aliases to manage clean URL's. We can leverage data producers provided by the graphql module to query these paths from Drupal.
44

55
In this section we will look at how we can load a node from it's URL.
66

77
## Add the schema declaration
88

9-
The first step as seen in the introduction is to add the types and fields in the schema. We can do this directly in the schema string in your own schema implementation.
9+
The first step, as seen in the introduction, is to add the types and fields in the schema. We can do this directly in the schema string in your own schema implementation (`src/Plugin/GraphQL/Schema/SdlSchemaMyDrupalGql.php`).
1010

1111
```
1212
...
@@ -29,7 +29,7 @@ interface NodeInterface {
2929
3030
```
3131

32-
In this schema we can see that we can query a node by its route, that takes a parameter called "path". We also (similar to the test schema that comes with the module) have a NodeInterface and a Article type that implements that interface. That means our "Article" will be available inside a fragment in the NodeInterface type.
32+
In this schema we can see that we can query a node by its route, that takes a parameter called "path". We also (similar to the test schema that comes with the module) have a "NodeInterface" and an "Article" type that implements that interface. That means our "Article" will be available inside a fragment in the NodeInterface type.
3333

3434
## Adding resolvers
3535

@@ -61,12 +61,12 @@ To add the resolvers we go to our schema implementation and call the appropriate
6161
}
6262
```
6363

64-
Here we take advantage of the `compose` method inside our resolver builder object that allows chaining multiple producers together. This is a very useful technique, that will be very useful when dealing with more complex scenarios.
64+
Here we take advantage of the `compose` method inside our resolver builder object that allows chaining multiple producers together. This technique can be very helpful when dealing with more complex scenarios.
6565

66-
In this example our query could look like this :
66+
In this example our query could look like this :
6767

6868
```graphql
69-
{
69+
query {
7070
route(path: "/node/1") {
7171
... on Article {
7272
id
@@ -76,7 +76,7 @@ In this example our query could look like this :
7676
}
7777
```
7878

79-
and the response :
79+
and the response :
8080

8181
```json
8282
{

doc/starting/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The module requires installation via `composer`in order to pull in the dependenc
55
1. Install the module by running `composer require drupal/graphql:4.x-dev`.
66
2. Enable the GraphQL module in extensions.
77
3. Login and navigate to `/admin/config/graphql` to create a new server.
8-
4. At this point you can either start with the test schema provided by the module (see the Introduction section) or start right away making your own custom schema as we will describe in the following sections.
8+
4. At this point you can either start with the "Example schema" provided by the graphql_examples module (see the Introduction section) or start right away making your own custom schema as we will describe in the following sections.
99

1010
## Dependencies
1111

doc/starting/custom-schema.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Creating a custom schema
22

3-
The best way to start making a new schema is to take the test schema provided by the graphql module in `src/Plugin/GraphQL/Schema/SdlSchemaTest.php` and add it to a custom module of your own. By doing this you can then start adapting the schema to your needs including your own content types and making them available in the schema.
3+
The best way to start making a new schema is to take the example schema provided by the graphql_examples module in `/graphql/examples/` and copy all the files from the example module to a custom module of your own. By doing this you can then start adapting the schema to your needs including your own content types and making them available in the schema.
44

5-
The code including all the demo queries and mutations from these docs can be found in [this repository](https://github.com/joaogarin/mydrupalgql).
6-
7-
## Clone the SdlSchemaTest
5+
## Clone the SdlSchemaTest (deprecated)
86

97
First create your own module and call it `mydrupalgql`. Make sure you have a .info file inside the module to make sure drupal will know about this module (for more info see [Custom modules in drupal](https://www.drupal.org/docs/8/creating-custom-modules)).
108
Then head to the graphql module folder and copy the content of `src/Plugin/GraphQL/Schema/SdlSchemaTest.php`.

0 commit comments

Comments
 (0)