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/enums.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ registerEnum(Direction, {
36
36
37
37
The last step is very important: TypeScript has limited reflection ability, so we have to explicitly provide the enum type both for object/input type fields as well as return type of queries/mutations or arg type:
Copy file name to clipboardExpand all lines: docs/interfaces-and-inheritance.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,10 @@ TypeScript has first class support for interfaces. Unfortunatelly, they exist on
9
9
10
10
Luckily, we can use abstract class for this purpose - it behave almost like an interface (can't be "newed", can be implemented by class), it just won't stop developers from implementing a method or initializing a field. But until we do the same things like with an interface, we can safely use it.
11
11
12
-
So, how to create GraphQL interface definition? We create an abstract class and decorate it with `@GraphQLInterfaceType()`. The rest is exactly the same as with object types - we use `@Field` to declare the shape of the type:
12
+
So, how to create GraphQL interface definition? We create an abstract class and decorate it with `@InterfaceType()`. The rest is exactly the same as with object types - we use `@Field` to declare the shape of the type:
13
13
14
14
```ts
15
-
@GraphQLInterfaceType()
15
+
@InterfaceType()
16
16
abstractclassIPerson {
17
17
@Field(type=>ID)
18
18
id:string;
@@ -28,7 +28,7 @@ abstract class IPerson {
28
28
Then we can use this "interface" in object type class definition:
29
29
30
30
```ts
31
-
@GraphQLObjectType({ implements: IPerson })
31
+
@ObjectType({ implements: IPerson })
32
32
classPersonimplementsIPerson {
33
33
id:string;
34
34
name:string;
@@ -47,7 +47,7 @@ One of the most known principles of software development is DRY - don't repeat y
47
47
48
48
While creating GraphQL API, it's a common pattern to have pagination args in resolvers, like `skip` and `take`. So instead of repeating yourself, you can declare it once:
49
49
```ts
50
-
@GraphQLArgsType()
50
+
@ArgsType()
51
51
classPaginationArgs {
52
52
@Field(type=>Int, { nullable: true })
53
53
skip:number=0;
@@ -59,7 +59,7 @@ class PaginationArgs {
59
59
60
60
and then reuse it everywhere:
61
61
```ts
62
-
@GraphQLArgsType()
62
+
@ArgsType()
63
63
classGetTodosArgsextendsPaginationArgs {
64
64
@Field({ nullable: false })
65
65
onlyCompleted:boolean=false;
@@ -69,7 +69,7 @@ class GetTodosArgs extends PaginationArgs {
69
69
This technique also works with input type classes, as well as with object type classes:
70
70
```ts
71
71
// `Person` is the object type class we've created earlier in this docs
@Field(type=>ObjectIdScalar) // and explicitly use it
114
114
readonly id:ObjectId;
@@ -123,7 +123,7 @@ class User {
123
123
124
124
Optionally, you can delcare the association between reflected property type and your scalars to automatically map them (no need to explicit type annotation!):
125
125
```ts
126
-
@GraphQLObjectType()
126
+
@ObjectType()
127
127
classUser {
128
128
@Field() // magic goes here - no type annotation for custom scalar
Copy file name to clipboardExpand all lines: docs/unions.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ You can read more about GraphQL union type in [official docs](http://graphql.org
7
7
Let's start by creating the object types from example above:
8
8
9
9
```ts
10
-
@GraphQLObjectType()
10
+
@ObjectType()
11
11
classMovie {
12
12
@Field()
13
13
name:string;
@@ -17,7 +17,7 @@ class Movie {
17
17
}
18
18
```
19
19
```ts
20
-
@GraphQLObjectType()
20
+
@ObjectType()
21
21
classActor {
22
22
@Field()
23
23
name:string;
@@ -41,7 +41,7 @@ All that left to do is to use the union type in the query.
41
41
Notice, that due to TypeScript's reflection limitation, you have to explicitly use `SearchResultUnion` value in `@Query` decorator return type annotation.
42
42
For TS compile-time type safety you can also use `typeof SearchResultUnion` which is equal to type `Movie | Actor`.
0 commit comments