Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added initial configuration for GraphQL #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/GraphQL/GraphTypes/UserType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using GraphQL.Types;
using NetCoreBootstrap.Models.Database;

namespace NetCoreBootstrap.GraphQL.GraphQLTypes
{
public class UserType : ObjectGraphType<User>
{
public UserType()
{
Field(user => user.Id);
Field(user => user.Email);
Field(user => user.UserName);
}
}
}
22 changes: 22 additions & 0 deletions src/GraphQL/Queries/UserQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using GraphQL.Types;
using NetCoreBootstrap.Repositories.Interfaces;
using NetCoreBootstrap.GraphQL.GraphQLTypes;

namespace NetCoreBootstrap.GraphQL.Queries
{
public class UserQuery : ObjectGraphType
{
private readonly IUnitOfWork _unitOfWork;
public UserQuery(IUnitOfWork unitOfWork)
{
this._unitOfWork = unitOfWork;
Field<ListGraphType<UserType>>("users", resolve: context => _unitOfWork.UserRepository.GetAllUsers());
Field<UserType>("user",
arguments: new QueryArguments(new QueryArgument<IntGraphType> { Name = "id" }),
resolve:
context => _unitOfWork.UserRepository
.GetUserById(context.GetArgument<string>("id"))
.Result);
}
}
}
12 changes: 12 additions & 0 deletions src/GraphQL/Schemas/UserSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using GraphQL;
using GraphQL.Types;
using NetCoreBootstrap.GraphQL.Queries;

namespace NetCoreBootstrap.GraphQL.Schemas
{
public class UserSchema : Schema
{
public UserSchema(IDependencyResolver resolver) : base(resolver)
=> this.Query = resolver.Resolve<UserQuery>();
}
}
27 changes: 15 additions & 12 deletions src/NetCoreBootstrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
<CodeAnalysisRuleSet>./ca.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hangfire" Version="1.6.17"/>
<PackageReference Include="Hangfire.PostgreSql" Version="1.4.8.1"/>
<PackageReference Include="LocalizationCultureCore" Version="1.1.2"/>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="2.1.1"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="2.1.1"/>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.1"/>
<PackageReference Include="Rollbar" Version="1.5.0 "/>
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.1.0"/>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1"/>
<PackageReference Include="GraphQL" Version="2.4.0" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="3.4.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="3.5.0-alpha0014" />
<PackageReference Include="Hangfire" Version="1.6.17" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.4.8.1" />
<PackageReference Include="LocalizationCultureCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="2.1.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.1" />
<PackageReference Include="Rollbar" Version="1.5.0 " />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.1.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1" />
</ItemGroup>
</Project>
11 changes: 0 additions & 11 deletions src/Scripts/appsettings.Development.json

This file was deleted.

28 changes: 20 additions & 8 deletions src/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using System.Globalization;
using GraphQL;
using GraphQL.Server;
using GraphQL.Server.Ui.Playground;
using GraphQL.Types;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
Expand All @@ -13,10 +13,10 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
using NetCoreBootstrap.Mail;
using NetCoreBootstrap.GraphQL.GraphQLTypes;
using NetCoreBootstrap.GraphQL.Queries;
using NetCoreBootstrap.GraphQL.Schemas;
using NetCoreBootstrap.Models.Database;
using NetCoreBootstrap.Repositories;
using NetCoreBootstrap.Repositories.Database;
using NetCoreBootstrap.Repositories.Interfaces;
// using Rollbar;
Expand All @@ -39,6 +39,8 @@ public Startup(IConfiguration configuration, IHostingEnvironment currentEnvironm
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService));

// Add framework services.
// Rollbar service start
// ConfigureRollbarSingleton();
Expand Down Expand Up @@ -119,6 +121,13 @@ public void ConfigureServices(IServiceCollection services)
// Uncomment this if you want use Hangfire
// services.AddHangfire(options => GlobalConfiguration.Configuration.UsePostgreSqlStorage(connectionString));
// services.AddSingleton<IMailer, Mailer>();

// ----------------------------------------- GraphQL services -----------------------------------------------
services.AddScoped<UserType>();
services.AddScoped<UserQuery>();
services.AddScoped<ISchema, UserSchema>();

services.AddGraphQL();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down Expand Up @@ -169,6 +178,9 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
// Uncomment this if you want use Hangfire
// app.UseHangfireDashboard();
// app.UseHangfireServer(new BackgroundJobServerOptions(), null, new PostgreSqlStorage(Configuration["ConnectionString"]));
app.UseGraphQL<ISchema>("/graphql");
// use graphql-playground at default url /ui/playground
app.UseGraphQLPlayground(new GraphQLPlaygroundOptions { Path = "/ui/playground" });
}

// Rollbar methods start
Expand Down