-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix missing return types #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
|
||
```javascript | ||
type Mutation { | ||
setMessage(message: String) | ||
setMessage(message: String): Boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More typically graphql mutations return the thing they were mutating so clients can be aware of anything the server did (maybe you lost a race condition with set-message with someone else, or maybe the server did some post-processing) but also as a convenient mechanism to keep a client cache up to date.
That's perhaps overkill here, and illustrating that it's okay to return a boolean is good, but something like this should probably be mentioned here in reference to the fuller example you have below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK i changed the example and mentioned this a bit in the text
@@ -36,25 +39,33 @@ var root = { | |||
|
|||
You don't need anything more than this to implement mutations. But in many cases, you will find a number of different mutations that all accept the same input parameters. A common example is that creating an object in a database and updating an object in a database often take the same parameters. To make your schema simpler, you can use “input types” for this, by using the `input` keyword instead of the `type` keyword. | |||
|
|||
For example, instead of a single message of the day, let's say we have one message per author, where the author is just a unique username, and we want a mutation API both for creating a new message and for updating an old message. We could use the schema: | |||
For example, instead of a single message of the day, let's say we have many messages, indexed in a database by an `ID`, and each message has both a `content` string and an `author` string. We want a mutation API both for creating a new message and for updating an old message. We could use the schema: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lowercase id
to match the field name you're referencing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
When I changed the mutations example to use variables correctly, I broke the return types. This fixes the example to correctly have return types for each endpoint & have separate Message and MessageInput types.