Skip to content

Commit 0703dac

Browse files
committed
Document errors when type aliases for custom scalars are missing (closes #320)
1 parent de80139 commit 0703dac

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
@@ -102,7 +102,19 @@ struct UnionQuery;
102102

103103
## Custom scalars
104104

105-
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.
105+
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.
106+
107+
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:
108+
109+
```
110+
error[E0412]: cannot find type `URI` in module `super`
111+
|
112+
| #[derive(GraphQLQuery)]
113+
| ^^^^^^^^^^^^ not found in `super`
114+
|
115+
= note: possible candidate is found in another module, you can import it into scope:
116+
crate::repo_view::URI
117+
```
106118

107119
## Deprecations
108120

0 commit comments

Comments
 (0)