private async Task HandleIntrospectionQuery(RequestPayload requestPayload, HttpContext httpContext)
        {
            var schema           = _schemaProvider.Schema;
            var convertedSchema  = _schema ?? _schemaConverter.Convert(schema);
            var docuemntExecutor = new DocumentExecuter();
            var executionOptions = new ExecutionOptions()
            {
                Schema             = convertedSchema,
                OperationName      = requestPayload.OperationName,
                Query              = requestPayload.Query,
                Inputs             = new Inputs(),
                EnableMetrics      = false,
                ExposeExceptions   = true,
                SetFieldMiddleware = false,
                FieldNameConverter = _graphOptions.FieldNameConverter == FieldNameConverter.Default
                ? _defaultConverter
                : _camelCaseConverter
            };

            var result = await docuemntExecutor.ExecuteAsync(executionOptions);

            httpContext.Response.ContentType = "application/json";
            httpContext.Response.StatusCode  = 200;

            await new DocumentWriter().WriteAsync(httpContext.Response.Body, result);
        }
Ejemplo n.º 2
0
 private void SetVariables(GraphContext context, RequestPayload payload)
 {
     if (payload.Variables != null)
     {
         foreach (JProperty item in payload.Variables.Children())
         {
             context.Variables[item.Name] = item.Value;
         }
     }
 }
Ejemplo n.º 3
0
        public ValueTask <GraphContext> CreateAsync(RequestPayload payload)
        {
            var        document      = _documentBuilder.Build(payload.Query);
            var        operation     = document.Operations.Single();
            var        operationName = operation.Name;
            var        operationType = (OperationType)(int)operation.OperationType;
            IGraphType graphType;
            var        graphSchema = _schemaProvider.Schema;

            switch (operationType)
            {
            case OperationType.Query:
            {
                graphType = graphSchema.Query;
                break;
            }

            case OperationType.Mutation:
            {
                graphType = graphSchema.Mutation;
                break;
            }

            default:
            {
                graphType = graphSchema.Subscription;
                break;
            }
            }

            if (!graphType.Fields.TryGetGetField(typeof(void), operationName, out var operationField))
            {
                throw new GraphException($"Specified GraphQL operation '{operationName}' does not exist in the schema");
            }
            var context = new GraphContext(operationName, operationType, operationField, _httpContextAccessor.HttpContext.RequestServices);

            SetArguments(context, operation);
            context.SelectionSet = _selectionSetProvider.GetSelectionSet(payload.Query, operation, document.Fragments);
            SetVariables(context, payload);
            context.SetArguments(payload.Query);
            return(new ValueTask <GraphContext>(context));
        }