Skip to content

Commit

Permalink
Fixed more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Jul 15, 2020
1 parent 9e1c342 commit 546d2b7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/HotChocolate/Utilities/src/Utilities/ServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public class ServiceFactory : IServiceProvider

public object? CreateInstance(Type type)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}

try
{
return ActivatorHelper.CompileFactory(type).Invoke(Services ?? _empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,6 @@ public void CreateInstanceFactory_From_AbstactClass()
.Message.MatchSnapshot();
}

[Fact]
public void CreateInstanceFactory_From_Class_With_Multiple_Constructors()
{
// arrange
// act
Action action = () => ActivatorHelper
.CompileFactory(typeof(Foo).GetTypeInfo());

// assert
Assert.Throws<InvalidOperationException>(action)
.Message.MatchSnapshot();
}

public interface IFoo
{

Expand Down
44 changes: 44 additions & 0 deletions website/src/blog/2020-07-16-version-11/2020-07-16-version-11.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,47 @@ public void ConfigureServices(IServiceCollection services)

Again, I can have in-memory subscriptions on one schema and Redis subscriptions on the other.

Next we need to define our `Mutation` type in order to trigger subscriptions whenever something happens on our server.

```csharp
public class Mutation
{
public string SendMessage(
string userId
string message,
[Service] ITopicEventSender eventSender)
{
eventSender.SendAsync(userId, message);
return message;
}
}
```

In our example we have a mutation that can send a text message to a user represented by the user API. In order to send a message to our subscription bus we are using the userId argument as a topic and the message as a payload and use the injected `ITopicEventSender` to send the message.

In our subscription type we do not need to handle the receive process or anything. We just specify what the topic is and what the message is and everything will be automatically injected.

```csharp
public class Subscription
{
[Subscribe]
public string OnMessage(
[Topic] string userId,
[EventMessage] string message) =>
message;
}
```

The userId in this instance is an argument that is provided from the outside, whereas the message is a parameter where the subscription bus injects the sent message into our resolver.

```graphql
subscription onMessage {
onMessage(userId: "123");
}
```

There are a lot more variants with the new subscriptions but I will cover that in a later blog post that only looks at subscriptions and what we can do with them.

## Extensibility

We put a big emphasis

0 comments on commit 546d2b7

Please sign in to comment.