Skip to content

Commit a781420

Browse files
authored
Merge pull request #377 from noritada/doc-updates-on-type-aliases-for-custom-scalars
Document errors when type aliases for custom scalars are missing
2 parents 40e6f93 + 0703dac commit a781420

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,19 @@ struct UnionQuery;
110110

111111
## Custom scalars
112112

113-
The generated code will reference the scalar types as defined in the server schema. This means you have to provide matching rust types in the scope of the struct under derive. It can be as simple as declarations like `type Email = String;`. This gives you complete freedom on how to treat custom scalars, as long as they can be deserialized.
113+
In GraphQL, five scalar types, `Int`, `Float`, `String`, `Boolean`, and `ID`, are available out of the box and are automatically mapped to equivalent types in Rust. However, in addition, custom scalar types can be defined by service providers by adding declarations like `scalar URI` to the server schema.
114+
115+
If such custom scalar types are defined in the schema, depending on the content of the query, the generated code will also reference those scalar types. This means you have to provide matching Rust types in the scope of the struct under derive. It can be as simple as declarations like `type URI = String;`. This gives you complete freedom on how to treat custom scalars, as long as they can be deserialized. If such declarations are not provided, you will get build errors like this:
116+
117+
```
118+
error[E0412]: cannot find type `URI` in module `super`
119+
|
120+
| #[derive(GraphQLQuery)]
121+
| ^^^^^^^^^^^^ not found in `super`
122+
|
123+
= note: possible candidate is found in another module, you can import it into scope:
124+
crate::repo_view::URI
125+
```
114126

115127
## Deprecations
116128

0 commit comments

Comments
 (0)