Join Glenn Block for an in-depth discussion in this video New GraphQL.NET schema classes, part of API Development in .NET with GraphQL.
- [Instructor] Here are the steps that we're going to follow in order to configure the subscription schema. First we're going to create a new OrderEventType. This is going to be the GraphQL type that corresponds with our order event model that was just created. Then we'll create a GraphQL subscription object and this is very similar to what we've done with queries and mutations. This is going to expose one or more events that the clients will be able to subscribe to.
Next we'll have to update the schema because everything has to be surfaced on the schema so that the clients can get to it and then we'll go and register the new types as we've been doing for our queries and mutations. Now along the way, we're going to have to deal with some new GraphQL.NET classes that we haven't really been using. Up until now, we've been relying on the field helper functions to add new fields to our types, but these don't support subscriptions so we're going to have to peel back and use the underlying add field function on object graph type which until now we haven't really had to deal with.
Now we're going to deal with some other related classes, but these are still useful for you to know and that you'll be able to benefit from. So first there's ResolveFieldContext so every time we've created a resolve function, we've been getting this context object and this is just the type of that object. Now whenever we supply that resolve function, behind the scenes it actually creates this FuncFieldResolver and when you're using add field, you have to create that directly and you're going to see that.
Now this EventStreamFieldType when we call this add field function, we specify the type and we're going to specify this to say that the field that we're creating is actually an event stream and this is what's needed for exposing subscriptions. Now we're also going to use the EventStreamResolver so resolving an event stream is different than just resolving a value so you'll see we'll be using this as well and that resolver will actually get a different kind of context object which is called ResolveEventStreamContext.
Okay, let's go to it.
- Creating a new GraphQL project
- Exposing a new GraphQL API
- Enabling and creating mutations
- Updating and configuring the schema
- Enabling subscriptions
- New GraphQL.NET schema classes
- Creating the OrderEventType