Search in sources :

Example 1 with GraphQLRequest

use of org.allGraphQLCases.client.util.GraphQLRequest in project graphql-maven-plugin-project by graphql-java-generator.

the class FullQueriesIT method test_Issue65_withGraphQLValuedParameter.

@Test
@Execution(ExecutionMode.CONCURRENT)
void test_Issue65_withGraphQLValuedParameter() throws GraphQLRequestPreparationException, GraphQLRequestExecutionException {
    // Preparation
    String request = // 
    "mutation mut1 {" + // 
    "createHuman (human:  {name: \"a name with a string that contains a \\\", two { { and a } \", friends: [], appearsIn: [JEDI,NEWHOPE]} )" + "@testDirective(value:?value, anotherValue:?anotherValue, anArray  : [  \"a string that contains [ [ and ] that should be ignored\" ,  \"another string\" ] , \r\n" + "anObject:{    name: \"a name\" , appearsIn:[],friends : [{name:\"subname\",appearsIn:[],type:\"\"}],type:\"type\"})   {id name appearsIn friends {id name}}}";
    GraphQLRequest graphQLRequest = new GraphQLRequest(request);
    // Go, go, go
    Human human = mutationType.execWithBindValues(graphQLRequest, null).getCreateHuman();
    // Verifications
    assertEquals("a name with a string that contains a \", two { { and a } ", human.getName());
}
Also used : Human(org.allGraphQLCases.client.Human) GraphQLRequest(org.allGraphQLCases.client.util.GraphQLRequest) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with GraphQLRequest

use of org.allGraphQLCases.client.util.GraphQLRequest in project graphql-maven-plugin-project by graphql-java-generator.

the class FullQueriesIT method test_Issue82_IntParameter.

@Test
@Execution(ExecutionMode.CONCURRENT)
void test_Issue82_IntParameter() throws GraphQLRequestPreparationException, GraphQLRequestExecutionException {
    // Preparation
    GraphQLRequest request = myQuery.getGraphQLRequest("{withOneMandatoryParamDefaultValue (intParam: ?param)  {}}");
    // test 1 (with an int bind parameter)
    Integer ret = request.execQuery("param", 1).getWithOneMandatoryParamDefaultValue();
    assertEquals(1, ret);
    // test 2 (with an Integer bind parameter)
    ret = request.execQuery("param", Integer.valueOf(2)).getWithOneMandatoryParamDefaultValue();
    assertEquals(2, ret);
    // test 3 (with a hardcoded int parameter)
    request = myQuery.getGraphQLRequest("{withOneMandatoryParamDefaultValue (intParam: 3)  {}}");
    ret = request.execQuery().getWithOneMandatoryParamDefaultValue();
    assertEquals(3, ret);
    // test 4 (with a hardcoded boolean and string parameter)
    request = myQuery.getGraphQLRequest("{directiveOnQuery(uppercase: true) @testDirective(value:\"a value\") {}}");
    List<String> strings = request.execQuery().getDirectiveOnQuery();
    assertNotNull(strings);
    assertTrue(strings.size() == 1);
    assertEquals("A VALUE", strings.get(0));
    // test 5 (with a hardcoded Float parameter, that has an int value)
    request = myQuery.getGraphQLRequest("{issue82Float(aFloat: 5) {}}");
    assertEquals(5, request.execQuery().getIssue82Float());
    // test 6 (with a hardcoded Float parameter, that has a float value)
    request = myQuery.getGraphQLRequest("{issue82Float(aFloat: 6.6) {}}");
    assertEquals(6.6, request.execQuery().getIssue82Float());
    // test 7 (with an ID parameter)
    request = myQuery.getGraphQLRequest("{issue82ID(aID: \"123e4567-e89b-12d3-a456-426655440000\") {}}");
    assertTrue(request.execQuery().getIssue82ID().equalsIgnoreCase("123e4567-e89b-12d3-a456-426655440000"), "Should be '123e4567-e89b-12d3-a456-426655440000' but is '" + request.execQuery().getIssue82ID() + "'");
    // test 8 (with an enumeration)
    request = myQuery.getGraphQLRequest("{withEnum(episode: JEDI) {name}}");
    assertEquals("JEDI", request.execQuery().getWithEnum().getName());
    // test 9 (with a custom scalar)
    request = myQuery.getGraphQLRequest("{issue53(date: \"2021-05-20\") {}}");
    Date verif = new Calendar.Builder().setDate(2021, 5 - 1, 20).build().getTime();
    assertEquals(verif, request.execQuery().getIssue53());
}
Also used : GraphQLRequest(org.allGraphQLCases.client.util.GraphQLRequest) Calendar(java.util.Calendar) Date(java.util.Date) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with GraphQLRequest

use of org.allGraphQLCases.client.util.GraphQLRequest in project graphql-maven-plugin-project by graphql-java-generator.

the class GraphQLTransportWSIT method testQueryWithoutGraphQLVariables.

@Test
void testQueryWithoutGraphQLVariables() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException {
    // Preparation
    List<FieldParameterInput> inputs = new ArrayList<>();
    inputs.add(FieldParameterInput.builder().withUppercase(true).build());
    inputs.add(FieldParameterInput.builder().withUppercase(false).build());
    // 
    GraphQLRequest graphQLRequest = myQuery.getAllFieldCasesGraphQLRequest("{issue65(inputs: &inputs)}");
    // Go, go, go
    AllFieldCases ret = myQuery.allFieldCases(graphQLRequest, null, "inputs", inputs);
    // Verification
    assertEquals(inputs.size(), ret.getIssue65().size());
    assertEquals(ret.getIssue65().get(0).getName().toUpperCase(), ret.getIssue65().get(0).getName(), "The first name should be in uppercase");
    assertNotEquals(ret.getIssue65().get(1).getName().toUpperCase(), ret.getIssue65().get(1).getName(), "The second name should NOT be in uppercase");
}
Also used : FieldParameterInput(org.allGraphQLCases.client.FieldParameterInput) GraphQLRequest(org.allGraphQLCases.client.util.GraphQLRequest) ArrayList(java.util.ArrayList) AllFieldCases(org.allGraphQLCases.client.AllFieldCases) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with GraphQLRequest

use of org.allGraphQLCases.client.util.GraphQLRequest in project graphql-maven-plugin-project by graphql-java-generator.

the class GraphQLVariablesIT method withDirectiveTwoParameters.

@Execution(ExecutionMode.CONCURRENT)
@Test
void withDirectiveTwoParameters() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException {
    // Preparation
    GraphQLRequest directiveOnQuery = mutationType.getGraphQLRequest(// 
    "query namedQuery($uppercase :\n" + // 
    "Boolean, \n\r" + " $Value :   String ! , $anotherValue:String) {directiveOnQuery (uppercase: $uppercase) @testDirective(value:$Value, anotherValue:$anotherValue)}");
    Map<String, Object> params = new HashMap<>();
    params.put("uppercase", true);
    params.put("anotherValue", "another value with an antislash: \\");
    params.put("Value", "a first \"value\"");
    // Go, go, go
    MyQueryType resp = directiveOnQuery.execQuery(params);
    // Verifications
    assertNotNull(resp);
    List<String> ret = resp.getDirectiveOnQuery();
    assertNotNull(ret);
    assertEquals(2, ret.size());
    // 
    assertEquals("A FIRST \"VALUE\"", ret.get(0));
    assertEquals("ANOTHER VALUE WITH AN ANTISLASH: \\", ret.get(1));
}
Also used : GraphQLRequest(org.allGraphQLCases.client.util.GraphQLRequest) HashMap(java.util.HashMap) MyQueryType(org.allGraphQLCases.client.MyQueryType) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with GraphQLRequest

use of org.allGraphQLCases.client.util.GraphQLRequest in project graphql-maven-plugin-project by graphql-java-generator.

the class GraphQLVariablesIT method test_GraphQLVariables_subscribeToADate.

@Execution(ExecutionMode.CONCURRENT)
@Test
public void test_GraphQLVariables_subscribeToADate() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException, InterruptedException {
    // Preparation
    SubscriptionCallbackToADate callback = new SubscriptionCallbackToADate("test_GraphQLVariables_subscribeToAList");
    Date date = new GregorianCalendar(2021, 4 - 1, 15).getTime();
    // Go, go, go
    GraphQLRequest subscription = subscriptionExecutor.getGraphQLRequest("subscription sub($aCustomScalarParam: Date!) {issue53(date: $aCustomScalarParam){}}");
    SubscriptionClient sub = subscription.execSubscription(callback, Date.class, "aCustomScalarParam", date);
    // Let's wait a max of 10 second, until we receive some notifications (my PC is really slow, especially when the
    // antivirus consumes 98% of my CPU!
    callback.latchForMessageReception.await(10, TimeUnit.SECONDS);
    // Let's disconnect from the subscription
    sub.unsubscribe();
    // Verification
    assertNull(callback.lastReceivedError, "expected no error, but received " + callback.lastReceivedError);
    assertNotNull(callback.lastReceivedMessage, "The subscription should have received a message");
}
Also used : GraphQLRequest(org.allGraphQLCases.client.util.GraphQLRequest) SubscriptionClient(com.graphql_java_generator.client.SubscriptionClient) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) SubscriptionCallbackToADate(org.allGraphQLCases.subscription.SubscriptionCallbackToADate) SubscriptionCallbackToADate(org.allGraphQLCases.subscription.SubscriptionCallbackToADate) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

GraphQLRequest (org.allGraphQLCases.client.util.GraphQLRequest)28 Test (org.junit.jupiter.api.Test)28 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)27 Execution (org.junit.jupiter.api.parallel.Execution)23 ArrayList (java.util.ArrayList)9 Human (org.allGraphQLCases.client.Human)8 List (java.util.List)6 AllFieldCases (org.allGraphQLCases.client.AllFieldCases)6 Date (java.util.Date)5 Character (org.allGraphQLCases.client.Character)5 Droid (org.allGraphQLCases.client.Droid)5 SubscriptionClient (com.graphql_java_generator.client.SubscriptionClient)3 Calendar (java.util.Calendar)3 AnotherMutationType (org.allGraphQLCases.client.AnotherMutationType)3 FieldParameterInput (org.allGraphQLCases.client.FieldParameterInput)3 MyQueryType (org.allGraphQLCases.client.MyQueryType)3 HashMap (java.util.HashMap)2 AllFieldCasesInput (org.allGraphQLCases.client.AllFieldCasesInput)2 AnyCharacter (org.allGraphQLCases.client.AnyCharacter)2 CharacterInput (org.allGraphQLCases.client.CharacterInput)2