Exemple #1
0
        static void Main(string[] args)
        {
            var client = new GraphQLClient("http://*****:*****@"
                query {
                  users {
                    edges {
                      node {
                        name 
                        email
                      }
                    }
                  }
                }
            ";

            var obj = client.Query(query, null).Get("users");

            if (obj != null)
            {
                Console.WriteLine("success ");
            }
            else
            {
                Console.WriteLine("Null :(");
            }

            Console.WriteLine("MUTATION ---------------- ");

            var mutation = "mutation { LoginEmail(input: { clientMutationId: \"abc\" email: \"[email protected]\" password: \"boratino\" }) { clientMutationId token error }}";
            var result   = client.Query(mutation, null).Get("LoginEmail");


            Console.WriteLine("MUTATION PARAM ---------------- ");

            mutation = @"mutation($input: LoginEmailInput!) { 
                            LoginEmail(input: $input) { 
                                clientMutationId 
                                token 
                                error 
                            }
                        }";
            var result2 = client.Query(mutation, new { input = new { clientMutationId = "abc", email = "*****@*****.**", password = "******" } }).Get("LoginEmail");

            Console.ReadLine();
        }
    public IEnumerator MutationCall()
    {
        GraphQLClient client = new GraphQLClient(apiUrl);

        Member memberInput = new Member()
        {
            name  = "Bob Jones",
            email = "*****@*****.**"
        };

        string variables = @"{""input"": " + JsonUtility.ToJson(memberInput) + " }";

        using (UnityWebRequest www = client.Query(mutation, variables, "AddMember")) {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);
                // handle error
            }
            else
            {
                string     responseString = www.downloadHandler.text;
                JSONObject reponse        = new JSONObject(responseString);

                // handle json result with JSONObject
            }
        }
    }
    public IEnumerator QueryCall(System.Action <bool> callback)
    {
        GraphQLClient client = new GraphQLClient(apiUrl);

        using (UnityWebRequest www = client.Query(query, "", "")) {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);

                callback(false);
            }
            else
            {
                string     responseString = www.downloadHandler.text;
                JSONObject response       = new JSONObject(responseString);
                JSONObject data           = response.GetField("data");
                JSONObject organizations  = data.GetField("organizations");
                accessData(organizations);


                callback(true);
            }
        }
    }
Exemple #4
0
        public void TestETMDB()
        {
            //https://etmdb.com/graphql?

            var etmdbQuery = GraphQLQueryBuilder.New()
                             .Query("allFilmographyTypes", args =>
            {
                args.Param("first", "10");
            }, select =>
            {
                select.Field("edges").Select(edges =>
                {
                    edges.Field("node").Select(node =>
                    {
                        node.Field("slug");
                    });
                });
            }).Build(GraphQLFormatting.None);

            var client = new GraphQLClient("https://etmdb.com/graphql");

            var result = client.Query(etmdbQuery);

            Assert.IsFalse(result.Errors.Any());
            Assert.IsNotNull(result.Data);
        }
Exemple #5
0
 public void Query(string query, object variables = null, Action <GraphQLResponse> callback = null)
 {
     if (hasToken)
     {
         client.Query(query, fetcher.token.access_token, callback);
     }
 }
Exemple #6
0
        private async Task RequestDetail(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var             reply   = context.MakeMessage();
            var             message = await argument;
            var             query3  = @"query($headRefName: String!) { 
                                      viewer { 
                                      pullRequests (first : 100, headRefName : $headRefName){
                                        edges {   
                                          node {
                                            id
                                            title
                                            body
                                            state
                                            headRefName
                                            revertUrl
                                            url
                                            repository {
                                                nameWithOwner
                                            }
                                            headRefName
                                          }
                                        }
                                      }
                                      }
                                    }";
            var             client  = new GraphQLClient();
            string          data    = client.Query(query3, new { headRefName = message.Text });
            RootPullRequest obj     = Newtonsoft.Json.JsonConvert.DeserializeObject <RootPullRequest>(data);

            if (obj.data.viewer.pullRequests.edges.Count == 0)
            {
                reply.Text = "No pull request found.";
            }
            else
            {
                HeroCard card = new HeroCard
                {
                    Title = obj.data.viewer.pullRequests.edges[0].node.headRefName,
                    Text  = "<b>Id         :</b>" + obj.data.viewer.pullRequests.edges[0].node.id + "</br>"
                            + "<b>Body       :</b>" + obj.data.viewer.pullRequests.edges[0].node.body + "</br>"
                            + "<b>State      :</b>" + obj.data.viewer.pullRequests.edges[0].node.state + "</br>"
                            + "<b>RevertUrl  :</b>" + obj.data.viewer.pullRequests.edges[0].node.revertUrl + "</br>"
                            + "<b>Repository :</b>" + obj.data.viewer.pullRequests.edges[0].node.repository.nameWithOwner,
                    Buttons = new List <CardAction> {
                        new CardAction(ActionTypes.OpenUrl, "More Info", value: obj.data.viewer.pullRequests.edges[0].node.url)
                    }
                };
                reply.Attachments = new List <Attachment>();
                reply.Attachments.Add(card.ToAttachment());
            }

            await context.PostAsync(reply);

            context.Done <object>(new object());
        }
Exemple #7
0
 void Start()
 {
     Debug.Log("Starting!");
     if (unansweredQuestions == null || unansweredQuestions.Count == 0)
     {
         if (graphQLClient == null)
         {
             graphQLClient = new GraphQLClient(graphQLEndpoint);
         }
         graphQLClient.Query(QuestionsQuery, callback: QuestionsCallback);
         return;
     }
     SetCurrentQuestion();
 }
Exemple #8
0
    private IEnumerator AuthentifyingPlayer(string accessToken, Action <bool> callback)
    {
        string query = @"query authUser($accessToken:String!) { authUser(accessToken:$accessToken) {_id, turns,type}}";

        string variable = "{\"accessToken\":\"" + accessToken + "\"}";

        using (UnityWebRequest www = client.Query(query, variable, "authUser"))
        {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);

                callback?.Invoke(false);
            }
            else
            {
                string responseString = www.downloadHandler.text;
                bool   isError        = IsResponseError(responseString);
                Debug.Log(responseString);
                if (!isError)
                {
                    JSONObject response = new JSONObject(responseString);
                    userId = response.GetField("data").GetField("authUser").GetField("_id").str;
                    Turns  = Convert.ToInt16(response.GetField("data").GetField("authUser").GetField("turns").i);
                    Type   = Convert.ToInt16(response.GetField("data").GetField("authUser").GetField("type").i);
                }
                else
                {
                    Debug.Log("error:" + responseString);
                }

                callback?.Invoke(!isError);
            }
        }
    }
        public async Task DreamersController_POST_CreateDreamer()
        {
            // Arrange
            var count    = 20;
            var random   = new Random();
            var requests = _fixture
                           .Build <CreateDreamerRequestFake>()
                           .With(d => d.Age, random.Next(1, 119))
                           .With(d => d.Gender, GenderEnum.Female)
                           .CreateMany(count)
                           .Select(dreamer =>
            {
                var json = JsonConvert.SerializeObject(dreamer);
                var data = new StringContent(json, Encoding.UTF8, "application/json");

                return(data);
            });
            var query           = @"
                    query DreamerQuery {
                      dreamers {
                        dreamerId
                        age
                        gender
                        firstName
                        lastName
                      }
                    }                    
                ";
            var dreamersRequest = new GraphQLRequest
            {
                Query = query
            };
            // Act
            var responses = await Task.WhenAll(requests.Select(r => _client.PostAsync($"/api/dreamers", r)));

            var graphResponse = await _graphQL.Query <DreamerResponse>(query);

            // Assert
            Assert.Equal(count, graphResponse.Dreamers.Length);
            foreach (var response in responses)
            {
                response.EnsureSuccessStatusCode(); // Status Code 200-299
                Assert.Equal("application/json; charset=utf-8",
                             response.Content.Headers.ContentType.ToString());
            }
        }
Exemple #10
0
        private async Task RepositoryDetailData(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var reply   = context.MakeMessage();
            var message = await argument;

            var    query3             = @"query($owner: String!,$name: String! ) {
                                                repository(owner: $owner, name: $name)
                                                {
                                                  id
                                                  name
                                                  homepageUrl
                                                  resourcePath
                                                  isPrivate
                                                  updatedAt
                                                  createdAt
                                                  nameWithOwner
                                                            }
                                                        }";
            var    client             = new GraphQLClient();
            string data               = client.Query(query3, new { owner = "poonam0025", name = message.Text });
            RepositoryRootObject obj  = Newtonsoft.Json.JsonConvert.DeserializeObject <RepositoryRootObject>(data);
            HeroCard             card = new HeroCard
            {
                Title = message.Text,
                Text  = "<b>Id : </b> " + obj.data.repository.id + "</br>"
                        + "<b>Resource path : </b> " + obj.data.repository.resourcePath + "</br>"
                        + "<b>IsPrivate : </b> " + obj.data.repository.isPrivate + "</br>"
                        + "<b>CreatedAt : </b> " + Convert.ToDateTime(obj.data.repository.createdAt).ToString("dd MMM yyyy hh:mm:ss tt") + "</br>"
                        + "<b>UpdatedAt : </b> " + Convert.ToDateTime(obj.data.repository.updatedAt).ToString("dd MMM yyyy hh:mm:ss tt") + "</br>"
                        + "<b>Name with Owner : </b> " + obj.data.repository.nameWithOwner,
                Buttons = new List <CardAction> {
                    new CardAction(ActionTypes.OpenUrl, "More Info", value: obj.data.repository.url)
                }
            };

            reply.Attachments = new List <Attachment>();
            reply.Attachments.Add(card.ToAttachment());
            await context.PostAsync(reply);

            context.Done <object>(new object());
        }
Exemple #11
0
        public async Task StartAsync(IDialogContext context)
        {
            var               reply  = context.MakeMessage();
            HeroCard          card   = new HeroCard();
            var               query  = @"query  {
                    viewer{
                        name
                      repositories(first: 100)
                      {
                        nodes
                        {
                           name
                        }
                        }
                    }
                }";
            var               client = new GraphQLClient();
            string            data   = client.Query(query, null);
            AllRepository     obj    = Newtonsoft.Json.JsonConvert.DeserializeObject <AllRepository>(data);
            List <CardAction> button = new List <CardAction>();
            CardAction        cardAction;

            foreach (Node1 rep in obj.data.viewer.repositories.nodes)
            {
                cardAction = new CardAction(ActionTypes.ImBack, rep.name, value: rep.name);
                button.Add(cardAction);
            }
            card.Title    = "Below are your repositories";
            card.Subtitle = "To get detail click on it";
            card.Buttons  = button;
            Attachment attachment = card.ToAttachment();

            reply.Attachments.Add(attachment);
            await context.PostAsync(reply);

            context.Wait(RepositoryDetailData);
        }
Exemple #12
0
        /// <summary>
        /// Helper method to generate a compose extension
        ///
        /// Note that for this sample, we are returning generated positions for illustration purposes only.
        /// </summary>
        /// <returns></returns>
        public ComposeExtensionResponse CreateResponse()
        {
            try
            {
                ComposeExtensionResponse   response = null;
                ComposeExtensionAttachment composeExtensionAttachment = new ComposeExtensionAttachment();
                var query   = activity.GetComposeExtensionQueryData();
                var results = new ComposeExtensionResult()
                {
                    AttachmentLayout = "list",
                    Type             = "result",
                    Attachments      = new List <ComposeExtensionAttachment>(),
                };
                string text = "";
                //Check to make sure a query was actually made:
                if (query.CommandId == null || query.Parameters == null)
                {
                    return(null);
                }
                else if (query.Parameters.Count > 0)
                {
                    // query.Parameters has the parameters sent by client

                    string headRefName = "";

                    if (query.CommandId == "PRs")
                    {
                        var titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "PRs" || p.Name == "Repos" || p.Name == "Issues");
                        if (titleParam != null)
                        {
                            headRefName = titleParam.Value.ToString().ToLower();
                        }

                        var             query3 = @"query($headRefName: String!) { 
                                      viewer { 
                                      pullRequests (first : 100, headRefName : $headRefName){
                                        edges {   
                                          node {
                                            id
                                            title
                                            body
                                            state
                                            headRefName
                                            revertUrl
                                            url
                                            repository {
                                                nameWithOwner
                                            }
                                            headRefName
                                          }
                                        }
                                      }
                                      }
                                    }";
                        var             client = new GraphQLClient();
                        string          data   = client.Query(query3, new { headRefName = headRefName });
                        RootPullRequest obj    = Newtonsoft.Json.JsonConvert.DeserializeObject <RootPullRequest>(data);


                        if (obj.data.viewer.pullRequests.edges.Count == 0)
                        {
                            text = "No  pull request exists.";
                        }
                        else
                        {
                            HeroCard card = new HeroCard
                            {
                                Title = obj.data.viewer.pullRequests.edges[0].node.headRefName,
                                Text  = "<b>Id         :</b>" + obj.data.viewer.pullRequests.edges[0].node.id + "</br>"
                                        + "<b>Body       :</b>" + obj.data.viewer.pullRequests.edges[0].node.body + "</br>"
                                        + "<b>State      :</b>" + obj.data.viewer.pullRequests.edges[0].node.state + "</br>"
                                        + "<b>RevertUrl  :</b>" + obj.data.viewer.pullRequests.edges[0].node.revertUrl + "</br>"
                                        + "<b>Repository :</b>" + obj.data.viewer.pullRequests.edges[0].node.repository.nameWithOwner,
                                Buttons = new List <CardAction> {
                                    new CardAction(ActionTypes.OpenUrl, "More Info", value: obj.data.viewer.pullRequests.edges[0].node.url)
                                }
                            };
                            composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                        }

                        if (text != "")
                        {
                            results.Text = text;
                        }
                        else
                        {
                            results.Attachments.Add(composeExtensionAttachment);
                        }
                    }
                    else if (query.CommandId == "Repos")
                    {
                        string repository = "";
                        var    titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "PRs" || p.Name == "Repos" || p.Name == "Issues");
                        if (titleParam != null)
                        {
                            repository = titleParam.Value.ToString().ToLower();
                        }
                        var    query3            = @"query($owner: String!,$name: String! ) {
                                                repository(owner: $owner, name: $name)
                                                {
                                                  id
                                                  name
                                                  homepageUrl
                                                  resourcePath
                                                  isPrivate
                                                  updatedAt
                                                  createdAt
                                                  nameWithOwner
                                                  url
                                                            }
                                                        }";
                        var    client            = new GraphQLClient();
                        string data              = client.Query(query3, new { owner = "poonam0025", name = repository });
                        RepositoryRootObject obj = Newtonsoft.Json.JsonConvert.DeserializeObject <RepositoryRootObject>(data);

                        if (obj.data.repository == null)
                        {
                            text = "No " + repository + "found.";
                        }
                        else
                        {
                            HeroCard card = new HeroCard
                            {
                                Title = repository,
                                Text  = "<b>Id : </b> " + obj.data.repository.id + "</br>"
                                        + "<b>Resource path : </b> " + obj.data.repository.resourcePath + "</br>"
                                        + "<b>IsPrivate : </b> " + obj.data.repository.isPrivate + "</br>"
                                        + "<b>CreatedAt : </b> " + Convert.ToDateTime(obj.data.repository.createdAt).ToString("dd MMM yyyy hh:mm:ss tt") + "</br>"
                                        + "<b>UpdatedAt : </b> " + Convert.ToDateTime(obj.data.repository.updatedAt).ToString("dd MMM yyyy hh:mm:ss tt") + "</br>"
                                        + "<b>Name with Owner : </b> " + obj.data.repository.nameWithOwner,
                                Buttons = new List <CardAction> {
                                    new CardAction(ActionTypes.OpenUrl, "More Info", value: obj.data.repository.url)
                                }
                            };

                            composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                        }

                        if (text != "")
                        {
                            results.Text = text;
                        }
                        else
                        {
                            results.Attachments.Add(composeExtensionAttachment);
                        }
                    }

                    else if (query.CommandId == "Issues")
                    {
                        string repository = "";
                        var    titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "PRs" || p.Name == "Repos" || p.Name == "Issues");
                        if (titleParam != null)
                        {
                            repository = titleParam.Value.ToString().ToLower();
                        }
                        var    query3 = @"query($owner:String!,$name:String!) {
                                repository(owner : $owner, name: $name)
                                  {
                                    issues(first:20) { 
                                      edges { 
                                        node { 
                                          title 
                                          url 
                                          state
                                          body
                                          createdAt
                                        } 
                                      } 
                                    } 
                                  } 
                                }";
                        var    client = new GraphQLClient();
                        string data   = client.Query(query3, new { owner = "poonam0025", name = repository });
                        RepositoryDetailRoot repositorydata = Newtonsoft.Json.JsonConvert.DeserializeObject <RepositoryDetailRoot>(data);

                        if (repositorydata.data.repository.issues.edges.Count == 0)
                        {
                            text = "No issue found.";
                        }
                        else
                        {
                            HeroCard card = new HeroCard();
                            for (int i = 0; i < repositorydata.data.repository.issues.edges.Count; i++)
                            {
                                card = new HeroCard
                                {
                                    Title = "<b>" + repositorydata.data.repository.issues.edges[i].node.title + "</b>",
                                    Text  = "<b>Description     :</b>" + repositorydata.data.repository.issues.edges[i].node.body + "</br>"
                                            + "<b>Created At  :</b>" + Convert.ToDateTime(repositorydata.data.repository.issues.edges[i].node.createdAt).ToString("dd MMM yyyy hh:mm:ss tt") + "</br>"
                                            + "<b>State :</b>" + repositorydata.data.repository.issues.edges[i].node.state,
                                    Buttons = new List <CardAction> {
                                        new CardAction(ActionTypes.OpenUrl, "More Info", value: repositorydata.data.repository.issues.edges[i].node.url)
                                    }
                                };

                                composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                                results.Attachments.Add(composeExtensionAttachment);
                            }
                        }
                    }

                    response = new ComposeExtensionResponse()
                    {
                        ComposeExtension = results
                    };
                }
                return(response);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public string GetHello()
        {
            var client = new GraphQLClient(_connection);

            return(client.Query("{ hello }", null).Get <string>("hello"));
        }
        public async Task StartAsync(IDialogContext context)
        {
            var reply = context.MakeMessage();
            List <AdaptiveChoice> choice = new List <AdaptiveChoice>();

            choice.Add(new AdaptiveChoice()
            {
                Title = "--Select option--", Value = "--Select option--"
            });
            var query = @"query  {
                    viewer{
                        name
                      repositories(first: 100)
                      {
                         nodes
                        {
                         name
                        }
                      }
                    }
                }";

            var           client = new GraphQLClient();
            string        data   = client.Query(query, null);
            AllRepository obj    = Newtonsoft.Json.JsonConvert.DeserializeObject <AllRepository>(data);

            foreach (Node1 rep in obj.data.viewer.repositories.nodes)
            {
                choice.Add(new AdaptiveChoice()
                {
                    Title = rep.name, Value = rep.name
                });
            }
            AdaptiveCard card = new AdaptiveCard()
            {
                Body = new List <AdaptiveElement>()
                {
                    new AdaptiveTextBlock()
                    {
                        Text = "Search Issue", Weight = AdaptiveTextWeight.Bolder, Size = AdaptiveTextSize.Large, Wrap = true, HorizontalAlignment = AdaptiveHorizontalAlignment.Center
                    },
                    new AdaptiveTextBlock()
                    {
                        Text = "Select Repository"
                    },
                    new AdaptiveChoiceSetInput()
                    {
                        Id = "Repository", Style = AdaptiveChoiceInputStyle.Compact, Choices = choice
                    },
                    new AdaptiveTextBlock()
                    {
                        Text = "Select Issue State"
                    },
                    new AdaptiveChoiceSetInput()
                    {
                        Id      = "State", Value = "--ALL--", IsMultiSelect = false, Style = AdaptiveChoiceInputStyle.Compact,
                        Choices = new List <AdaptiveChoice>()
                        {
                            new AdaptiveChoice()
                            {
                                Title = "--ALL--", Value = "--ALL--"
                            },
                            new AdaptiveChoice()
                            {
                                Title = "OPEN",
                                Value = "OPEN"
                            },
                            new AdaptiveChoice()
                            {
                                Title = "CLOSED",
                                Value = "CLOSED"
                            }
                        }
                    }
                },
                Actions = new List <AdaptiveAction>()
                {
                    new AdaptiveSubmitAction()
                    {
                        Title    = "Submit",
                        Id       = "IssueDetail",
                        DataJson = @"{""Action"":""GetIssueDetail""}"
                    }
                }
            };

            Microsoft.Bot.Connector.Attachment attachment = new Microsoft.Bot.Connector.Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card,
                //  Name = "ABCD"
            };

            reply.Attachments.Add(attachment);
            await context.PostAsync(reply);

            context.Done <object>(new object());
        }
        private static async Task <Activity> SearchData(TeamsSubmit obj, Activity activity)
        {
            Activity replyActivity = activity.CreateReply();

            if (obj.Repository == "--Select option--")
            {
                replyActivity.Text = "Please select Repository";
            }
            else
            {
                string data   = "";
                var    client = new GraphQLClient();
                if (obj.State == "--ALL--")
                {
                    var query = @"query($owner:String!,$name:String!) {
                                repository(owner : $owner, name: $name)
                                  {
                                    issues(first:20) { 
                                      edges { 
                                        node { 
                                          title 
                                          url 
                                          state
        
                                        } 
                                      } 
                                    } 
                                  } 
                                }";
                    data = client.Query(query, new { owner = "poonam0025", name = obj.Repository });
                }
                else
                {
                    var query = @"query($owner:String!,$name:String!, $Issuestate:[IssueState!]) {
                                repository(owner : $owner, name: $name)
                                  {
                                    issues(first:20, states:$Issuestate) { 
                                      edges { 
                                        node { 
                                          title 
                                          createdAt
                                          body
                                          url 
                                          state
        
                                        } 
                                      } 
                                    } 
                                  } 
                                }";
                    data = client.Query(query, new { owner = "poonam0025", name = obj.Repository, states = obj.State });
                }
                RepositoryDetailRoot repositorydata = new RepositoryDetailRoot();
                try
                {
                    repositorydata = Newtonsoft.Json.JsonConvert.DeserializeObject <RepositoryDetailRoot>(data);
                }
                catch (Exception EX)
                {
                }

                if (repositorydata.data.repository.issues.edges.Count == 0)
                {
                    replyActivity.Text = "No issue found under this repository";
                }
                else
                {
                    HeroCard card = new HeroCard();
                    replyActivity.Attachments = new List <Attachment>();
                    replyActivity.Text        = "Below are the issue detail of " + obj.Repository;
                    for (int i = 0; i < repositorydata.data.repository.issues.edges.Count; i++)
                    {
                        card = new HeroCard
                        {
                            Title = repositorydata.data.repository.issues.edges[i].node.title,
                            Text  = "<b>Description     :</b>" + repositorydata.data.repository.issues.edges[i].node.body + "</br>"
                                    + "<b>Created At  :</b>" + Convert.ToDateTime(repositorydata.data.repository.issues.edges[i].node.createdAt).ToString("dd MMM yyyy hh:mm:ss tt") + "</br>"
                                    + "<b>State :</b>" + repositorydata.data.repository.issues.edges[i].node.state,
                            Buttons = new List <CardAction> {
                                new CardAction(ActionTypes.OpenUrl, "More Info", value: repositorydata.data.repository.issues.edges[i].node.url)
                            }
                        };

                        replyActivity.Attachments.Add(card.ToAttachment());
                    }
                }
            }
            return(replyActivity);
        }