void NoContext()
    {
        #region NoContext

        var options = new ExecutionOptions
        {
            Schema = schema,
            Query  = queryString,
            Inputs = inputs
        };
        options.UseFluentValidation(validatorTypeCache);

        #endregion
    }
    async Task ExecuteQuery()
    {
        #region UseFluentValidation

        var options = new ExecutionOptions
        {
            Schema = schema,
            Query  = queryString,
            Inputs = inputs
        };
        options.UseFluentValidation(validatorTypeCache);

        var executionResult = await executer.ExecuteAsync(options);

        #endregion
    }
    void ExecuteQueryWithContextImplementingDictionary()
    {
        #region ExecuteQueryWithContextImplementingDictionary

        var options = new ExecutionOptions
        {
            Schema      = schema,
            Query       = queryString,
            Inputs      = inputs,
            UserContext = new MyUserContext
                          (
                myProperty: "the value"
                          )
        };
        options.UseFluentValidation(validatorTypeCache);

        #endregion
    }
    public static async Task <string> ExecuteQuery(string queryString, Inputs?inputs, ValidatorTypeCache cache)
    {
        queryString      = queryString.Replace("'", "\"");
        using var schema = new Schema();
        var documentExecuter = new DocumentExecuter();

        var executionOptions = new ExecutionOptions
        {
            Schema = schema,
            Query  = queryString,
            Inputs = inputs
        };

        executionOptions.UseFluentValidation(cache);

        var result = await documentExecuter.ExecuteAsync(executionOptions);

        return(await new DocumentWriter(indent: true).WriteToStringAsync(result));
    }
Example #5
0
    Task <ExecutionResult> Execute(string query,
                                   string?operationName,
                                   JObject?variables,
                                   CancellationToken cancellation)
    {
        var options = new ExecutionOptions
        {
            Schema            = schema,
            Query             = query,
            OperationName     = operationName,
            Inputs            = variables?.ToInputs(),
            CancellationToken = cancellation,
#if (DEBUG)
            ExposeExceptions = true,
            EnableMetrics    = true,
#endif
        };

        options.UseFluentValidation(ValidatorCacheBuilder.Instance);

        return(executer.ExecuteAsync(options));
    }
Example #6
0
        public async Task <IActionResult> Post([FromBody] GraphQlQuery query)
        {
            var validatorTypeCache = new ValidatorTypeCache();

            validatorTypeCache.
            AddValidatorsFromAssemblyContaining(typeof(ItemValidator));

            var options = new ExecutionOptions
            {
                Schema = schema,
                Query  = query.Query,
                Inputs = query.Variables.ToInputs()
            };

            options.UseFluentValidation(validatorTypeCache);

            var result = await new DocumentExecuter().ExecuteAsync(options);

            if (result.Errors?.Count > 0)
            {
                return(BadRequest(result.Errors));
            }
            return(Ok(result));
        }
    void ExecuteQueryWithContextInsideDictionary()
    {
        #region ExecuteQueryWithContextInsideDictionary

        var options = new ExecutionOptions
        {
            Schema      = schema,
            Query       = queryString,
            Inputs      = inputs,
            UserContext = new Dictionary <string, object>
            {
                {
                    "MyUserContext",
                    new MyUserContext
                    (
                        myProperty: "the value"
                    )
                }
            }
        };
        options.UseFluentValidation(validatorTypeCache);

        #endregion
    }