Skip to content

GG-380 Add test for multitable types missing table.#346

Open
Erkelinux wants to merge 2 commits intomainfrom
GG-380-add-tests
Open

GG-380 Add test for multitable types missing table.#346
Erkelinux wants to merge 2 commits intomainfrom
GG-380-add-tests

Conversation

@Erkelinux
Copy link
Collaborator

Also made the check throw all errors for one union/interface at once, rather than one by one.

@andreahn
Copy link
Collaborator

Prøvde å få feilen i graphitron-example ved å fjerne tabell fra StaffWithEmail, men da får jeg heller en valideringsfeil på referanse (og kun det):

Error on field "addressAsSubquery" in type "StaffWithEmail": No foreign key found between tables "RENTAL" and "ADDRESS". Please specify path with the @reference directive.

Dette er antageligvis på grunn av at Payment har et felt som peker mot StaffWithEmail, og derfor blir forrige tabell RENTAL. Det blir med andre ord en følgefeil av at StaffWithEmail mangler tabell, men vi får aldri den egentlige feilen (at typen mangler tabell) siden den blir kastet i kodegenereringen.

Jeg syns vi burde flyttet dette til ProcessedDefinitionsValidator sånn at vi får feilmeldingen uavhengig av om noe annet feiler i valideringssteget

@Erkelinux
Copy link
Collaborator Author

Prøvde å få feilen i graphitron-example ved å fjerne tabell fra StaffWithEmail, men da får jeg heller en valideringsfeil på referanse (og kun det):

Error on field "addressAsSubquery" in type "StaffWithEmail": No foreign key found between tables "RENTAL" and "ADDRESS". Please specify path with the @reference directive.

Dette er antageligvis på grunn av at Payment har et felt som peker mot StaffWithEmail, og derfor blir forrige tabell RENTAL. Det blir med andre ord en følgefeil av at StaffWithEmail mangler tabell, men vi får aldri den egentlige feilen (at typen mangler tabell) siden den blir kastet i kodegenereringen.

Jeg syns vi burde flyttet dette til ProcessedDefinitionsValidator sånn at vi får feilmeldingen uavhengig av om noe annet feiler i valideringssteget

Prøvde å rydde opp i dette nå, og tilpasset slik at dette bare blir sjekket det ene stedet siden jeg fant at dette ble allerede validert andre steder (men det ser ikke ut til å plukke opp alt?)

* @return Get the implementations for an interface given its name
*/
public Set<ObjectDefinition> getImplementationsForInterface(String interfaceName) {
public List<ObjectDefinition> getImplementationsForInterface(String interfaceName) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hvorfor har du endra fra Set til List?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set var ikke brukt til noe konkret og rekkefølge var påkrevd flere steder uannsett. Her trengte jeg vel rekkefølge på noe og innså at Set ble uannsett konvertert til ordnede strukturer og tenkte at det er like greit at den er liste fra start

Comment on lines 391 to 399
@@ -399,19 +398,11 @@ public Set<ObjectDefinition> getTypesFromInterfaceOrUnion(String name) {
return null;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public Optional<List<ObjectDefinition>> getTypesFromInterfaceOrUnion(String name) {
if (isUnion(name)) {
return Optional.of(getUnionSubTypes(isConnectionObject(name) ? getConnectionObject(name).getNodeType() : name));
}
if (isInterface(name)) {
return Optional.of(getImplementationsForInterface(isConnectionObject(name) ? getConnectionObject(name).getNodeType() : name));
}
return Optional.empty();
}

hvis du først skal begynne å fikse her 🤷🏻

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tok det med, men opplever at det bare ble litt ekstra støy andre steder

Comment on lines +3 to +16
public enum ErrorMessages {
MISSING_FIELD("Input type %s referencing table %s does not map all fields required by the database. Missing required fields: %s"),
MISSING_NON_NULLABLE("Input type %s referencing table %s does not map all fields required by the database as non-nullable. Nullable required fields: %s"),
MISSING_TABLE_ON_MULTITABLE("Type(s) '%s' are used in a query '%s.%s' returning multitable interface or union '%s', but do not have tables set. This is not supported.");

private final String msg;

ErrorMessages(String msg) {
this.msg = msg;
}

public String getMsg() {
return msg;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeg er litt usikker på om jeg er så fan av dette. Det gjør det mye vanskeligere å lese testene vi har på validering

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gjør om testene tilbake

.filter(it -> !it.getTypeName().equals(NODE_TYPE.getName()))
.forEach((field) -> {
var multitableName = field.getTypeName();
if (multitableName.equalsIgnoreCase(NODE_TYPE.getName()) || multitableName.equalsIgnoreCase(ERROR_TYPE.getName())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (multitableName.equalsIgnoreCase(NODE_TYPE.getName()) || multitableName.equalsIgnoreCase(ERROR_TYPE.getName())) {
if (multitableName.equalsIgnoreCase(ERROR_TYPE.getName())) {

Node blir vel filtrert ut over

Comment on lines +960 to 962
if (implementation.getTable() != null && !tableHasPrimaryKey(implementation.getTable().getName())) {
addErrorMessage("Interface '%s' is returned in field '%s', but implementing type '%s' " +
"has table '%s' which does not have a primary key. This is not supported.", name, field.getName(), implementation.getName(), implementation.getTable().getName());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hvorfor endra du på det her? Det er to forskjellige feil

.map(AbstractObjectDefinition::getName)
.collect(Collectors.joining("', '"));
if (!typesMissingTable.isEmpty()) {
addErrorMessage(MISSING_TABLE_ON_MULTITABLE.getMsg(), typesMissingTable, field.getContainerTypeName(), field.getName(), field.getTypeName());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
addErrorMessage(MISSING_TABLE_ON_MULTITABLE.getMsg(), typesMissingTable, field.getContainerTypeName(), field.getName(), field.getTypeName());
addErrorMessage(MISSING_TABLE_ON_MULTITABLE.getMsg(), typesMissingTable, field.formatPath(), field.getTypeName());

public enum ErrorMessages {
MISSING_FIELD("Input type %s referencing table %s does not map all fields required by the database. Missing required fields: %s"),
MISSING_NON_NULLABLE("Input type %s referencing table %s does not map all fields required by the database as non-nullable. Nullable required fields: %s"),
MISSING_TABLE_ON_MULTITABLE("Type(s) '%s' are used in a query '%s.%s' returning multitable interface or union '%s', but do not have tables set. This is not supported.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MISSING_TABLE_ON_MULTITABLE("Type(s) '%s' are used in a query '%s.%s' returning multitable interface or union '%s', but do not have tables set. This is not supported.");
MISSING_TABLE_ON_MULTITABLE("Type(s) '%s' are used in a query '%s' returning multitable interface or union '%s', but do not have tables set. This is not supported.");

void implementationWithoutTable() {
assertErrorsContain(
() -> getProcessedSchema("implementationWithoutTable"),
String.format(MISSING_TABLE_ON_MULTITABLE.getMsg(), "Customer", "Query", "someInterface", "SomeInterface")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeg tror jeg syns dette blir litt vel uleselig 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants