You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
32
32
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.
34
34
35
35
4.**Read the comments** and then enter the following query in the left pane:
36
36
@@ -59,6 +59,6 @@ For a query to work first you need to make an Article node. Create one with the
59
59
60
60
**NOTES:**
61
61
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.
64
64
* 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.
Copy file name to clipboardExpand all lines: doc/producers/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ The following code is an example of how a data producer for a creator field on t
38
38
39
39
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.
40
40
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.
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.
4
4
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).
6
6
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:
8
8
9
9
```
10
10
type Article implements NodeInterface {
@@ -14,9 +14,9 @@ type Article implements NodeInterface {
14
14
}
15
15
```
16
16
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:
18
18
19
-
```php
19
+
```php
20
20
$registry->addFieldResolver('Article', 'title',
21
21
$builder->produce('entity_label', [
22
22
'mapping' => [
@@ -26,15 +26,17 @@ We now need to resolve the title field via data producer provided by the module
26
26
);
27
27
```
28
28
29
-
We now can run a query like this :
29
+
We can now run a query like this:
30
30
31
31
```graphql
32
-
article(id:1) {
33
-
title
32
+
query {
33
+
article(id:1) {
34
+
title
35
+
}
34
36
}
35
37
```
36
38
37
-
and get something like :
39
+
and get the following result:
38
40
39
41
```json
40
42
{
@@ -46,4 +48,4 @@ and get something like :
46
48
}
47
49
```
48
50
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.
Copy file name to clipboardExpand all lines: doc/queries/menus.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Querying menus
2
2
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.
4
4
5
5
## Add the schema declaration
6
6
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`).
8
8
9
9
```
10
10
...
@@ -124,4 +124,4 @@ To add the resolvers we go to our schema implementation and call the appropriate
124
124
}
125
125
```
126
126
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`.
Copy file name to clipboardExpand all lines: doc/queries/nodes.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Querying nodes
2
2
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.
4
4
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.
6
6
7
7
## Add the schema declaration
8
8
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`).
10
10
11
11
```
12
12
schema {
@@ -31,7 +31,8 @@ interface NodeInterface {
31
31
id: Int!
32
32
}
33
33
```
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.
Copy file name to clipboardExpand all lines: doc/queries/references.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Querying entity references
2
2
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.
4
4
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.
6
6
7
7
## Add the schema declaration
8
8
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`).
10
10
11
11
```
12
12
...
@@ -26,9 +26,9 @@ type TagTerm {
26
26
...
27
27
28
28
```
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.
30
30
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.
32
32
33
33
## Adding resolvers
34
34
@@ -39,9 +39,9 @@ Again inside the `getResolverRegistry` method :
39
39
* {@inheritdoc}
40
40
*/
41
41
protected function getResolverRegistry() {
42
-
42
+
43
43
...
44
-
44
+
45
45
$registry->addFieldResolver('Article', 'tags',
46
46
$builder->produce('entity_reference', [
47
47
'mapping' => [
@@ -69,4 +69,4 @@ Again inside the `getResolverRegistry` method :
69
69
}
70
70
```
71
71
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.
Copy file name to clipboardExpand all lines: doc/queries/routes.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Querying routes
2
2
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.
4
4
5
5
In this section we will look at how we can load a node from it's URL.
6
6
7
7
## Add the schema declaration
8
8
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`).
10
10
11
11
```
12
12
...
@@ -29,7 +29,7 @@ interface NodeInterface {
29
29
30
30
```
31
31
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.
33
33
34
34
## Adding resolvers
35
35
@@ -61,12 +61,12 @@ To add the resolvers we go to our schema implementation and call the appropriate
61
61
}
62
62
```
63
63
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.
65
65
66
-
In this example our query could look like this :
66
+
In this example our query could look like this :
67
67
68
68
```graphql
69
-
{
69
+
query{
70
70
route(path: "/node/1") {
71
71
...onArticle {
72
72
id
@@ -76,7 +76,7 @@ In this example our query could look like this :
Copy file name to clipboardExpand all lines: doc/starting/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ The module requires installation via `composer`in order to pull in the dependenc
5
5
1. Install the module by running `composer require drupal/graphql:4.x-dev`.
6
6
2. Enable the GraphQL module in extensions.
7
7
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.
Copy file name to clipboardExpand all lines: doc/starting/custom-schema.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,8 @@
1
1
# Creating a custom schema
2
2
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.
4
4
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)
8
6
9
7
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)).
10
8
Then head to the graphql module folder and copy the content of `src/Plugin/GraphQL/Schema/SdlSchemaTest.php`.
0 commit comments