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
Rework codegen for GraphQL objects and subscriptions (#971, #421)
- preserve and reuse defined impl blocks in #[graphql_object] and #[graphql_subscription] macros expansion
- allow renaming `ScalarValue` type parameter in expanded code via `scalar = S: ScalarValue` syntax
Additionally:
- rename `rename` attribute's argument to `rename_all`
- support `rename_all` in #[graphql_interface] macro
These, and more features, are described more thoroughly in [the reference documentation](https://docs.rs/juniper/latest/juniper/attr.graphql_object.html).
Copy file name to clipboardExpand all lines: docs/book/content/types/objects/defining_objects.md
+20-5
Original file line number
Diff line number
Diff line change
@@ -152,7 +152,22 @@ struct Person {
152
152
name:String,
153
153
age:i32,
154
154
#[graphql(name ="websiteURL")]
155
-
website_url:Option<String>, // Now exposed as websiteURL in the schema
155
+
website_url:Option<String>, // now exposed as `websiteURL` in the schema
156
+
}
157
+
#
158
+
# fnmain() {}
159
+
```
160
+
161
+
Or provide a different renaming policy on a struct for all its fields:
162
+
```rust
163
+
# externcrate juniper;
164
+
# usejuniper::GraphQLObject;
165
+
#[derive(GraphQLObject)]
166
+
#[graphql(rename_all ="none")] // disables any renaming
167
+
structPerson {
168
+
name:String,
169
+
age:i32,
170
+
website_url:Option<String>, // now exposed as `website_url` in the schema
156
171
}
157
172
#
158
173
# fnmain() {}
@@ -181,9 +196,9 @@ The `name`, `description`, and `deprecation` arguments can of course be
181
196
combined. Some restrictions from the GraphQL spec still applies though; you can
182
197
only deprecate object fields and enum values.
183
198
184
-
## Skipping fields
199
+
## Ignoring fields
185
200
186
-
By default all fields in a `GraphQLObject` are included in the generated GraphQL type. To prevent including a specific field, annotate the field with `#[graphql(skip)]`:
201
+
By default, all fields in a `GraphQLObject` are included in the generated GraphQL type. To prevent including a specific field, annotate the field with `#[graphql(ignore)]`:
187
202
188
203
```rust
189
204
# externcrate juniper;
@@ -192,9 +207,9 @@ By default all fields in a `GraphQLObject` are included in the generated GraphQL
192
207
structPerson {
193
208
name:String,
194
209
age:i32,
195
-
#[graphql(skip)]
210
+
#[graphql(ignore)]
196
211
# #[allow(dead_code)]
197
-
password_hash:String, //This cannot be queried or modified from GraphQL
212
+
password_hash:String, // cannot be queried or modified from GraphQL
0 commit comments