use of com.graphql_java_generator.plugin.language.impl.AppliedDirectiveImpl in project graphql-maven-plugin-project by graphql-java-generator.
the class AddRelayConnectionsTest method testAddRelayConnections_relayConnectionOnInputTypeField.
/**
* The <I>@RelayConnection</I> directive may not be set on a field of an input type. It's possible, as the
* <I>@RelayConnection</I> directive is defined in the input schema, so it can be badly defined
*
* @throws IOException
*/
@Test
@Execution(ExecutionMode.CONCURRENT)
void testAddRelayConnections_relayConnectionOnInputTypeField() throws IOException {
// Preparation
loadSpringContext(AllGraphQLCases_Client_SpringConfiguration.class, "testAddRelayConnections_relayConnectionOnInputTypeField", false);
// Let's parse (load) the GraphQL schemas, but not call the addRelayConnections() method, so that we can break
// the Connection interface compliance for the relay connection specification
((GenerateGraphQLSchemaConfigurationTestHelper) configuration).addRelayConnections = false;
documentParser.parseDocuments();
//
DirectiveImpl dir = new DirectiveImpl();
dir.setName("RelayConnection");
dir.getDirectiveLocations().add(DirectiveLocation.FIELD_DEFINITION);
//
AppliedDirectiveImpl d = new AppliedDirectiveImpl();
d.setDirective(dir);
//
getField("AllFieldCasesInput", "aliases").getAppliedDirectives().add(d);
// Go, go, go
RuntimeException e = assertThrows(RuntimeException.class, () -> addRelayConnections.addRelayConnections());
// Verification
assertTrue(e.getMessage().contains("input type may not have fields to which the @RelayConnection directive is applied"));
}
use of com.graphql_java_generator.plugin.language.impl.AppliedDirectiveImpl in project graphql-maven-plugin-project by graphql-java-generator.
the class AddRelayConnectionsTest method test_addEdgeConnectionAndApplyNodeInterface_step1RelayConnectionOnInputField.
@Test
@Execution(ExecutionMode.CONCURRENT)
void test_addEdgeConnectionAndApplyNodeInterface_step1RelayConnectionOnInputField() throws IOException {
// If a type's field is annotated by @RelayConnection, but this field is not a list, then an error should be
// thrown.
// Let's change the list attribute to false to one of this field
loadSpringContext(AllGraphQLCases_Client_SpringConfiguration.class, "test_addEdgeConnectionAndApplyNodeInterface_step2missingDirectiveOnInterfaceField", false);
// Let's parse (load) the GraphQL schemas, but not call the addRelayConnections() method, so that we can break
// the Node interface compliance for the relay connection specification
((GenerateGraphQLSchemaConfigurationTestHelper) configuration).addRelayConnections = false;
documentParser.parseDocuments();
//
FieldImpl f = (FieldImpl) getField("AllFieldCasesInput", "booleans");
//
DirectiveImpl dir = new DirectiveImpl();
dir.setName("RelayConnection");
dir.getDirectiveLocations().add(DirectiveLocation.FIELD_DEFINITION);
//
AppliedDirectiveImpl d = new AppliedDirectiveImpl();
d.setDirective(dir);
f.getAppliedDirectives().add(d);
// Go, go, go
RuntimeException e = assertThrows(RuntimeException.class, () -> addRelayConnections.addEdgeConnectionAndApplyNodeInterface());
// Verification
assertTrue(e.getMessage().contains("AllFieldCasesInput.booleans"));
assertTrue(e.getMessage().contains("input type may not have fields to which the @RelayConnection directive is applied"));
}
use of com.graphql_java_generator.plugin.language.impl.AppliedDirectiveImpl in project graphql-maven-plugin-project by graphql-java-generator.
the class DocumentParser method readAppliedDirectives.
/**
* Reads a GraphQL directive that has been applied to an item of the GraphQL schema. The relevant directive
* definition should already have been read before (see {@link #readDirectiveDefinition(DirectiveDefinition)}).
*
* @param directives
* @return
*/
List<AppliedDirective> readAppliedDirectives(List<graphql.language.Directive> directives) {
List<AppliedDirective> ret = new ArrayList<>();
if (directives != null) {
for (graphql.language.Directive nodeDirective : directives) {
AppliedDirectiveImpl d = new AppliedDirectiveImpl();
d.setDirective(getDirectiveDefinition(nodeDirective.getName()));
// Let's read its arguments
if (nodeDirective.getArguments() != null) {
for (Argument a : nodeDirective.getArguments()) {
// We store the graphql.language.Value as we receive it. We may not have parsed the relevant
// Object to check its field, and obviously, we can"t instanciate any object or enum yet, as we
// dont't even generated any code.
d.getArgumentValues().put(a.getName(), a.getValue());
}
}
ret.add(d);
}
// for
}
return ret;
}
use of com.graphql_java_generator.plugin.language.impl.AppliedDirectiveImpl in project graphql-maven-plugin-project by graphql-java-generator.
the class AddRelayConnectionsTest method test_addEdgeConnectionAndApplyNodeInterface_step2missingDirectiveOnInterfaceField.
@Test
@Execution(ExecutionMode.CONCURRENT)
void test_addEdgeConnectionAndApplyNodeInterface_step2missingDirectiveOnInterfaceField() throws IOException {
// If a type's field is annotated by @RelayConnection, but this field is "inherited" from an interface, in which
// is not inherited by this directive, then an error should be thrown.
// Let's add the @RelayConnection directive to the AllFieldCasesInterfaceType.id field, and check that two
// errors are found (as id is in the AllFieldCasesInterface and the WithID interfaces)
loadSpringContext(AllGraphQLCases_Client_SpringConfiguration.class, "test_addEdgeConnectionAndApplyNodeInterface_step2missingDirectiveOnInterfaceField", false);
// Let's parse (load) the GraphQL schemas, but not call the addRelayConnections() method, so that we can break
// the Node interface compliance for the relay connection specification
((GenerateGraphQLSchemaConfigurationTestHelper) configuration).addRelayConnections = false;
documentParser.parseDocuments();
DirectiveImpl dir = new DirectiveImpl();
dir.setName("RelayConnection");
dir.getDirectiveLocations().add(DirectiveLocation.FIELD_DEFINITION);
//
FieldImpl f = (FieldImpl) getField("AllFieldCasesInterfaceType", "id");
// We need to pass the "is a list" test
FieldTypeAST list = FieldTypeAST.builder().listDepth(1).listItemFieldTypeAST(f.getFieldTypeAST()).build();
f.setFieldTypeAST(list);
//
AppliedDirectiveImpl d = new AppliedDirectiveImpl();
d.setDirective(dir);
f.setAppliedDirectives(new ArrayList<>());
f.getAppliedDirectives().add(d);
Logger mockLogger = mock(Logger.class);
AddRelayConnections.logger = mockLogger;
ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
// Go, go, go
RuntimeException e = assertThrows(RuntimeException.class, () -> addRelayConnections.addEdgeConnectionAndApplyNodeInterface());
// Verification
assertTrue(e.getMessage().contains("2 error(s) was(were) found"), "Expected '2 error(s) was(were) found' in " + e.getMessage());
// First error
verify(mockLogger, times(2)).error(argument.capture());
String errorMessage = argument.getAllValues().get(0);
assertTrue(errorMessage.contains(" AllFieldCasesInterfaceType "));
assertTrue(errorMessage.contains(" id "));
assertTrue(errorMessage.contains("interface AllFieldCasesInterface, in which this field doesn't have the directive @RelayConnection applied"));
// Second error
errorMessage = argument.getAllValues().get(1);
assertTrue(errorMessage.contains(" AllFieldCasesInterfaceType "));
assertTrue(errorMessage.contains(" id "));
assertTrue(errorMessage.contains("interface WithID, in which this field doesn't have the directive @RelayConnection applied"));
}
Aggregations