Beispiel #1
0
        public async Task <MutationCreateCompanyAndXUsersTxn_Output> Execute(MutationCreateCompanyAndXUsersTxn_Input input)//, IServiceProvider serviceProvider, MVCDbContext contextFatherMVC = null, ApplicationDbContext contextFatherApp = null, bool autoCommit = true)
        {
            MutationCreateCompanyAndXUsersTxn_Output output = new MutationCreateCompanyAndXUsersTxn_Output();

            string queryRaw = @"
mutation {
  createCompanyAndXUsersTxn(
    input: {
        company: {
        name: " + SAHBResource.SetArgumentRaw(input.company.name) + @"
        description: " + SAHBResource.SetArgumentRaw(input.company.description) + @"
        email: " + SAHBResource.SetArgumentRaw(input.company.email) + @"
        password: "******"
        }
        usersToCreate: " + input.userstocreate + @"
    }
  ) {
    resultConfirmation {
        resultCode
        resultPassed
        resultMessage
        resultDetail
        resultDictionary {
            tag
            value
        }
    }
    company {
        companyId
        loginTokenId
        tokenAuth
        users
        {
            id
            userAppId
            userName
            firstName
            lastName
            nickname
            alias
            loginTokenId
        }
    }
    }
}

";

            string queryToExecute = " {\"query\":\" " + queryRaw + " \"} ";

            IGraphQLHttpExecutor executor = new GraphQLHttpExecutor();
            var result = await executor.ExecuteQuery(query : queryToExecute, url : input.url, method : HttpMethod.Post, authorizationMethod : "Bearer", authorizationToken : input.token);

            dynamic stuff = JsonConvert.DeserializeObject(result.Response);

            // Find a way to see errors
            bool errors = false;

            //foreach (var error in stuff.errors)
            {
                //System.Diagnostics.Debug.WriteLine("Error: " + error["message"]);
            }

            if (!errors)
            {
                // If no high level errors return the result as it is from server. It may contain errors
                output = stuff.data.createCompanyAndXUsersTxn.ToObject <MutationCreateCompanyAndXUsersTxn_Output>();
            }
            else
            {
                output.company            = null;
                output.ResultConfirmation = new resultConfirmation {
                    resultPassed = false, resultMessage = "ErrorMessage", resultDetail = "resultDetail"
                };
            }

            return(output);
        }
        public async Task <QueryChatsByUserMain_Output> Execute(QueryChatsByUserMain_Input input)//, IServiceProvider serviceProvider, MVCDbContext contextFatherMVC = null, ApplicationDbContext contextFatherApp = null, bool autoCommit = true)
        {
            QueryChatsByUserMain_Output output = new QueryChatsByUserMain_Output();


            string queryRaw = @"
query {
  chatsByUser(userAppId: " + SAHBResource.SetArgumentRaw(input.UserApp.userAppId) + @", take: " + input.takeChats + @") {
    chatId
    name
    comments(
      unseenForUserId: " + SAHBResource.SetArgumentRaw(input.UserApp.userAppId) + @"
      unseenForUserIdTake: " + input.unseenForUserIdTake + @"
      newestWhenNoUnseenTake: " + input.newestWhenNoUnseenTake + @"
    ) {
      commentId
      message
      user {
        userAppId
        nickname
      }
    }
    participants {
      participantId
      userAppId
      user {
        userAppId
        nickname
      }
    }
  }
}

";

            string queryToExecute = " {\"query\":\" " + queryRaw + " \"} ";

            IGraphQLHttpExecutor executor = new GraphQLHttpExecutor();
            var result = await executor.ExecuteQuery(query : queryToExecute, url : input.url, method : HttpMethod.Post, authorizationMethod : "Bearer", authorizationToken : input.token);

            dynamic stuff = JsonConvert.DeserializeObject(result.Response);

            // Find a way to see errors
            bool errors = false;

            //foreach (var error in stuff.errors)
            {
                //System.Diagnostics.Debug.WriteLine("Error: " + error["message"]);
            }

            if (!errors)
            {
                //List<chat> chats = stuff.data.chatsByUser.ToObject<List<chat>>();
                output.Chats = stuff.data.chatsByUser.ToObject <List <chat> >();
                output.ResultConfirmation = new resultConfirmation {
                    resultPassed = true
                };
            }
            else
            {
                output.Chats = null;
                output.ResultConfirmation = new resultConfirmation {
                    resultPassed = false, resultMessage = "ErrorMessage", resultDetail = "resultDetail"
                };
            }

            return(output);
        }
Beispiel #3
0
        public async Task <MutationCreateChatTxn_Output> Execute(MutationCreateChatTxn_Input input)//, IServiceProvider serviceProvider, MVCDbContext contextFatherMVC = null, ApplicationDbContext contextFatherApp = null, bool autoCommit = true)
        {
            MutationCreateChatTxn_Output output = new MutationCreateChatTxn_Output();

            String participantsIn = "";

            foreach (var userin in input.chat.participants)
            {
                string admin = (userin.isAdmin == true) ? "true" : "false";

                participantsIn += @"
                {
                    participantId: 0
                    chatId: 0
                    isAdmin: " + admin + @"
                    userAppId: " + SAHBResource.SetArgumentRaw(userin.userAppId) + @"
                }
                ";
            }

            string queryRaw = @"

mutation
{
  createChatTxn(input:
  {
    chat:
    {
      chatId:0
      name:" + SAHBResource.SetArgumentRaw(input.chat.name) + @"
      companyId: " + SAHBResource.SetArgumentRaw(input.chat.companyId) + @"
      participants:
      [
      " + participantsIn + @"    
      ]
    }
    }
  )
  {
    resultConfirmation {
      resultCode
      resultPassed
      resultMessage
      resultDetail
      resultDictionary {
        tag
        value
      }
    }
    chat
    {
      chatId
    }
  }
}


";

            string queryToExecute = " {\"query\":\" " + queryRaw + " \"} ";

            IGraphQLHttpExecutor executor = new GraphQLHttpExecutor();
            var result = await executor.ExecuteQuery(query : queryToExecute, url : input.url, method : HttpMethod.Post, authorizationMethod : "Bearer", authorizationToken : input.token);

            dynamic stuff = JsonConvert.DeserializeObject(result.Response);

            // Find a way to see errors
            bool errors = false;

            //foreach (var error in stuff.errors)
            {
                //System.Diagnostics.Debug.WriteLine("Error: " + error["message"]);
            }

            if (!errors)
            {
                // If no high level errors return the result as it is from server. It may contain errors
                output = stuff.data.createChatTxn.ToObject <MutationCreateChatTxn_Output>();
            }
            else
            {
                output.chat = null;
                output.ResultConfirmation = new resultConfirmation {
                    resultPassed = false, resultMessage = "ErrorMessage", resultDetail = "resultDetail"
                };
            }

            return(output);
        }
Beispiel #4
0
        public async Task <QueryRetrieveMasterInformationByUser_Output> Execute(QueryRetrieveMasterInformationByUser_Input input)//, IServiceProvider serviceProvider, MVCDbContext contextFatherMVC = null, ApplicationDbContext contextFatherApp = null, bool autoCommit = true)
        {
            QueryRetrieveMasterInformationByUser_Output output = new QueryRetrieveMasterInformationByUser_Output();

            string queryRaw = @"
mutation {
  retrieveMasterInformationByUser(
    input: {
      user: { userAppId: " + SAHBResource.SetArgumentRaw(input.UserApp.userAppId) + @" }
      chatsRecentTake: " + input.chatsRecentTake + @"
      commentsSeenTake: " + input.commentsSeenTake + @"
      commentsUnseenTake: " + input.commentsUnseenTake + @"
      commentsNewestTake: " + input.commentsNewestTake + @"
      commentsBeforeUnseenTake: " + input.commentsBeforeUnseenTake + @"
      findSpecificChatId: " + input.findSpecificChatId + @"
    }
  ) {
    commentsUnseen {
      chatId
      commentId
      userAppId
      message
      commentsInfo(infoForUserId: " + SAHBResource.SetArgumentRaw(input.UserApp.userAppId) + @") 
        {
            userAppId
            seen
        delivered
      }
    }
    commentsSeen {
      chatId
      commentId
      userAppId
      message
      commentsInfo(infoForUserId: " + SAHBResource.SetArgumentRaw(input.UserApp.userAppId) + @") 
    {
        userAppId
        seen
        delivered
      }
}
commentsNewest {
      chatId
      commentId
      userAppId
      message
      commentsInfo(infoForUserId: " + SAHBResource.SetArgumentRaw(input.UserApp.userAppId) + @") 
{
    userAppId
    seen
        delivered
      }
      
    }
    resultConfirmation
    {
      resultPassed
    }
  }
}

";

            string queryToExecute = " {\"query\":\" " + queryRaw + " \"} ";

            IGraphQLHttpExecutor executor = new GraphQLHttpExecutor();
            var result = await executor.ExecuteQuery(query : queryToExecute, url : input.url, method : HttpMethod.Post, authorizationMethod : "Bearer", authorizationToken : input.token);

            dynamic stuff = JsonConvert.DeserializeObject(result.Response);

            // Find a way to see errors
            bool errors = false;

            //foreach (var error in stuff.errors)
            {
                //System.Diagnostics.Debug.WriteLine("Error: " + error["message"]);
            }

            if (!errors)
            {
                /*
                 * output.commentsUnseen = stuff.data.retrieveMasterInformationByUser.commentsUnseen.ToObject<comment>();
                 * output.commentsSeen = stuff.data.retrieveMasterInformationByUser.commentsSeen.ToObject<comment>();
                 * output.commentsNewest = stuff.data.retrieveMasterInformationByUser.commentsNewest.ToObject<comment>();
                 * output.ResultConfirmation = new resultConfirmation { resultPassed = true, resultMessage = "OK", resultDetail = "" };
                 */
                // output = stuff.data.createCompanyAndXUsersTxn.ToObject<MutationCreateCompanyAndXUsersTxn_Output>();
                output = stuff.data.retrieveMasterInformationByUser.ToObject <QueryRetrieveMasterInformationByUser_Output>();
            }
            else
            {
                //output.company = null;
                output.ResultConfirmation = new resultConfirmation {
                    resultPassed = false, resultMessage = "ErrorMessage", resultDetail = "resultDetail"
                };
            }

            return(output);
        }
Beispiel #5
0
        public async Task <MutationAddCommentToChatTxn_Output> Execute(MutationAddCommentToChatTxn_Input input)//, IServiceProvider serviceProvider, MVCDbContext contextFatherMVC = null, ApplicationDbContext contextFatherApp = null, bool autoCommit = true)
        {
            MutationAddCommentToChatTxn_Output output = new MutationAddCommentToChatTxn_Output();

            string queryRaw = @"
mutation {
  addCommentToChatTxn(
    input: {
      comment: {
        commentId: 0
        chatId: " + input.comment.chatId + @"
        message: " + SAHBResource.SetArgumentRaw(input.comment.message) + @"
        userAppId: " + SAHBResource.SetArgumentRaw(input.comment.userAppId) + @"
      }
    }
  ) {
    resultConfirmation {
      resultCode
      resultPassed
      resultMessage
      resultDetail
      resultDictionary {
        tag
        value
      }
    }
    comment {
     commentId
     message
    }
  }
}

";

            string queryToExecute = " {\"query\":\" " + queryRaw + " \"} ";

            IGraphQLHttpExecutor executor = new GraphQLHttpExecutor();
            var result = await executor.ExecuteQuery(query : queryToExecute, url : input.url, method : HttpMethod.Post, authorizationMethod : "Bearer", authorizationToken : input.token);

            dynamic stuff = JsonConvert.DeserializeObject(result.Response);

            // Find a way to see errors
            bool errors = false;

            //foreach (var error in stuff.errors)
            {
                //System.Diagnostics.Debug.WriteLine("Error: " + error["message"]);
            }

            if (!errors)
            {
                // If no high level errors return the result as it is from server. It may contain errors
                output = stuff.data.addCommentToChatTxn.ToObject <MutationAddCommentToChatTxn_Output>();
                //List<chat> chats = stuff.data.chatsByUser.ToObject<List<chat>>();
                //output.comment = stuff.data.addCommentToChatTxn.ToObject<comment>();
                //output.ResultConfirmation = new resultConfirmation { resultPassed = true };
            }
            else
            {
                output.comment            = null;
                output.ResultConfirmation = new resultConfirmation {
                    resultPassed = false, resultMessage = "ErrorMessage", resultDetail = "resultDetail"
                };
            }

            return(output);
        }
        public async Task <QueryAllUsersByCompany_Output> Execute(QueryAllUsersByCompany_Input input)//, IServiceProvider serviceProvider, MVCDbContext contextFatherMVC = null, ApplicationDbContext contextFatherApp = null, bool autoCommit = true)
        {
            QueryAllUsersByCompany_Output output = new QueryAllUsersByCompany_Output();


            string queryRaw = @"
query allusersbycompany {
  company(id: " + SAHBResource.SetArgumentRaw(input.company.companyId) + @") {
    companyId
    users {
                id
                userAppId
      firstName
      lastName
      userName
      nickname
      alias
      email
      lastSeen
      department {
                    departmentId
                    name
      }
                groups {
                    groupofId
                    name
                }
            }
        }
    }

";

            string queryToExecute = " {\"query\":\" " + queryRaw + " \"} ";

            IGraphQLHttpExecutor executor = new GraphQLHttpExecutor();
            var result = await executor.ExecuteQuery(query : queryToExecute, url : input.url, method : HttpMethod.Post, authorizationMethod : "Bearer", authorizationToken : input.token);

            dynamic stuff = JsonConvert.DeserializeObject(result);

            // Find a way to see errors
            bool errors = false;

            //foreach (var error in stuff.errors)
            {
                //System.Diagnostics.Debug.WriteLine("Error: " + error["message"]);
            }

            if (!errors)
            {
                output.company            = stuff.data.company.ToObject <company>();
                output.ResultConfirmation = new resultConfirmation {
                    resultPassed = true, resultMessage = "OK", resultDetail = ""
                };
            }
            else
            {
                output.company            = null;
                output.ResultConfirmation = new resultConfirmation {
                    resultPassed = false, resultMessage = "ErrorMessage", resultDetail = "resultDetail"
                };
            }

            return(output);
        }
Beispiel #7
0
        static async Task Main(string[] args)
        {
            IGraphQLHttpClient client = GraphQLHttpClient.Default();

            // Get response from url using the HeroQuery object
            var response = await client.Query <HeroQuery>("https://mpjk0plp9.lp.gql.zone/graphql");

            Console.WriteLine(response.Hero.Name);

            // Get response from url using a generated object
            var query = client.CreateQuery(builder =>
                                           builder.Field("hero",
                                                         hero =>
                                                         hero
                                                         .Field("name")
                                                         .Field("friends",
                                                                friends =>
                                                                friends.Alias("MyFriends").Field("name"))),
                                           "https://mpjk0plp9.lp.gql.zone/graphql");
            var builderResponse = await query.Execute();

            Console.WriteLine(builderResponse["hero"]["name"].Value);
            foreach (var friend in builderResponse["hero"]["MyFriends"])
            {
                Console.WriteLine(friend["name"].Value);
            }

            // Get response from url using a generated object without alias
            query = client.CreateQuery(builder =>
                                       builder.Field("hero",
                                                     hero =>
                                                     hero
                                                     .Field("name")
                                                     .Field("friends",
                                                            friends =>
                                                            friends.Field("name"))),
                                       "https://mpjk0plp9.lp.gql.zone/graphql");
            builderResponse = await query.Execute();

            Console.WriteLine(builderResponse["hero"]["name"].Value);

            var character = await client.Query <CharacterQuery>("https://mpjk0plp9.lp.gql.zone/graphql", arguments : new GraphQLQueryArgument("characterID", "1000"));

            if (character.Character is Human human)
            {
                Console.WriteLine("Human!: " + human.Height);
            }

            // Create batch
            var batch = client.CreateBatch("https://mpjk0plp9.lp.gql.zone/graphql");

            // Create two requests in the batch
            var queryId1000 = batch.Query <CharacterQuery>(new GraphQLQueryArgument("characterID", "1000"));
            var queryId1001 = batch.Query <CharacterQuery>(new GraphQLQueryArgument("characterID", "1001"));

            // Execute the batch
            var queryId1000Result = await queryId1000.Execute();

            var queryId1001Result = await queryId1001.Execute();

            // Get result
            Console.WriteLine(queryId1000Result.Character.Name);
            Console.WriteLine(queryId1001Result.Character.Name);

            if (queryId1000Result.Character is Human human2)
            {
                Console.WriteLine("Human!: " + human2.Height);
            }
            else if (queryId1000Result.Character is Droid droid2)
            {
                Console.WriteLine("Droid!: " + droid2.PrimaryFunction);
            }

            // Create executor
            IGraphQLHttpExecutor executor = new GraphQLHttpExecutor();
            var result = await executor.ExecuteQuery(@"{""query"":""query{Hero:hero{Name:name Friends:friends{Name:name}}}""}",
                                                     "https://mpjk0plp9.lp.gql.zone/graphql", HttpMethod.Post);

            IGraphQLDeserialization graphQLDeserialization = new GraphQLDeserilization();

            var deserilizedResult = graphQLDeserialization.DeserializeResult <HeroQuery>(result.Response, null);

            Console.WriteLine(deserilizedResult.Data.Hero.Name);

            // Using dependency injection and console logging
            var serviceCollection = new ServiceCollection();

            serviceCollection
            .AddLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Information))
            .AddGraphQLHttpClient();
            var serviceProvider = serviceCollection.BuildServiceProvider();

            // Get client
            client = serviceProvider.GetRequiredService <IGraphQLHttpClient>();

            // Get response from url using the HeroQuery object
            response = await client.Query <HeroQuery>("https://mpjk0plp9.lp.gql.zone/graphql");

            Console.WriteLine(response.Hero.Name);

            // Swapi
            var swapiResponse = await client.Query <SwapiQuery>("https://swapi.apis.guru/");

            foreach (var movie in swapiResponse.AllFilms.Films)
            {
                Console.WriteLine(movie.Title);
            }

            var filmResponse = await client.Query <FilmQuery>("https://swapi.apis.guru/",
                                                              arguments : new GraphQLQueryArgument("filmIdVariable", "6"));

            Console.WriteLine(filmResponse.Film.Title);

            Console.ReadKey();
        }