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
Copy file name to clipboardExpand all lines: docs/source/guides/schema-design.md
+28-15Lines changed: 28 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -296,35 +296,48 @@ Following this pattern for mutations provides detailed information about the dat
296
296
297
297
<h3id="mutation-input-types">Input types</h3>
298
298
299
-
Input types are a special type in GraphQL which are defined as arguments to queries and, more commonly, mutations. They can be thought of as object types for arguments, in addition to the other scalar types. Input types are especially useful when multiple mutations require similar information; for example, when creating a user and updating a user require the same fields, like `age` and `name`.
299
+
Input types are a special type in GraphQL which allows an object to be passed as an argument to both queries and mutations and is helpful when simple scalar types aren't sufficient.
300
300
301
-
Input types are used like any other type and defining them is similar to a typical object type definitions, but with the `input` keyword rather than `type`.
301
+
This allows arguments to be structured in an more manageable way, similar to how switching to an `options` argument might be appreciated when `function` arguments become too iterative.
302
302
303
-
Here is an example of two mutations that operate on a `User`, _without_ using input types:
303
+
For example, consider this mutation which creates a post along with its accompanying media URLs (e.g. images):
304
304
305
-
```
305
+
```graphql
306
306
typeMutation {
307
-
createUser(name: String, age: Int, address: String, phone: String): User
Notonlydoesthisfacilitatepassingthe `PostAndMediaInput` aroundwithintheschema, it also provides a basis for annotating fields with descriptions which are automatically exposed by GraphQL-enabled tools:
328
+
329
+
```graphql
330
+
input PostAndMediaInput {
331
+
"A main title for the post"
332
+
title: String
333
+
"The textual body of the post."
334
+
body: String
335
+
"A list of URLs to render in the post."
336
+
mediaUrls: [String]
325
337
}
326
338
```
327
339
340
+
Input types can also be used when different operations require the exact same information, though we urge caution on over-using this technique since changes to `input` types are breaking changes for all operations which utilize them.
0 commit comments