Пример #1
0
        public async Task <QuestionDetail> GetLeetcodeAsync(string titleSlug)
        {
            var heroAndFriendsRequest = new GraphQLRequest
            {
                Query         = @"
                    query getQuestionDetail($titleSlug: String!) {
                    question(titleSlug: $titleSlug) {
                    questionId
                    questionTitle
                    questionTitleSlug
                    content
                    difficulty
                    categoryTitle
                    codeDefinition
                    sampleTestCase
                    metaData
                    questionDetailUrl
                  }
                
                }",
                OperationName = "getQuestionDetail",
                Variables     = new
                {
                    titleSlug = titleSlug
                }
            };
            var graphQLClient   = new GraphQLClient($"{BaseUrl}/graphql");
            var graphQLResponse = await graphQLClient.GetAsync(heroAndFriendsRequest);

            var questionDetail = graphQLResponse.GetDataFieldAs <QuestionDetail>("question");

            return(questionDetail);
        }
Пример #2
0
        /// <summary>Send a <see cref="GraphQLRequest" /> composed of a query batch via GET.</summary>
        /// <param name="client">The GraphQL Client.</param>
        /// <param name="queries">The query batch.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="ArgumentException">Dupe Key, missing parts or empty parts of a query</exception>
        /// <exception cref="ArgumentNullException">Invalid Configuration</exception>
        public static async Task <IReadOnlyDictionary <string, JToken> > GetBatch(this GraphQLClient client, IQuery[] queries, CancellationToken cancellationToken = default)
        {
            Guard.Argument(queries, nameof(queries)).NotNull().NotEmpty();

            GraphQLRequest  request  = CreateGraphQLResquest(queries);
            GraphQLResponse response = await client.GetAsync(request, cancellationToken);

            return(ParseResponse(queries, response));
        }
Пример #3
0
        /// <summary>Send a <see cref="GraphQLRequest" /> via GET.</summary>
        /// <typeparam name="T">Data Type.</typeparam>
        /// <param name="client">The GraphQL Client.</param>
        /// <param name="query">The query.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="ArgumentException">Dupe Key, missing parts or empty parts of a query</exception>
        /// <exception cref="ArgumentNullException">Invalid Configuration</exception>
        public static async Task <T> Get <T>(this GraphQLClient client, IQuery query, CancellationToken cancellationToken = default)
            where T : class
        {
            Guard.Argument(query, nameof(query)).NotNull();

            GraphQLRequest  request  = CreateGraphQLResquest(query);
            GraphQLResponse response = await client.GetAsync(request, cancellationToken);

            return(ParseResponse <T>(query, response));
        }