Example #1
0
        public static void Initialize()
        {
            if (StarWarsHttpServer != null) //already initialized
            {
                return;
            }
            if (File.Exists(LogFilePath))
            {
                File.Delete(LogFilePath);
            }

            // create server and Http graphQL server
            var app            = new StarWarsApp();
            var starWarsServer = new GraphQLServer(app);

            starWarsServer.RegisterModules(new StarWarsApiModule());
            StarWarsHttpServer = new GraphQLHttpServer(starWarsServer);
            StartWebHost();

            // Write schema doc to file
            var schemaDoc = starWarsServer.Model.SchemaDoc;

            File.WriteAllText("_starWarsSchema.txt", schemaDoc);


            Client = new GraphQLClient(GraphQLEndPointUrl);
            Client.RequestCompleted += Client_RequestCompleted;
        }
Example #2
0
        private GraphQLHttpServer CreateGraphQLHttpServer()
        {
            // create server and Http graphQL server
            var thingsBizApp = new ThingsApp();
            var thingsServer = new GraphQLServer(thingsBizApp);
            var thingsModule = new ThingsGraphQLModule();

            thingsServer.RegisterModules(thingsModule);
            var server = new GraphQLHttpServer(thingsServer);

            return(server);
        }
Example #3
0
        private GraphQLHttpServer CreateThingsGraphQLHttpServer()
        {
            // create server and Http graphQL server
            var thingsBizApp = new ThingsApp();
            var serverStt    = new GraphQLServerSettings()
            {
                Options = GraphQLServerOptions.DefaultDev
            };
            var thingsServer = new ThingsGraphQLServer(thingsBizApp, serverStt);
            var server       = new GraphQLHttpServer(thingsServer);

            return(server);
        }
Example #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //app.UseHttpsRedirection();
            app.UseRouting();

            // create server and configure GraphQL endpoints
            _graphQLServer = CreateThingsGraphQLHttpServer();
            app.UseEndpoints(endpoints => {
                endpoints.MapPost("graphql", HandleRequest);
                endpoints.MapGet("graphql", HandleRequest);
                endpoints.MapGet("graphql/schema", HandleRequest);
            });
            // Use GraphiQL UI
            app.UseGraphQLGraphiQL();
        }