Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[resolvers]: argument binding to delegate resolvers #1611

Merged
merged 7 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions dev/GraphQL.Dev.Reviews/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using GraphQL.Dev.Reviews;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Tanka.GraphQL.Dev.Reviews;
using Tanka.GraphQL.Extensions.ApolloFederation;
using Tanka.GraphQL.Language;
using Tanka.GraphQL.Server;


Expand All @@ -13,14 +13,16 @@
builder.Services.AddSingleton<ReviewsResolvers>();

// configure services
builder.AddTankaGraphQL3()
.AddOptions("reviews", options =>
builder.AddTankaGraphQL()
.AddSchemaOptions("reviews", options =>
{
options.AddReviews();

// add federation as last step
options.Configure<ReviewsReferenceResolvers>((schema, referenceResolvers) =>
options.Configure<ReviewsReferenceResolvers>((options, referenceResolvers) =>
{
var schema = options.Builder;

// federation should be added as last step so
// that all entity types are correctly detected
schema.AddSubgraph(new(referenceResolvers));
Expand All @@ -35,6 +37,6 @@
app.UseWebSockets();

// this uses the default pipeline
app.MapTankaGraphQL3("/graphql", "reviews");
app.MapTankaGraphQL("/graphql", "reviews");

app.Run();
15 changes: 9 additions & 6 deletions dev/GraphQL.Dev.Reviews/SchemaOptionsBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using GraphQL.Dev.Reviews;
using Microsoft.Extensions.Options;
using Tanka.GraphQL.Server;

namespace GraphQL.Dev.Reviews;
namespace Tanka.GraphQL.Dev.Reviews;

public static class SchemaOptionsBuilderExtensions
{
public static SchemaOptionsBuilder AddReviews(this SchemaOptionsBuilder options)
public static OptionsBuilder<SchemaOptions> AddReviews(this OptionsBuilder<SchemaOptions> optionsBuilder)
{
options.Configure<ReviewsResolvers>((schema, resolvers) =>
optionsBuilder.Configure<ReviewsResolvers>((options, resolvers) =>
{
schema.Add("""
var builder = options.Builder;
builder.Add("""
type Review @key(fields: "id") {
id: ID!
body: String
Expand All @@ -28,9 +31,9 @@ type Product @key(fields: "upc") @extends {
}
""");

schema.Add(resolvers);
builder.Add(resolvers);
});

return options;
return optionsBuilder;
}
}
6 changes: 3 additions & 3 deletions dev/graphql.dev.chat.web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
json.SerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
});
// configure services
builder.AddTankaGraphQL3()
.AddOptions("chat", options => { options.Configure(schema => schema.AddChat()); })
builder.AddTankaGraphQL()
.AddSchema("chat", schema => schema.AddChat())
.AddHttp()
.AddWebSockets();

Expand All @@ -25,6 +25,6 @@
app.UseWebSockets();

// this uses the default pipeline
app.MapTankaGraphQL3("/graphql", "chat");
app.MapTankaGraphQL("/graphql", "chat");

app.Run();
2 changes: 1 addition & 1 deletion docs/0-getting-started/04-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ required then you can implement your own server.

> See also
>
> - [Server](xref://server:0-common.md)
> - [Server](xref://server:00-index.md)


### Simple example with HTTP and websockets
Expand Down
11 changes: 11 additions & 0 deletions docs/2-language/02-executable-doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Executable Document

Tanka GraphQL splits the GraphQL document into two parts: executable document and type system document.
Executable document is the part of the document that is executed by the GraphQL server. Type system document
is the part of the document that is used to define the GraphQL schema.

Here's the definition of executable document:

```csharp
#include::xref://src:graphql.language/Nodes/ExecutableDocument.cs
```
120 changes: 0 additions & 120 deletions docs/2-language/02-imports.md

This file was deleted.

10 changes: 10 additions & 0 deletions docs/2-language/03-type-system-doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Executable Document

Type System Document is used to define the GraphQL schema. It is used by the
GraphQL server to validate the query and to resolve the query.

Here's the definition of type system document:

```csharp
#include::xref://src:graphql.language/Nodes/TypeSystem/TypeSystemDocument.cs
```
5 changes: 3 additions & 2 deletions docs/2-language/nav.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- [Language](xref://01-parser.md)
- [Imports](xref://02-imports.md)
- [Parser](xref://01-parser.md)
- [Executable Document](xref://02-executable-doc.md)
- [Type System Document](xref://03-type-system-doc.md)
3 changes: 0 additions & 3 deletions docs/2-language/syntax-tree/executable-doc.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/2-language/syntax-tree/nav.md

This file was deleted.

6 changes: 0 additions & 6 deletions docs/2-language/syntax-tree/tanka-docs-section.yml

This file was deleted.

3 changes: 0 additions & 3 deletions docs/2-language/syntax-tree/tree.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/2-language/syntax-tree/type-system-doc.md

This file was deleted.

63 changes: 0 additions & 63 deletions docs/3-server/0-common.md

This file was deleted.

14 changes: 14 additions & 0 deletions docs/3-server/00-index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Tanka GraphQL Server

Server provides a way to host GraphQL schema and execute queries against it. It runs on top
of ASP.NET Core and has transports for HTTP and WebSockets.

### Installation

Server is available as a NuGet package:

```csharp
dotnet add package tanka.graphql.server
```

See features on the side for more information.
4 changes: 4 additions & 0 deletions docs/3-server/05-features/00-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Features

Features are show by a sample projects. Samples shows how to use the feature with minimal code.
Full source code of each sample is available at [GitHub](https://github.com/pekkah/tanka-graphql).
11 changes: 11 additions & 0 deletions docs/3-server/05-features/01-http.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Http and WebSockets

This sample provides a basic HTTP and WebSockets server with GraphQL schema and query execution.
It supports both GET and POST requests and uses WebSockets for subscriptions.

WebSockets transport uses the newer [graphql-ws](https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md) protocol


```csharp
#include::xref://samples:GraphQL.Samples.Http/Program.cs
```
9 changes: 9 additions & 0 deletions docs/3-server/05-features/02-authorization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Authorization

This sample supports both websockets and HTTP requests. It uses a simple cookie authentication
to authenticate the user and then applies a authorization policy to the GraphQL endpoint.


```csharp
#include::xref://samples:GraphQL.Samples.Authorization/Program.cs
```
3 changes: 3 additions & 0 deletions docs/3-server/05-features/nav.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [Features](xref://05-features/00-list.md)
- [Http and WebSockets](xref://05-features/01-http.md)
- [Authorization](xref://05-features/02-authorization.md)
Loading