Search in sources :

Example 1 with Human

use of org.allGraphQLCases.client.Human 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 Human

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

the class GraphQLVariablesIT method mutation.

@Execution(ExecutionMode.CONCURRENT)
@Test
void mutation() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException {
    // Preparation
    GraphQLRequest mutationWithDirectiveRequest = mutationType.getGraphQLRequest(// 
    "" + // 
    "mutation creation($name  : String!, $friends : [ CharacterInput\r\n] , $appearsIn: [Episode]!,$uppercaseName:Boolean)\r\n" + // 
    "{createHuman (human: {name:$name, friends:$friends, appearsIn:$appearsIn}) " + // 
    "{id name(uppercase: $uppercaseName) appearsIn friends {id friends appearsIn name}}}");
    CharacterInput friendsParam = CharacterInput.builder().withName("a friend's name").withAppearsIn(Arrays.asList(Episode.NEWHOPE)).withType("Human").build();
    // Go, go, go
    AnotherMutationType resp = // 
    mutationWithDirectiveRequest.execMutation(// 
    "name", // 
    "a new name", // 
    "appearsIn", // 
    Arrays.asList(Episode.JEDI, Episode.EMPIRE, Episode.NEWHOPE), // 
    "uppercaseName", // 
    true, "friends", friendsParam);
    // Verifications
    assertNotNull(resp);
    Human human = resp.getCreateHuman();
    assertNotNull(human);
    assertEquals("A NEW NAME", human.getName());
    assertEquals(3, human.getAppearsIn().size());
    assertEquals(Episode.JEDI, human.getAppearsIn().get(0));
    assertEquals(Episode.EMPIRE, human.getAppearsIn().get(1));
    assertEquals(Episode.NEWHOPE, human.getAppearsIn().get(2));
}
Also used : Human(org.allGraphQLCases.client.Human) GraphQLRequest(org.allGraphQLCases.client.util.GraphQLRequest) CharacterInput(org.allGraphQLCases.client.CharacterInput) AnotherMutationType(org.allGraphQLCases.client.AnotherMutationType) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Human

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

the class AliasesIT method test_subscription.

@Execution(ExecutionMode.CONCURRENT)
@Test
public void test_subscription() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException, InterruptedException {
    // Preparation
    HumanSubscriptionCallback callback = new HumanSubscriptionCallback();
    // Go, go, go
    SubscriptionClient sub = subscriptionExecutor.subscribeNewHumanForEpisode(// 
    "{aliasId:id id aliasName:name name aliasHomePlanet:homePlanet homePlanet}", callback, Episode.JEDI);
    // Let's wait a max of 10 second, until we receive some notifications
    waitForEvent(100, () -> {
        return callback.lastReceivedMessage != null || callback.lastError != null;
    }, "Waiting for the subscription to receive the notification");
    // Let's disconnect from the subscription
    sub.unsubscribe();
    // Verification
    if (callback.lastError != null) {
        fail("The subsccription raised this error: " + callback.lastError);
    }
    assertNotNull(callback.lastReceivedMessage);
    assertTrue(callback.lastReceivedMessage instanceof Human);
    Human verif = callback.lastReceivedMessage;
    assertEquals(verif.getId(), verif.getAliasValue("aliasId"));
    assertEquals(verif.getName(), verif.getAliasValue("aliasName"));
    assertEquals(verif.getHomePlanet(), verif.getAliasValue("aliasHomePlanet"));
}
Also used : Human(org.allGraphQLCases.client.Human) SubscriptionClient(com.graphql_java_generator.client.SubscriptionClient) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Human

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

the class FragmentIT method test_InlineAndGlobalFragments_withOneOptionalParam_Human.

@Execution(ExecutionMode.CONCURRENT)
@Test
void test_InlineAndGlobalFragments_withOneOptionalParam_Human() throws GraphQLRequestPreparationException, GraphQLRequestExecutionException {
    // Preparation
    GraphQLRequest graphQLRequest = myQuery.getGraphQLRequest(// 
    "" + // 
    "query{" + // 
    "  withOneOptionalParam(character: &input){" + // 
    "    appearsIn " + // 
    "    ...id " + // 
    "    ... on Character { ...id } " + // 
    "    ... on Droid {  primaryFunction ... on Character {name(uppercase: ?notDefinedBindVariable) friends {name}}  } " + // 
    "    ... on Human {  homePlanet ... on Human { ... on Character  { name(uppercase: ?notDefinedBindVariable)}} } " + // 
    "  } " + // 
    "} " + // 
    "fragment id on Character {id} ");
    input.setType("Human");
    // Go, go, go
    Character withOneOptionalParam = graphQLRequest.execQuery(params).getWithOneOptionalParam();
    // Verification
    assertNotNull(withOneOptionalParam);
    assertTrue(withOneOptionalParam instanceof Human, "we've ask for thas in input's type");
    assertEquals("Human", withOneOptionalParam.get__typename());
    assertTrue(withOneOptionalParam instanceof Human);
    assertNotNull(withOneOptionalParam.getAppearsIn());
    assertNotNull(withOneOptionalParam.getId());
    assertNull(withOneOptionalParam.getFriends(), "friends have been requested onyl for droids");
    assertNotNull(withOneOptionalParam.getName(), "name has been requested in inline fragment for human");
    assertNotNull(((Human) withOneOptionalParam).getHomePlanet(), "homePlanet is requested for humans");
}
Also used : Human(org.allGraphQLCases.client.Human) GraphQLRequest(org.allGraphQLCases.client.util.GraphQLRequest) Character(org.allGraphQLCases.client.Character) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Human

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

the class FullQueriesDeprecatedIT method mutation.

@Execution(ExecutionMode.CONCURRENT)
@Test
void mutation() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException {
    // Preparation
    HumanInput input = new HumanInput();
    input.setName("a new name");
    List<Episode> episodes = new ArrayList<>();
    episodes.add(Episode.JEDI);
    episodes.add(Episode.EMPIRE);
    episodes.add(Episode.NEWHOPE);
    input.setAppearsIn(episodes);
    // //////////////////////////////////////////////////////////////////////////////////////////////
    // WITHOUT DIRECTIVE
    // Go, go, go
    AnotherMutationTypeResponse resp = mutationType.exec(mutationWithoutDirectiveResponse, "humanInput", input);
    // Verifications
    assertNotNull(resp);
    Human ret = resp.getCreateHuman();
    assertNotNull(ret);
    assertEquals("a new name", ret.getName());
    // //////////////////////////////////////////////////////////////////////////////////////////////
    // WITH DIRECTIVE
    // Go, go, go
    resp = // 
    mutationType.exec(// 
    mutationWithDirectiveResponse, // 
    "humanInput", // 
    input, // 
    "value", // 
    "the mutation value", "anotherValue", "the other mutation value");
    // Verifications
    assertNotNull(resp);
    ret = resp.getCreateHuman();
    assertNotNull(ret);
    assertEquals("the other mutation value", ret.getName());
}
Also used : Human(org.allGraphQLCases.client.Human) Episode(org.allGraphQLCases.client.Episode) HumanInput(org.allGraphQLCases.client.HumanInput) ArrayList(java.util.ArrayList) AnotherMutationTypeResponse(org.allGraphQLCases.client.util.AnotherMutationTypeResponse) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Human (org.allGraphQLCases.client.Human)14 Test (org.junit.jupiter.api.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 Execution (org.junit.jupiter.api.parallel.Execution)11 GraphQLRequest (org.allGraphQLCases.client.util.GraphQLRequest)8 Character (org.allGraphQLCases.client.Character)5 CharacterInput (org.allGraphQLCases.client.CharacterInput)5 HumanInput (org.allGraphQLCases.client.HumanInput)5 Droid (org.allGraphQLCases.client.Droid)4 ArrayList (java.util.ArrayList)3 AnotherMutationType (org.allGraphQLCases.client.AnotherMutationType)3 Episode (org.allGraphQLCases.client.Episode)3 AnyCharacter (org.allGraphQLCases.client.AnyCharacter)2 SubscriptionClient (com.graphql_java_generator.client.SubscriptionClient)1 GraphQLRepositoryInvocationHandler (com.graphql_java_generator.client.graphqlrepository.GraphQLRepositoryInvocationHandler)1 AnotherMutationTypeExecutorAllGraphQLCases (org.allGraphQLCases.client.util.AnotherMutationTypeExecutorAllGraphQLCases)1 AnotherMutationTypeResponse (org.allGraphQLCases.client.util.AnotherMutationTypeResponse)1 MyQueryTypeExecutorAllGraphQLCases (org.allGraphQLCases.client.util.MyQueryTypeExecutorAllGraphQLCases)1 TheSubscriptionTypeExecutorAllGraphQLCases (org.allGraphQLCases.client.util.TheSubscriptionTypeExecutorAllGraphQLCases)1