Udate docs

This commit is contained in:
Sunli 2020-09-13 11:51:10 +08:00
parent b71833b1a4
commit 13f7126a13
4 changed files with 0 additions and 100 deletions

View File

@ -13,7 +13,6 @@
- [Union](define_union.md)
- [InputObject](define_input_object.md)
- [Default value](default_value.md)
- [Two ways to define types](procedural_macros.md)
- [Schema](define_schema.md)
- [Query and Mutation](query_and_mutation.md)
- [Subscription](subscription.md)

View File

@ -1,49 +0,0 @@
# Two ways to define types
I think you have discovered that GraphQL types can be defined using both an attribute macro and a derive.
The following is the corresponding table:
|Type|Attribute macro|Derive|
|---|-----|----|
|Enum|Enum|GQLEnum|
|Simple Object|SimpleObject|GQLSimpleObject|
|Input Object|InputObject|GQLInputObject|
|Interface|Interface|GQLInterface|
|Union|Union|GQLUnion|
|Merged Object|MergedObject|GQLMergedObject|
|Merged Subscription|MergedSubscription|GQLMergedSubscription|
The advantage of the attribute macro is that you can provide parameters at the same time, for example
```rust
#[SimpleObject(name = "ABC")]
struct MyObject {
value: i32,
}
```
**However, attribute macros do not support conditional compilation**. The following does not work:
```rust
#[SimpleObject]
struct MyObject {
#[cfg(windows)]
value: i32,
#[cfg(not(windows))]
value: i32,
}
```
Deriving, on the other hand, does support conditional compilation, but as derive macros can't take parameters you need to provide them separately. For example:
```rust
#[derive(SimpleObject)]
#[graphql(name = "ABC")]
struct MyObject {
value: i32,
}
```
_Which way you use to define types is up to you, personally I prefer to use derive._

View File

@ -13,7 +13,6 @@
- [联合(Union)](define_union.md)
- [输入对象(InputObject)](define_input_object.md)
- [默认值](default_value.md)
- [定义类型的两种方式](procedural_macros.md)
- [定义模式(Schema)](define_schema.md)
- [查询和变更](query_and_mutation.md)
- [订阅](subscription.md)

View File

@ -1,49 +0,0 @@
# 定义类型的两种方式
我想你已经发现定义一个GraphqlQL类型可以通过属性宏或者派生。
下面是一个对应表:
|类型|属性宏|派生|
|---|-----|----|
|枚举(Enum)|Enum|GQLEnum|
|简单对象(Simple Object)|SimpleObject|GQLSimpleObject|
|输入对象(Input Object)|InputObject|GQLInputObject|
|接口(Interface)|Interface|GQLInterface|
|联合(Union)|Union|GQLUnion|
|合并对象(Merged Object)|MergedObject|GQLMergedObject|
|合并订阅(Merged Subscription)|MergedSubscription|GQLMergedSubscription|
属性宏的好处在于你可以同时提供一些参数,例如:
```rust
#[SimpleObject(name = "ABC")]
struct MyObject {
value: i32,
}
```
但是它不支持条件编译,例如:
```rust
#[SimpleObject]
struct MyObject {
#[cfg(windows)]
value: i32,
#[cfg(not(windows))]
value: i32,
}
```
派生可以支持条件编译,但它需要单独提供参数,例如:
```rust
#[derive(SimpleObject)]
#[graphql(name = "ABC")]
struct MyObject {
value: i32,
}
```
用哪种方式来定义类型取决于你,我更加推荐使用派生。