From 9c02b26e38c03f81d7e51f6b2010042e15130054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20=C4=90=E1=BB=A9c=20H=C3=A0o?= <39975444+haond10adp@users.noreply.github.com> Date: Sat, 23 Jan 2021 08:07:01 +0700 Subject: [PATCH 1/2] Update Tutorial-ObjectTypes.md typo --- docs/Tutorial-ObjectTypes.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/Tutorial-ObjectTypes.md b/docs/Tutorial-ObjectTypes.md index 246aa67a51..6aa8c7fd84 100644 --- a/docs/Tutorial-ObjectTypes.md +++ b/docs/Tutorial-ObjectTypes.md @@ -16,22 +16,22 @@ type Query { } ``` -If we wanted to have more and more methods based on a random die over time, we could implement this with a `RandomDie` object type instead. +If we wanted to have more and more methods based on a random dice over time, we could implement this with a `RandomDice` object type instead. ```graphql -type RandomDie { +type RandomDice { roll(numRolls: Int!): [Int] } type Query { - getDie(numSides: Int): RandomDie + getDice(numSides: Int): RandomDice } ``` -Instead of a root-level resolver for the `RandomDie` type, we can instead use an ES6 class, where the resolvers are instance methods. This code shows how the `RandomDie` schema above can be implemented: +Instead of a root-level resolver for the `RandomDice` type, we can instead use an ES6 class, where the resolvers are instance methods. This code shows how the `RandomDice` schema above can be implemented: ```js -class RandomDie { +class RandomDice { constructor(numSides) { this.numSides = numSides; } @@ -50,8 +50,8 @@ class RandomDie { } var root = { - getDie: function ({ numSides }) { - return new RandomDie(numSides || 6); + getDice: function ({ numSides }) { + return new RandomDice(numSides || 6); }, }; ``` @@ -59,14 +59,14 @@ var root = { For fields that don't use any arguments, you can use either properties on the object or instance methods. So for the example code above, both `numSides` and `rollOnce` can actually be used to implement GraphQL fields, so that code also implements the schema of: ```graphql -type RandomDie { +type RandomDice { numSides: Int! rollOnce: Int! roll(numRolls: Int!): [Int] } type Query { - getDie(numSides: Int): RandomDie + getDice(numSides: Int): RandomDice } ``` @@ -79,19 +79,19 @@ var { buildSchema } = require('graphql'); // Construct a schema, using GraphQL schema language var schema = buildSchema(` - type RandomDie { + type RandomDice { numSides: Int! rollOnce: Int! roll(numRolls: Int!): [Int] } type Query { - getDie(numSides: Int): RandomDie + getDice(numSides: Int): RandomDice } `); -// This class implements the RandomDie GraphQL type -class RandomDie { +// This class implements the RandomDice GraphQL type +class RandomDice { constructor(numSides) { this.numSides = numSides; } @@ -111,8 +111,8 @@ class RandomDie { // The root provides the top-level API endpoints var root = { - getDie: function ({ numSides }) { - return new RandomDie(numSides || 6); + getDice: function ({ numSides }) { + return new RandomDice(numSides || 6); }, }; @@ -130,11 +130,11 @@ app.listen(4000, () => { }); ``` -When you issue a GraphQL query against an API that returns object types, you can call multiple methods on the object at once by nesting the GraphQL field names. For example, if you wanted to call both `rollOnce` to roll a die once, and `roll` to roll a die three times, you could do it with this query: +When you issue a GraphQL query against an API that returns object types, you can call multiple methods on the object at once by nesting the GraphQL field names. For example, if you wanted to call both `rollOnce` to roll a dice once, and `roll` to roll a dice three times, you could do it with this query: ```graphql { - getDie(numSides: 6) { + getDice(numSides: 6) { rollOnce roll(numRolls: 3) } From 7716f5bf1dda1492e902709c07e9605c8cac8383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20=C4=90=E1=BB=A9c=20H=C3=A0o?= <39975444+haond10adp@users.noreply.github.com> Date: Sat, 23 Jan 2021 12:04:55 +0700 Subject: [PATCH 2/2] Update Tutorial-ObjectTypes.md --- docs/Tutorial-ObjectTypes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Tutorial-ObjectTypes.md b/docs/Tutorial-ObjectTypes.md index 6aa8c7fd84..1cf2951773 100644 --- a/docs/Tutorial-ObjectTypes.md +++ b/docs/Tutorial-ObjectTypes.md @@ -70,7 +70,7 @@ type Query { } ``` -Putting this all together, here is some sample code that runs a server with this GraphQL API: +Putting this altogether, here is some sample code that runs a server with this GraphQL API: ```js var express = require('express');