Beispiel #1
0
        public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            var writer = new SchemaWriter(new TodoSchema());

            string schema = await writer.Generate();

            using (FileStream fs = File.Create(Path.Combine(env.WebRootPath, "schema.json")))
            {
                byte[] info = new UTF8Encoding(true).GetBytes(schema);
                fs.Write(info, 0, info.Length);
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //app
            //    .UseStaticFiles()
            //    .UseDefaultFiles()
            //    .UseRouter(
            //        new RouteBuilder(app)
            //            .MapPost("graphql", async context =>
            //            {
            //                var executor = context.RequestServices.GetService<RequestExecutor>();
            //                try
            //                {
            //                    //var resp = await executor.ExecuteAsync(
            //                    //    context.Request.Body,
            //                    //    context.Request.ContentType,
            //                    //    (_, files) =>
            //                    //    {
            //                    //        _.Schema = new TodoSchema();
            //                    //        //_.FieldNameConverter = new CamelCaseFieldNameConverter();
            //                    //    }
            //                    //);

            //                   // await context.Response.WriteAsync(await resp.Write());

            //                }
            //                catch (Exception err)
            //                {
            //                    throw err;
            //                }
            //            })
            //            .Build()
            //    );
        }
Beispiel #2
0
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            var writer = new SchemaWriter(new TodoSchema());

            string schema = await writer.Generate();

            using (FileStream fs = File.Create(Path.Combine(env.WebRootPath, "schema.json")))
            {
                byte[] info = new UTF8Encoding(true).GetBytes(schema);
                fs.Write(info, 0, info.Length);
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware();
            }

            app
            .UseStaticFiles()
            .UseDefaultFiles()
            .UseRouter(
                new RouteBuilder(app)
                .MapPost("graphql", async context =>
            {
                var executor = context.RequestServices.GetService <RequestExecutor>();
                try {
                    var resp = await executor.ExecuteAsync(
                        context.Request.Body,
                        context.Request.ContentType,
                        (_, files) => {
                        _.Schema             = new TodoSchema();
                        _.FieldNameConverter = new CamelCaseFieldNameConverter();
                    }
                        );

                    await context.Response.WriteAsync(resp.Write());
                } catch (Exception err) {
                    throw err;
                }
            })
                .Build()
                );
        }
Beispiel #3
0
        public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            var writer = new SchemaWriter(new TodoSchema());

            string schema = await writer.Generate();

            using (FileStream fs = File.Create(Path.Combine(env.WebRootPath, "schema.json")))
            {
                byte[] info = new UTF8Encoding(true).GetBytes(schema);
                fs.Write(info, 0, info.Length);
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app
            .UseStaticFiles()
            .UseDefaultFiles()
            .UseGraphQL <TodoSchema>()
            .UseGraphQLGraphiQL();
        }