コード例 #1
0
ファイル: GraphQLMiddleware.cs プロジェクト: Ciorna/PSSC-2020
 public GraphQLMiddleware(
     RequestDelegate next,
     GraphQLSettings settings,
     IDocumentExecuter executer,
     IDocumentWriter writer)
 {
     _next     = next;
     _settings = settings;
     _executer = executer;
     _writer   = writer;
 }
コード例 #2
0
        public static void Handle(IApplicationBuilder app)
        {
            var settings = new GraphQLSettings
            {
                BuildUserContext = ctx =>
                {
                    Guid   userId       = Guid.Empty;
                    string userIdString = ctx.User.Claims.FirstOrDefault(c => c.Type == "acid")?.Value;
                    if (userIdString != null)
                    {
                        userId = Guid.Parse(userIdString);
                    }
                    else
                    {
                        var userIdValue = RequestContext.Get(RequestContextConst.UserId)?.ToString();
                        if (!string.IsNullOrWhiteSpace(userIdValue))
                        {
                            userId = Guid.Parse(RequestContext.Get(RequestContextConst.UserId)?.ToString());
                        }
                    }

                    Guid   organisationId       = Guid.Empty;
                    string organisationIdString = ctx.User.Claims.FirstOrDefault(c => c.Type == "organisationId")?.Value;
                    if (organisationIdString != null)
                    {
                        organisationId = Guid.Parse(organisationIdString);
                    }
                    else
                    {
                        var organisationIdValue = RequestContext.Get(RequestContextConst.OrganisationId)?.ToString();
                        if (!string.IsNullOrWhiteSpace(organisationIdValue))
                        {
                            organisationId = Guid.Parse(RequestContext.Get(RequestContextConst.OrganisationId)?.ToString());
                        }
                    }

                    var userContext = new GraphQLUserContext
                    {
                        UserId         = userId,
                        OrganisationId = organisationId
                    };

                    return(Task.FromResult(userContext));
                }
            };

#if !DEBUG
            app.UseMiddleware <IdentityAuthenticationMiddleware>();
#else
            app.UseSetupRequestContext();
#endif
            app.UseMiddleware <GraphQLMiddleware>(settings);
            app.UseGraphQL <StackUnderflowSchema>(new PathString(""));
        }