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: README.md
+18-11Lines changed: 18 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -71,12 +71,12 @@ var schema = GraphQL<TestContext>.CreateDefaultSchema(() => new TestContext());
71
71
The default schema is required to use the helper method`GraphQL<TContext>.Execute(query)`, but you can execute queries against the schema without it. Next, we'll define a type in the schema and fields on that type.
Fields can be defined using only a property expression, or you can specify your own fields and provide a custom resolving expression. Let's do the same for account:
If we just want to expose all fields, we can use the `AddAllFields` helper method.
89
89
90
-
The last thing we want to do is create some queries. Let's add some to find users:
90
+
The last thing we want to do is create some queries, as fields on the schema itself. Let's add some to find users:
91
91
92
92
```csharp
93
-
schema.AddQuery("users", db=>db.Users);
94
-
schema.AddQuery("user", new { id=0 }, (db, args) =>db.Users.Where(u=>u.Id==args.id).FirstOrDefault());
93
+
schema.AddListField("users", db=>db.Users);
94
+
schema.AddField("user", new { id=0 }, (db, args) =>db.Users.Where(u=>u.Id==args.id).FirstOrDefault());
95
95
```
96
96
97
-
In our first query, we want to see all users so we can just return the entire list. However, notice how in the second query we define the shape of an anonymous type `new { id = 0 }`. This is what is expected to be passed in from the GraphQL query. Since we've defined the shape, we can now use that in the `Where` clause to build our IQueryable. We use `FirstOrDefault` to signify that this query will return a single result. Now we're ready to execute a query.
97
+
In our first query, we want to see all users so we can just return the entire list. However, notice how in the second query we define the shape of an anonymous type `new { id = 0 }`. This is what is expected to be passed in from the GraphQL query. Since we've defined the shape, we can now use that in the `Where` clause to build our IQueryable. We use `FirstOrDefault` to signify that this query will return a single result.
98
+
99
+
```csharp
100
+
schema.Complete();
101
+
```
102
+
103
+
Finally, we complete the schema when we've finished setting up. Now we're ready to execute a query.
0 commit comments