コード例 #1
0
        public async static System.Threading.Tasks.Task <dynamic> post()
        {
            var request = new GraphQL.Common.Request.GraphQLRequest
            {
                Query     = @"
                query GetStationsOperation($pagination: Input_com_busfive_citypass_api_graphql_Pagination, $orderBy: [Input_com_busfive_citypass_api_graphql_OrderBy], $filter: String){
                    GetStations(pagination: $pagination, orderBy: $orderBy, filter: $filter) {
                        stationId
                        name
                        borderCrossing
                    }        
                }
            ",
                Variables = new
                {
                    pagination = new
                    {
                        page         = 1,
                        itemsPerPage = 10000
                    }
                }
            };

            var client = new GraphQLClient("http://149.202.105.188:8160/api/transport_data");

            client.DefaultRequestHeaders.Add("BusfiveAuthorization", "VROsNbCJOiZ7dKFbVCJdzonxPg6v52gwWhwvEiQpigQigAYi.fq0Kt4CHdoXJe4t");

            var val = await client.PostAsync(request);

            return(val.Data.GetStations);
        }
コード例 #2
0
        public async Task <T> GetResponseAsync <T>()
        {
            using (var client = new GraphQLClient(_uri))
            {
                var request = new GraphQL.Common.Request.GraphQLRequest
                {
                    Query     = _query,
                    Variables = _parameters
                };

                foreach (var header in _headers)
                {
                    if (client.DefaultRequestHeaders.Contains(header.Key))
                    {
                        client.DefaultRequestHeaders.Remove(header.Key);
                    }
                    client.DefaultRequestHeaders.Add(header.Key, header.Value);
                }

                var result = await client.PostAsync(request);

                if (result.Errors != null && result.Errors.Any())
                {
                    throw new AggregateException(result.Errors.Select(x => new Exception($"Message: {x.Message}\nLocations: {x.Locations}")));
                }

                return(((JObject)result.Data).ToObject <T>());
            }
        }
コード例 #3
0
        public async Task <T> GetResponseAsync <T>()
        {
            using (var client = new GraphQLClient(_uri))
            {
                var request = new GraphQL.Common.Request.GraphQLRequest
                {
                    Query     = _query,
                    Variables = _parameters
                };
                var result = await client.PostAsync(request);

                return(result.GetDataFieldAs <T>(_entity));
            }
        }
コード例 #4
0
        /// <summary>
        /// Run the GraphQL Query
        /// </summary>
        /// <returns></returns>
        async public Task <JObject> Call()
        {
            GraphQLHttpRequest request = new GraphQLHttpRequest()
            {
                Query         = this.Query,
                OperationName = this.OperationName,
                Variables     = this.Variables
            };

            GraphQLHttpResponse response = await this._client.SendQueryAsync(request);

            if (response.Errors != null)
            {
                throw new GraphQLException(response.Errors);
            }

            JObject data = (JObject)response.Data;

            return(data);
        }
コード例 #5
0
ファイル: MdcAPI.cs プロジェクト: allisterb/Victor
        public static async Task <BoardsQueryResultData> GetBoards()
        {
            var graphQLClient = new GraphQLClient("https://api.monday.com/v2");

            graphQLClient.DefaultRequestHeaders.Add("Authorization", Config("MDC_API_TOKEN"));
            var boardsQueryRequest = new GraphQL.Common.Request.GraphQLRequest
            {
                Query = @"{
                  boards {
                    id
                    name
                    columns {
                      title
                      id
                      type
                    }
                    groups {
                        title
                      id
                    }  
                  }
                }"
            };

            try
            {
                var graphQLResponse = await graphQLClient.PostAsync(boardsQueryRequest);

                return(graphQLResponse.Data.ToObject <BoardsQueryResultData>());
            }
            catch (Exception e)
            {
                Error(e, "Error retrieving boards from monday.com API.");
                return(null);
            }
        }
コード例 #6
0
        public async static System.Threading.Tasks.Task <dynamic> post(int stationBegin, int stationEnd, DateTime departureDate, DateTime returnDate)
        {
            var request = new GraphQL.Common.Request.GraphQLRequest
            {
                Query     = @"
                    query GetLinesDrivingThroughStationsOperation(
                        $filter: String,
                        $page: Int,
                        $itemsPerPage: Int,
                        $orderBy: [Input_com_busfive_citypass_api_graphql_OrderBy!],
                        $fromStationId: Int!,
                        $toStationId: Int!,
                        $cardTypeId: Int!,
                        $departureDate: String,
                        $returnDate: String,
                        $currencyId: Int!
                ) {
                        GetLinesDrivingThroughStations(
                            filter: $filter,
                            orderBy: $orderBy,
                            departureDate: $departureDate,
                            returnDate: $returnDate,
                            currencyId: $currencyId,
                            pagination: {
                                itemsPerPage: $itemsPerPage
                                page: $page
                            }, fromStationId: $fromStationId,
                                toStationId: $toStationId,
                                cardTypeId: $cardTypeId) {
                                        lineId
                                        currency
                                        linePrice
                                        lineCarrierKind {
                                            kindId
                                            name
                                            shortName
                                        }
                                        subLinePrice
                                        subLineStationFrom
                                        subLineStationTo
                                        partner {
                                            id
                                            name
                                        }
                                        timeTables {
                                            departTime
                                            directionId
                                            entries {
                                                borderCrossing
                                                distanceToFirstStationKilometers
                                                station {
                                                    name
                                                    stationId
                                                }
                                                timeSeconds
                                            }
                                            lineId
                                            timeTableId
                                            maxPassengerCount
                                        }
                                }
                    }
                ",
                Variables = new
                {
                    cardTypeId    = (returnDate == DateTime.Today.AddDays(-1) ? 1 : 2),
                    fromStationId = stationBegin,
                    toStationId   = stationEnd,
                    departureDate = departureDate.ToString("yyyy-MM-ddTHH:mm:ss.000Z"),
                    returnDate    = returnDate.ToString("yyyy-MM-ddTHH:mm:ss.0000Z"),
                    currencyId    = 1,
                    page          = 1,
                    itemsPerPage  = 10000
                }
            };

            var client = new GraphQLClient("http://149.202.105.188:8160/api/transport_data");

            client.DefaultRequestHeaders.Add("BusfiveAuthorization", "VROsNbCJOiZ7dKFbVCJdzonxPg6v52gwWhwvEiQpigQigAYi.fq0Kt4CHdoXJe4t");

            var val = await client.PostAsync(request);

            return(val.Data.GetLinesDrivingThroughStations);
        }
コード例 #7
0
        private async Task HandleShemaConf(HttpContext context)
        {
            string path = context.Request.Path.Value;

            if (path.EndsWith("schema.json"))
            {
                //generate admin schema.conf for client
                var gqlRequest = new GraphQL.Common.Request.GraphQLRequest
                {
                    Query         = @"{
                          __schema {
                            queryType { name }
                            types {
                                inputFields {
                                  name
                                  description
                                  type{
                                    name
                                    ofType{
                                      kind
                                      name
                                      ofType{
                                        kind
                                        name
                                        ofType {
                                          name
                                          description
                                        }
                                      }
                                    }
                                  }
                                  defaultValue
                                }
                                
                                name
                                description
                                interfaces {
                                  name
                                  description
                                }
                                enumValues {
                                  description
                                  deprecationReason
                                }
                                fields {
                                    name
                                    description
                                    type {
                                        name
                                        kind
                                    }
                                    isDeprecated
                                    deprecationReason
                                }
                                kind
                                possibleTypes {
                                  name
                                  description
                                }
                            }
                            mutationType { name }
                            directives {
                              name
                              description
                              locations
                              args {
                                name
                                description
                                type{
                                  kind
                                  name
                                  ofType{
                                    kind
                                    name
                                    ofType {
                                      name
                                      description
                                    }
                                  }
                                }
                                defaultValue
                              }
                            }
                          }
                        }",
                    OperationName = ""
                };
                string        endpoint        = context.Request.Scheme + "://" + context.Request.Host.ToString() + context.Request.Path.Value.Substring(0, path.Length - 11) + "graphql";
                GraphQLClient graphQLClient   = new GraphQLClient(endpoint);
                var           graphQLResponse = await graphQLClient.PostAsync(gqlRequest);

                string dataContent = JsonConvert.SerializeObject(new { data = graphQLResponse.Data });
                context.Response.ContentType = "application/octet-stream";
                await context.Response.WriteAsync(dataContent);

                return;
            }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            const String c_collectionUri = "https://dev.azure.com/ankhokha";

            // Interactively ask the user for credentials, caching them so the user isn't constantly prompted

            VssCredentials creds = new VssBasicCredential(String.Empty, "");

            // Connect to Azure DevOps Services
            VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);

            // Get a GitHttpClient to talk to the Git endpoints
            GitHttpClient gitClient = connection.GetClient <GitHttpClient>();

            int              pullRequestId           = 1;
            IList <string>   fileList                = new List <string>();
            IList <File>     fileDetailsList         = new List <File>();
            List <FileInput> fileMutationDetailsList = new List <FileInput>();
            var              repository              = gitClient.GetRepositoryAsync("8ff8a410-814b-463b-8ecc-949c96fe2007").SyncResult();
            var              repoLink                = (repository.Links.Links["web"] as ReferenceLink).Href;
            var              uriBuilder              = new UriBuilder(repoLink);
            var              query = HttpUtility.ParseQueryString(uriBuilder.Query);

            while (true)
            {
                fileMutationDetailsList.Clear();
                Console.WriteLine(pullRequestId);
                // Get data about a specific repository
                IList <GitCommitRef> commitsList;
                try
                {
                    commitsList = gitClient.GetPullRequestCommitsAsync("8ff8a410-814b-463b-8ecc-949c96fe2007", pullRequestId).SyncResult();
                }
                catch (VssServiceException ex)
                {
                    Console.WriteLine(String.Format("Pull request with id {0} not found. Exiting...", pullRequestId));
                    break;
                }

                string email      = "";
                string authorName = "";

                foreach (var commit in commitsList)
                {
                    var commitId = commit.CommitId;
                    var result   = gitClient.GetChangesAsync(commitId, new Guid("8ff8a410-814b-463b-8ecc-949c96fe2007")).SyncResult <GitCommitChanges>();
                    var changes  = result.Changes.ToList();


                    foreach (var change in changes)
                    {
                        fileList.Add(change.Item.Path);
                        query["path"]    = change.Item.Path;
                        email            = commit.Author.Email;
                        authorName       = commit.Author.Name;
                        uriBuilder.Query = query.ToString();

                        var include = true;
                        foreach (var file in fileMutationDetailsList)
                        {
                            if (file.Path == change.Item.Path)
                            {
                                include = false;
                            }
                        }
                        if (include)
                        {
                            fileMutationDetailsList.Add(new FileInput(change.Item.Path, uriBuilder.ToString()));
                        }
                    }
                }

                string graphqlServer = "https://ganes-server.azurewebsites.net/graphql";

                var graphQlCLient = new GraphQL.Client.GraphQLClient(graphqlServer);

                var q = new GraphQL.Common.Request.GraphQLRequest();

                List <FileInput> a = new List <FileInput> ();

                q.Query = @"mutation Mutation1($files: [FileInput]!, $email: String!, $name: String!, $pullRequestId: String!)
                            {
                              IngestPullRequest(
                                pullRequest: {
                                  Files: $files,
                                  ModifiedBy:
                                        {
                                        email: $email,
                                        name: $name
                                  },
                                Properties:
                                        {
                                        Key: ""pullRequestId"",
                                        Value: $pullRequestId
                                    }
                                }
                              )
                              {
                                name
                                }
                            }";



                q.Variables = new {
                    files         = fileMutationDetailsList,
                    email         = email,
                    name          = authorName,
                    pullRequestId = pullRequestId.ToString()
                };

                var response = graphQlCLient.PostAsync(q).SyncResult();

                Thread.Sleep(2000);

                pullRequestId++;
            }
        }