Example #1
0
        public Schema Create(Repository orginalRepository, string schemaName, Stream stream)
        {
            Schema schema = _schemaProvider.Create(orginalRepository, schemaName, stream);

            Sync(Site.Current, orginalRepository, delegate(Repository targetRepository)
            {
                _schemaProvider.Create(targetRepository, schemaName, stream);
            });

            return(schema);
        }
Example #2
0
        public async Task Invoke(HttpContext httpContext)
        {
            var logger = httpContext.RequestServices.GetService <ILogger <GraphQlMiddleware> >();

            HttpRequest  request  = httpContext.Request;
            HttpResponse response = httpContext.Response;

            // GraphQL HTTP only supports GET and POST methods.
            if (request.Method != "GET" && request.Method != "POST")
            {
                response.Headers.Add("Allow", "GET, POST");
                response.StatusCode = 405;

                return;
            }

            // Check authorization
            if (options.AuthorizationPolicy != null)
            {
                var authorizationService = httpContext.RequestServices.GetRequiredService <IAuthorizationService>();
                var authzResult          = await authorizationService.AuthorizeAsync(httpContext.User, options.AuthorizationPolicy);

                if (!authzResult.Succeeded)
                {
                    await httpContext.ForbidAsync();

                    return;
                }
            }

            GraphQlParameters parameters = await GetParametersAsync(request);

            ISchema schema = schemaProvider.Create(httpContext.RequestServices);

            var result = await executer.ExecuteAsync(executionOptions =>
            {
                executionOptions.Schema                  = schema;
                executionOptions.Query                   = parameters.Query;
                executionOptions.OperationName           = parameters.OperationName;
                executionOptions.Inputs                  = parameters.GetInputs();
                executionOptions.CancellationToken       = httpContext.RequestAborted;
                executionOptions.ComplexityConfiguration = options.ComplexityConfiguration;
                executionOptions.UserContext             = httpContext;
                executionOptions.ExposeExceptions        = options.ExposeExceptions;
                ConfigureDocumentExecutionListeners(executionOptions, executionListeners);
            });

            if (result.Errors?.Count > 0)
            {
                logger.LogError("GraphQL Result {Errors}", result.Errors);
            }

            var writer = new DocumentWriter(indent: options.FormatOutput);
            var json   = writer.Write(result);

            response.StatusCode  = 200;
            response.ContentType = "application/json; charset=utf-8";

            await response.WriteAsync(json);
        }
Example #3
0
 public Schema Create(Repository repository, string schemaName, System.IO.Stream templateStream)
 {
     try
     {
         return(inner.Create(repository, schemaName, templateStream));
     }
     finally
     {
         ClearObjectCache(new Schema(repository, schemaName));
     }
 }