Skip to content

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

Merged
merged 2 commits into from
Sep 15, 2016
Merged

fix missing return types #85

merged 2 commits into from
Sep 15, 2016

Conversation

lacker
Copy link
Contributor

@lacker lacker commented Sep 15, 2016

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.

Copy link
Collaborator

@leebyron leebyron left a 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
Copy link
Collaborator

@leebyron leebyron Sep 15, 2016

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

Copy link
Contributor Author

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:
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@lacker lacker merged commit ecd6e6b into graphql:source Sep 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants