// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { var typeAdapter = new GraphTypeAdapter(); var constructor = new SchemaConstructor <ISchema, IGraphType>(typeAdapter); var schema = constructor.Build(typeof(SchemaDefinition <GraphQl.Query, GraphQl.Mutation, GraphQl.Subscription>)); var graphQLEngine = new GraphQLEngine() .WithFieldResolutionStrategy(FieldResolutionStrategy.Normal) .WithQuery <GraphQl.Query>() .WithMutation <GraphQl.Mutation>() .WithSubscription <GraphQl.Subscription>() .BuildSchema(); services.AddSingleton <MessageService>(); services.AddSingleton(schema); services.AddMvc(); services.AddTransient <IDependencyInjector, Injector>(); services.AddSingleton(provider => graphQLEngine); services.AddSingleton <IDocumentExecuter, GraphQL.Conventions.DocumentExecuter>(); services.AddSingleton <IDocumentWriter>(x => { var jsonSerializerSettings = x.GetRequiredService <IOptions <JsonSerializerSettings> >(); return(new DocumentWriter(Formatting.None, jsonSerializerSettings.Value)); }); services.AddTransient(typeof(IGraphQLExecuter <>), typeof(DefaultGraphQLExecuter <>)); services.AddTransient <IWebSocketConnectionFactory <ISchema>, WebSocketConnectionFactory <ISchema> >(); services.AddTransient <IOperationMessageListener, LogMessagesListener>(); services.AddTransient <IOperationMessageListener, ProtocolMessageListener>(); }
protected ISchema Schema <TSchema>() { var typeAdapter = new GraphTypeAdapter(); var constructor = new SchemaConstructor <ISchema, IGraphType>(typeAdapter); var schema = constructor.Build(typeof(TSchema)); Assert.IsNotNull(schema); return(schema); }
public GraphQLEngine BuildSchema(params System.Type[] types) { if (_schema == null) { if (types.Length > 0) { _schemaTypes.AddRange(types); } _schema = _constructor.Build(_schemaTypes.ToArray()); _schemaPrinter = new SchemaPrinter(_schema, new[] { TypeNames.Url, TypeNames.Uri, TypeNames.TimeSpan, TypeNames.Guid }); } return(this); }
public GraphQLEngine BuildSchema(params System.Type[] types) { if (_schema == null) { if (types.Length > 0) { _schemaTypes.AddRange(types); } _schema = _constructor.Build(_schemaTypes.ToArray()); _schemaPrinter = new SchemaPrinter( _schema, new SchemaPrinterOptions { CustomScalars = new List <string> { TypeNames.Url, TypeNames.Uri, TypeNames.TimeSpan, TypeNames.Guid }, IncludeDescriptions = _includeFieldDescriptions, IncludeDeprecationReasons = _includeFieldDeprecationReasons, } ); } return(this); }