Skip to content

Commit bae096a

Browse files
committed
Rest of the docs
1 parent 84b9e51 commit bae096a

File tree

2 files changed

+81
-7
lines changed

2 files changed

+81
-7
lines changed

docs/getting-started.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,31 @@ public class CharacterInterface : InterfaceGraphType<StarWarsCharacter>
348348

349349
# Variables
350350

351-
TODO
351+
You can pass variables recieved from the client to the execution engine by using the `Inputs` property.
352+
353+
```csharp
354+
var inputs = variablesJson.ToInputs();
355+
356+
var result = await executer.ExecuteAsync(_ =>
357+
{
358+
_.Inputs = inputs;
359+
});
360+
```
352361

353362
# Query Validation
354363

355-
TODO
364+
There [are a number of query validation rules](http://facebook.github.io/graphql/#sec-Validation) that are ran when a query is executed. All of these are turned on by default. You can add your own validation rules or clear out the existing ones by accessing the `ValidationRules` property.
365+
366+
```csharp
367+
var result = await executer.ExecuteAsync(_ =>
368+
{
369+
_.ValidationRules = new[] {new RequiresAuthValidationRule()}.Concat(DocumentValidator.CoreRules());
370+
});
371+
```
356372

357373
# Subscriptions
358374

359-
The Schema class supports a Subscription property and the parser supports the `subscription` type. Subscriptions are an experimental feature of the GraphQL specification.
375+
The Schema class supports a Subscription graph type and the parser supports the `subscription` keyword. Subscriptions are an experimental feature of the GraphQL specification.
360376

361377
```graphql
362378
subscription comments($repoName: String!) {

docs/learn.md

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,70 @@
11
# Error Handling
22

3-
TODO
3+
The `ExecutionResult` provides an `Errors` property which includes any errors encountered during exectution. Errors are returned [according to the spec](http://facebook.github.io/graphql/#sec-Errors), which means stack traces are excluded. The `ExecutionResult` is transformed to what the spec requires using JSON.NET. You can change what information is provided by overriding the JSON Converter.
4+
5+
You can provide additional error handling or logging for fields by adding Field Middleware.
46

57
# User Context
68

7-
TODO
9+
You can provide a `UserContext` to provide access to your specific data. The `UserContext` is accessible in field resolvers and validation rules.
10+
11+
```csharp
12+
public class GraphQLUserContext
13+
{
14+
}
15+
16+
var result = await _executer.ExecuteAsync(_ =>
17+
{
18+
_.UserContext = new GraphQLUserContext();
19+
}).ConfigureAwait(false);
20+
21+
Field<ListGraphType<DinnerType>>(
22+
"popularDinners",
23+
resolve: context =>
24+
{
25+
var userContext = context.UserContext.As<GraphQLUserContext>();
26+
});
27+
```
828

929
# Dependency Injection
1030

11-
TODO
31+
GraphQL .NET supports dependency injection through a simple resolve function on the Schema class. Internally when trying to resolve a type the library will call this resolve function.
32+
33+
34+
35+
The default implementation uses `Activator.CreateInstance`.
36+
37+
```csharp
38+
type => (GraphType) Activator.CreateInstance(type)
39+
```
40+
41+
How you integrate this into your system will depend on the dependency injection framework you are using. Registering your schema with a resolve function that accesses your container may look something like this:
42+
43+
```csharp
44+
// Nancy TinyIoCContainer
45+
container.Register((c, overloads) =>
46+
{
47+
return new NerdDinnerSchema(type => c.Resolve(type) as IGraphType);
48+
});
49+
50+
// SimpleContainer
51+
var container = new SimpleContainer();
52+
container.Singleton(new StarWarsSchema(type => container.Get(type) as IGraphType));
53+
```
54+
55+
[The GraphiQL sample application uses Dependency Injection.](https://github.com/graphql-dotnet/graphql-dotnet/blob/master/src/GraphQL.GraphiQL/Bootstrapper.cs)
56+
57+
```csharp
58+
public class NerdDinnerSchema : GraphQL.Types.Schema
59+
{
60+
public NerdDinnerSchema(Func<Type, IGraphType> resolve)
61+
: base(resolve)
62+
{
63+
Query = (IObjectGraphType)resolve(typeof(Query));
64+
Mutation = (IObjectGraphType)resolve(typeof(Mutation));
65+
}
66+
}
67+
```
1268

1369
# Object/Field Metadata
1470

@@ -241,4 +297,6 @@ var report = StatsReport.From(schema, result.Operation, result.Perf, start);
241297

242298
# Relay
243299

244-
TODO
300+
The core project provides a few classes to help with Relay. You can find more types and helpers [here](https://github.com/graphql-dotnet/relay).
301+
302+
(Example needed)

0 commit comments

Comments
 (0)