示例#1
0
        public DefaultGraphQLExecuter(
            TSchema schema,
            IDocumentExecuter documentExecuter,
            IOptions <GraphQLOptions> options,
            IEnumerable <IDocumentExecutionListener> listeners,
            IEnumerable <IValidationRule> validationRules)
        {
            Schema = schema;

            _documentExecuter = documentExecuter;
            _options          = options.Value;
            _listeners        = listeners;
            _validationRules  = validationRules;
        }
示例#2
0
        public InstrumentingGraphQLExecutor(
            TSchema schema,
            IDocumentExecuter documentExecuter,
            IOptions <GraphQLOptions> options,
            IEnumerable <IDocumentExecutionListener> listeners,
            IEnumerable <IValidationRule> validationRules)
            : base(schema, documentExecuter, options, listeners, validationRules)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.options = options.Value;
        }
 public GraphQLHttpMiddleware(
     RequestDelegate next,
     PathString path,
     GraphQLSettings settings,
     IGraphQLRequestDeserializer deserializer,
     IEnumerable <IDocumentExecutionListener> listeners,
     IOptions <GraphQLOptions> options,
     IDocumentWriter writer,
     ILoggerFactory loggerFactory)
 {
     _next         = next;
     _path         = path;
     _deserializer = deserializer;
     _options      = options.Value;
     _listeners    = listeners;
     _settings     = settings;
     _writer       = writer;
     _logger       = loggerFactory.CreateLogger <GraphQLHttpMiddleware <TSchema> >();
 }
示例#4
0
        /// <summary>
        /// Executes a GraphQL query / mutation on the Trace service.
        /// </summary>
        /// <param name="query">     the graphql query / mutation </param>
        /// <param name="variables"> the graphql variables </param>
        /// <param name="opts">      the graphql options </param>
        /// <exception cref="TraceSdkException">
        ///  </exception>
        public async Task <GraphQLResponse> GraphqlAsync(String query, IDictionary <string, object> variables, GraphQLOptions opts, Type tclass)
        {
            String gqlUrl = this.endpoints.Trace + "/graphql";

            // delegate the graphql request execution
            GraphQLResponse response = await GraphqlExecute(gqlUrl, await this.GetAuthorizationHeader(null), query, variables, tclass);

            if (opts == null)
            {
                opts = defaultGraphQLOptions;
            }

            if (response.Errors == null)
            {
                // if the response is empty, throw.
                if (response.Data == null)
                {
                    throw new TraceSdkException("The graphql response is empty.");
                }
            }
            else
            {
                var statusCode = response.Errors.LastOrDefault()?.AdditonalEntries?.Values.ToArray()[0];

                int retry = opts.Retry;
                // handle errors explicitly
                // extract the status from the error response
                // if 401 and retry > 0 then we can retry
                if (statusCode != null && statusCode.ToString() == "401" && retry > 0)
                {
                    // unauthenticated request might be because token expired
                    // clear token and retry
                    this.ClearToken();
                    opts.Retry = opts.Retry - 1;
                    return(await this.GraphqlAsync(query, variables, opts, tclass));
                }
                // otherwise rethrow
                throw new TraceSdkException(response.Errors[0].Message);
            }
            return(response);
        }
示例#5
0
        /// <summary>
        /// Executes the query and returns a responseEntity of type passed </summary>
        /// <param name="url"> </param>
        /// <param name="auth"> </param>
        /// <param name="query"> </param>
        /// <param name="Variables"> </param>
        /// <param name="tClass">
        /// @return </param>
        public async Task <GraphQLResponse <dynamic> > GraphqlExecute(string url, string query, IDictionary <string, object> variables, GraphQLOptions opts)
        {
            GraphQLHttpClient graphClient = new GraphQLHttpClient(url, new NewtonsoftJsonSerializer());

            graphClient.HttpClient.DefaultRequestHeaders.Add("User-Agent", this.userAgent);
            graphClient.HttpClient.DefaultRequestHeaders.Add("Authorization", await this.GetAuthorizationHeader(null));
            GraphQLRequestCamel request = new GraphQLRequestCamel(query, variables);

            try
            {
                return(await graphClient.SendQueryAsync <dynamic>(request));
            }
            catch (GraphQLHttpRequestException e)
            {
                if (opts == null)
                {
                    opts = defaultGraphQLOptions;
                }
                int retry = opts.Retry;
                // handle errors explicitly
                // extract the status from the error response
                // if 401 and retry > 0 then we can retry
                if (e.StatusCode == HttpStatusCode.Unauthorized && retry > 0)
                {
                    // unauthenticated request might be because token expired
                    // clear token and retry
                    this.ClearToken();
                    opts.Retry -= 1;
                    return(await this.GraphqlExecute(url, query, variables, opts));
                }

                // otherwise rethrow
                throw new TraceSdkException(e.Content);
            }
        }
示例#6
0
        /// <summary>
        /// Executes a GraphQL query / mutation on the Trace service.
        /// </summary>
        /// <param name="query">     the graphql query / mutation </param>
        /// <param name="variables"> the graphql variables </param>
        /// <param name="opts">      the graphql options </param>
        /// <exception cref="TraceSdkException">
        ///  </exception>
        public async Task <GraphQLResponse <dynamic> > GraphqlAsync(String query, IDictionary <string, object> variables, GraphQLOptions opts, Type tclass)
        {
            String gqlUrl = this.endpoints.Trace + "/graphql";

            if (opts == null)
            {
                opts = defaultGraphQLOptions;
            }

            // delegate the graphql request execution
            GraphQLResponse <dynamic> response;

            try
            {
                response = await GraphqlExecute(gqlUrl, query, variables, opts);
            }
            catch (GraphQLHttpRequestException e)
            {
                int retry = opts.Retry;
                // handle errors explicitly
                // extract the status from the error response
                // if 401 and retry > 0 then we can retry
                if (e.StatusCode == HttpStatusCode.Unauthorized && retry > 0)
                {
                    // unauthenticated request might be because token expired
                    // clear token and retry
                    this.ClearToken();
                    opts.Retry = opts.Retry - 1;
                    return(await this.GraphqlAsync(query, variables, opts, tclass));
                }
                // otherwise rethrow
                throw new TraceSdkException(e.Content);
            }


            if (response.Errors == null)
            {
                // if the response is empty, throw.
                if (response.Data == null)
                {
                    throw new TraceSdkException("The graphql response is empty.");
                }
            }
            else
            {
                throw new TraceSdkException(response.Errors[0].Message);
            }
            return(response);
        }
示例#7
0
 private static void NopConfigureOptions(GraphQLOptions options, IServiceProvider provider)
 {
 }