Skip to content

Commit 1e2cbbc

Browse files
author
monica.lopez-gris
committed
fix doc
1 parent c6035b0 commit 1e2cbbc

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

documentation/Home.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ toc::[]
4141
- link:guides-logger.asciidoc[Logger]
4242
- link:guides-mailer.asciidoc[Mailer Module]
4343
- link:guides-eslint-sonarqube-config[ESLint SonarQube Configuration]
44+
- link:guides-graphql[GraphQL]
4445

4546
== devon4node applications
4647

documentation/guides-grapql.asciidoc

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ For example, on a regular API a get by id method would return something like:
4040
----
4141
But if we want to get *only* the wind data we have to create another endpoint that returns the specified data.
4242

43-
But instead with graphQL we can get different information without creating new endpoints, in this case we only want the wind data so:
43+
But instead with graphQL we can get different information without creating new endpoints, in this case we only want the wind data so it would return:
4444

4545
[source, json]
4646
----
@@ -67,10 +67,9 @@ This tutorial uses the schema first method.
6767
6868
We assume you have already a functioning TODO module / app.
6969
70-
If not you can use https://github.com/devonfw/devon4node/wiki/samples#devon4node-samples[Devon4node TODO sample]
70+
If not you can use https://github.com/devonfw/devon4node/tree/develop/samples/graphql[Devon4node GraphQL sample]
7171
====
7272

73-
7473
First we need to import GraphQLModule to our `app.module.ts`.
7574

7675
[source,typescript]
@@ -100,8 +99,14 @@ The `definitions` indicates the file where the typescript definitions will autom
10099

101100
=== Schema
102101

102+
Graphql is a typed language with `object types`, `scalars`, and `enums`.
103+
104+
We use `querys` to define the methods we are going to use for fetching data, and `mutations` are used for modifying this data, similar to how `GET` and `POST` work.
105+
103106
Let's define the elements, querys and mutations that our module is going to have.
104107

108+
For that we have to create a graphql file on our module, on this case we are going to name it "schema.graphql".
109+
105110
[source,typescript]
106111
----
107112
type Todo {
@@ -120,11 +125,14 @@ type Mutation {
120125
}
121126
----
122127

128+
For more information about Types go to the official https://graphql.org/learn/schema/[graphQL documentation]
129+
130+
123131
=== Resolver
124132

125133
Resolvers has the instructions to turn GraphQL orders into the data requested.
126134

127-
To create a resolver we go to our module and then create a new `todo.resolver.ts` file, import the decorators needed and set our resolver.
135+
To create a resolver we go to our module and then create a new `todo.resolver.ts` file, import the decorators needed and set the resolver.
128136

129137
[source,typescript]
130138
----
@@ -166,7 +174,7 @@ export class TodoResolver {
166174

167175
Here we have also an argument decorator `@Args` which is an object with the arguments passed into the field in the query.
168176

169-
By default we can access the query or mutation using it's name, for example:
177+
By default we can access the query or mutation using the method's name, for example:
170178

171179
For the `deleteTodo` mutation.
172180

@@ -199,9 +207,9 @@ Learn more about resolvers, mutations and their argument decorators on the https
199207

200208
=== Playground
201209

202-
The playground allow us to test or resolvers, we can access by default on `http://localhost:3000/graphql`.
210+
To test our backend we can use tools as Postman, but graphql already gives us a playground to test our resolvers, we can access by default on `http://localhost:3000/graphql`.
203211

204-
We can call a query this way:
212+
We can call a query, or several querys this way:
205213

206214
[source,typescript]
207215
----
@@ -249,7 +257,7 @@ mutation{
249257

250258
And the output
251259

252-
[source,typescript]
260+
[source,json]
253261
----
254262
{
255263
"data": {
@@ -260,4 +268,18 @@ And the output
260268
}
261269
----
262270

263-
In this case we return just one item so there is no array, we also got just the `task data` but if we want the `id too, we just have to add it on the request.
271+
In this case we return just one item so there is no array, we also got just the `task data` but if we want the `id` too, we just have to add it on the request.
272+
273+
To make the playground unavailable we can add an option to the app.module import:
274+
275+
[source,typescript]
276+
----
277+
...
278+
GraphQLModule.forRoot({
279+
...
280+
playground: false,
281+
}),
282+
...
283+
----
284+
285+
For further information go to the official https://docs.nestjs.com/graphql/quick-start[NestJS documentation]

samples/graphql-schema-first

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)