Search in sources :

Example 1 with DataFetcherImpl

use of com.graphql_java_generator.plugin.language.impl.DataFetcherImpl in project graphql-maven-plugin-project by graphql-java-generator.

the class DocumentParser_allGraphQLCases_Server_Test method test_parseOneDocument_allGraphQLCases.

@Test
@Execution(ExecutionMode.CONCURRENT)
void test_parseOneDocument_allGraphQLCases() throws IOException {
    // Go, go, go
    int i = generateCodeDocumentParser.parseDocuments();
    // Verification
    assertEquals(44, i, "Nb java files are generated");
    assertEquals(8, generateCodeDocumentParser.getDirectives().size(), "Nb directives");
    assertEquals(27, generateCodeDocumentParser.getObjectTypes().size(), "Nb objects");
    assertEquals(5, generateCodeDocumentParser.getCustomScalars().size(), "Nb custom scalars");
    assertEquals(14, generateCodeDocumentParser.getInterfaceTypes().size(), "Nb interfaces");
    assertEquals(3, generateCodeDocumentParser.getEnumTypes().size(), "Nb enums");
    assertNotNull(generateCodeDocumentParser.getQueryType(), "One query");
    assertNotNull(generateCodeDocumentParser.getMutationType(), "One mutation");
    assertNotNull(generateCodeDocumentParser.getSubscriptionType(), "One subscription");
    assertEquals("query", generateCodeDocumentParser.getQueryType().getRequestType());
    assertEquals("mutation", generateCodeDocumentParser.getMutationType().getRequestType());
    assertEquals("subscription", generateCodeDocumentParser.getSubscriptionType().getRequestType());
    // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    DataFetcherImpl dataFetcher = findDataFetcher("DataFetchersDelegateAllFieldCases", "oneWithIdSubType", 1);
    assertTrue(dataFetcher.isCompletableFuture(), "oneWithIdSubType: the dataLoader one");
    // 
    dataFetcher = findDataFetcher("DataFetchersDelegateAllFieldCases", "listWithIdSubTypes", 1);
    assertFalse(dataFetcher.isCompletableFuture(), "listWithIdSubTypes (only standard dataFethcher here)");
    // 
    dataFetcher = findDataFetcher("DataFetchersDelegateAllFieldCases", "oneWithoutIdSubType", 1);
    assertFalse(dataFetcher.isCompletableFuture(), "oneWithoutIdSubType (only standard dataFethcher here)");
    // 
    dataFetcher = findDataFetcher("DataFetchersDelegateAllFieldCases", "listWithoutIdSubTypes", 1);
    assertFalse(dataFetcher.isCompletableFuture(), "listWithoutIdSubTypes (only standard dataFethcher here)");
    // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Checks if input types for the AllFieldCases object are correctly read
    // 
    ObjectType objectType = (ObjectType) generateCodeDocumentParser.getType("AllFieldCases");
    int j = 0;
    // checkField(type, j, name, list, mandatory, itemMandatory, typeName, classname)
    // checkInputParameter(type, j, numParam, name, list, mandatory, itemMandatory, typeName, classname,
    // defaultValue)
    // 
    // id: ID!
    checkField(objectType, j, "id", 0, true, null, "ID", "UUID");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // name: String!
    checkField(objectType, j, "name", 0, true, null, "String", "String");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // forname(uppercase: Boolean, textToAppendToTheForname: String): String
    checkField(objectType, j, "forname", 0, false, null, "String", "String");
    checkNbInputParameter(objectType, j, 2);
    checkInputParameter(objectType, j, 0, "uppercase", 0, false, null, "Boolean", "Boolean", null);
    checkInputParameter(objectType, j, 1, "textToAppendToTheForname", 0, false, null, "String", "String", null);
    j += 1;
    // age: Long!
    checkField(objectType, j, "age", 0, true, null, "Long", "Long");
    checkNbInputParameter(objectType, j, 1);
    checkInputParameter(objectType, j, 0, "unit", 0, false, null, "Unit", "Unit", new graphql.language.EnumValue("YEAR"));
    j += 1;
    // aFloat: Float
    checkField(objectType, j, "aFloat", 0, false, null, "Float", "Double");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // date: Date
    checkField(objectType, j, "date", 0, false, null, "Date", "Date");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // dateTime: DateTime
    checkField(objectType, j, "dateTime", 0, false, null, "DateTime", "OffsetDateTime");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // dates: [Date]!
    checkField(objectType, j, "dates", 1, true, false, "Date", "Date");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // nbComments: Int
    checkField(objectType, j, "nbComments", 0, false, null, "Int", "Integer");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // comments: [String]
    checkField(objectType, j, "comments", 1, false, false, "String", "String");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // booleans: [Boolean!]
    checkField(objectType, j, "booleans", 1, false, true, "Boolean", "Boolean");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // aliases: [String]!
    checkField(objectType, j, "aliases", 1, true, false, "String", "String");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // planets: [String!]!
    checkField(objectType, j, "planets", 1, true, true, "String", "String");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // friends: [Human!]
    checkField(objectType, j, "friends", 1, false, true, "Human", "Human");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // matrix: [[Float]]!
    checkField(objectType, j, "matrix", 2, true, false, "Float", "Double");
    checkNbInputParameter(objectType, j, 0);
    j += 1;
    // oneWithIdSubType: AllFieldCasesWithIdSubtype
    checkField(objectType, j, "oneWithIdSubType", 0, false, null, "AllFieldCasesWithIdSubtype", "AllFieldCasesWithIdSubtype");
    checkNbInputParameter(objectType, j, 1);
    checkInputParameter(objectType, j, 0, "uppercase", 0, false, null, "Boolean", "Boolean", null);
    j += 1;
    // listWithIdSubTypes(nbItems: Long!, date: Date, dates: [Date]!, uppercaseName: Boolean,
    // textToAppendToTheForname: String): [AllFieldCasesWithIdSubtype]
    checkField(objectType, j, "listWithIdSubTypes", 1, false, false, "AllFieldCasesWithIdSubtype", "AllFieldCasesWithIdSubtype");
    checkNbInputParameter(objectType, j, 5);
    checkInputParameter(objectType, j, 0, "nbItems", 0, true, null, "Long", "Long", null);
    checkInputParameter(objectType, j, 1, "date", 0, false, null, "Date", "Date", null);
    checkInputParameter(objectType, j, 2, "dates", 1, true, false, "Date", "Date", null);
    checkInputParameter(objectType, j, 3, "uppercaseName", 0, false, null, "Boolean", "Boolean", null);
    checkInputParameter(objectType, j, 4, "textToAppendToTheForname", 0, false, null, "String", "String", null);
    j += 1;
    // oneWithoutIdSubType(input: FieldParameterInput): AllFieldCasesWithoutIdSubtype
    checkField(objectType, j, "oneWithoutIdSubType", 0, false, false, "AllFieldCasesWithoutIdSubtype", "AllFieldCasesWithoutIdSubtype");
    checkNbInputParameter(objectType, j, 1);
    checkInputParameter(objectType, j, 0, "input", 0, false, null, "FieldParameterInput", "FieldParameterInput", null);
    j += 1;
    // listWithoutIdSubTypes(nbItems: Int!, input: FieldParameterInput, textToAppendToTheForname: String):
    // [AllFieldCasesWithoutIdSubtype]
    checkField(objectType, j, "listWithoutIdSubTypes", 1, false, false, "AllFieldCasesWithoutIdSubtype", "AllFieldCasesWithoutIdSubtype");
    checkNbInputParameter(objectType, j, 3);
    checkInputParameter(objectType, j, 0, "nbItems", 0, true, null, "Long", "Long", null);
    checkInputParameter(objectType, j, 1, "input", 0, false, null, "FieldParameterInput", "FieldParameterInput", null);
    checkInputParameter(objectType, j, 2, "textToAppendToTheForname", 0, false, null, "String", "String", null);
    j += 1;
    // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Checks of type implementing multiples interfaces
    objectType = (ObjectType) generateCodeDocumentParser.getType("Human");
    // 
    assertEquals(4, objectType.getImplementz().size());
    assertTrue(objectType.getImplementz().contains("Character"));
    assertTrue(objectType.getImplementz().contains("Commented"));
    assertTrue(objectType.getImplementz().contains("WithID"));
    // This is an union
    assertTrue(objectType.getImplementz().contains("AnyCharacter"));
    // 
    InterfaceType interfaceType = (InterfaceType) generateCodeDocumentParser.getType("WithID");
    assertEquals(4, interfaceType.getImplementingTypes().size());
    j = 0;
    assertEquals("AllFieldCases", interfaceType.getImplementingTypes().get(j++).getName());
    assertEquals("AllFieldCasesInterfaceType", interfaceType.getImplementingTypes().get(j++).getName());
    assertEquals("Human", interfaceType.getImplementingTypes().get(j++).getName());
    assertEquals("Droid", interfaceType.getImplementingTypes().get(j++).getName());
    // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Checks of directive parsing
    i = 0;
    assertEquals("skip", generateCodeDocumentParser.getDirectives().get(i++).getName());
    assertEquals("include", generateCodeDocumentParser.getDirectives().get(i++).getName());
    assertEquals("defer", generateCodeDocumentParser.getDirectives().get(i++).getName());
    assertEquals("deprecated", generateCodeDocumentParser.getDirectives().get(i++).getName());
    assertEquals("IDScalarDirective", generateCodeDocumentParser.getDirectives().get(i++).getName());
    assertEquals("RelayConnection", generateCodeDocumentParser.getDirectives().get(i++).getName());
    assertEquals("testDirective", generateCodeDocumentParser.getDirectives().get(i++).getName());
    assertEquals("anotherTestDirective", generateCodeDocumentParser.getDirectives().get(i++).getName());
    // On Scalar
    assertEquals(0, generateCodeDocumentParser.getType("Date").getAppliedDirectives().size(), "No directive in the schema, as it is adapted for graphql-java v15.0, see below in the junit test code");
    // The next test is deactivated, because of a bug in graphql-java v15.0. It should be restored, once the issue
    // 2055 is solved
    // checkDirectivesOnType(generateCodeDocumentParser.getType("Date"), true, "on Scalar", null, null, null, null,
    // null,
    // null, null, true);
    checkDirectivesOnType(generateCodeDocumentParser.getType("Long"), false, null, null, null, null, null, null, null, null, false);
    // On schema
    // Currently not managed (schema is not stored, and no java classes is generated afteward for the schema)
    // On enum
    assertEquals(0, generateCodeDocumentParser.getType("Episode").getAppliedDirectives().size(), "No directive in the schema, as it is adapted for graphql-java v15.0, see below in the junit test code");
    // The next test is deactivated, because of a bug in graphql-java v15.0. It should be restored, once the issue
    // 2055 is solved
    // checkDirectivesOnType(generateCodeDocumentParser.getType("Episode"), true, "on Enum", "69", 666, (float)
    // 666.666,
    // true, "00000000-0000-0000-0000-000000000002", null, "2001-02-28", false);
    checkDirectivesOnType(generateCodeDocumentParser.getType("Unit"), false, null, null, null, null, null, null, null, null, false);
    // On enum item
    // The 3 below tests should be removed, and 3 next be uncommented, once the graphqm-java's issue 2055 is solved
    checkDirectivesOnEnumValue(generateCodeDocumentParser.getType("Episode"), "DOES_NOT_EXIST", false, "on Enum", "-1", false);
    checkDirectivesOnEnumValue(generateCodeDocumentParser.getType("Episode"), "JEDI", false, null, null, false);
    checkDirectivesOnEnumValue(generateCodeDocumentParser.getType("Episode"), "EMPIRE", false, null, null, false);
    // The next 3 tests are deactivated, because of a bug in graphql-java v15.0. It should be restored, once the
    // issue 2055 is solved
    // checkDirectivesOnEnumValue(generateCodeDocumentParser.getType("Episode"), "DOES_NOT_EXIST", true, "on Enum",
    // "-1",
    // true);
    // checkDirectivesOnEnumValue(generateCodeDocumentParser.getType("Episode"), "JEDI", false, null, null, false);
    // checkDirectivesOnEnumValue(generateCodeDocumentParser.getType("Episode"), "EMPIRE", false, null, null, true);
    // On interface
    checkDirectivesOnType(generateCodeDocumentParser.getType("WithID"), true, "on Interface", "666", null, null, null, null, null, null, false);
    checkDirectivesOnType(generateCodeDocumentParser.getType("Character"), true, "on Character interface", null, null, null, null, null, null, null, true);
    // On interface field
    checkDirectivesOnField(generateCodeDocumentParser.getType("Character"), "name", true, "on interface field", null, true, 0);
    checkDirectivesOnField(generateCodeDocumentParser.getType("Character"), "appearsIn", false, null, null, true, 0);
    // On union
    // checkDirectivesOnType(documentParser.getType("AnyCharacter"), true, "on Union", null, false);
    // On input type
    checkDirectivesOnType(generateCodeDocumentParser.getType("AllFieldCasesInput"), true, "on Input Type", null, null, null, null, null, null, null, false);
    // On input type field
    checkDirectivesOnField(generateCodeDocumentParser.getType("AllFieldCasesInput"), "id", true, "on Input Field", null, false, 0);
    checkDirectivesOnField(generateCodeDocumentParser.getType("AllFieldCasesInput"), "name", false, null, null, false, 0);
    // On type
    checkDirectivesOnType(generateCodeDocumentParser.getType("AllFieldCases"), true, "on Object", null, null, null, null, null, null, null, true);
    // On type field
    checkDirectivesOnField(generateCodeDocumentParser.getType("AllFieldCases"), "id", true, "on Field", null, false, 0);
    checkDirectivesOnField(generateCodeDocumentParser.getType("AllFieldCases"), "name", false, null, null, false, 0);
    // On input parameter
    checkDirectivesOnInputParameter(generateCodeDocumentParser.getType("AllFieldCases"), "forname", "uppercase", true, "on Argument", null, false);
    checkDirectivesOnInputParameter(generateCodeDocumentParser.getType("AllFieldCases"), "forname", "textToAppendToTheForname", false, null, null, false);
}
Also used : ObjectType(com.graphql_java_generator.plugin.language.impl.ObjectType) InterfaceType(com.graphql_java_generator.plugin.language.impl.InterfaceType) DataFetcherImpl(com.graphql_java_generator.plugin.language.impl.DataFetcherImpl) Execution(org.junit.jupiter.api.parallel.Execution) Test(org.junit.jupiter.api.Test)

Aggregations

DataFetcherImpl (com.graphql_java_generator.plugin.language.impl.DataFetcherImpl)1 InterfaceType (com.graphql_java_generator.plugin.language.impl.InterfaceType)1 ObjectType (com.graphql_java_generator.plugin.language.impl.ObjectType)1 Test (org.junit.jupiter.api.Test)1 Execution (org.junit.jupiter.api.parallel.Execution)1