I got a kind of individual problem with a general question to which i didn't found anything online.
My problems are key-value enums in my backend to which the graphql runtime cannot match the input scalars. Int and String are coming from my client and should be matched to corresponding enums on the server. But thats not possible because the client sends me the value of the key-value enum and with this the runtime cannot map the string/int values to the enums. For example:
type Query {
fetchTemplates(limit: Int, offset: Int, filter: Filter!): Wrapper
}
input Filter {
"state -> enum 'TypeState' with nummeric internal values"
state: Int
"opening -> enum 'Opening' with string internal values"
opening: String
}
and backend enums and class
public class Filter {
private TypeState state;
private Opening opening;
// getter and setter
}
public enum TypeState {
DRAFT(1),
APPROVED(2),
ARCHIVED(3);
private final int typeState;
@JsonCreator
TypeState(@JsonProperty("typeState") int typeState) {
this.typeState = typeState;
}
}
public enum Opening {
MANUAL_CLOSING("manual_closing"),
MECHANIC_CLOSING("mechanic_closing"),
AUOTMATIC_CLOSING("automatic_close");
private final String opening;
@JsonCreator
Opening(@JsonProperty("opening") String opening) {
this.opening = opening;
}
}
So I tried to use the directives, normaly the perfect use-case for this.
input typeFilter {
"state -> enum 'TypeState' with nummeric internal values"
state: Int @enumMapping(enum: TYPESTATE)
"opening -> enum 'Opening' with string internal values"
opening: String @uppercase
}
directive @uppercase on INPUT_FIELD_DEFINITION
directive @enumMapping(enum: Enum) on INPUT_FIELD_DEFINITION
enum Enum {
TYPESTATE
}
I encountered the problem that the normal type directives are explained everywhere but nowhere the input directives, because with the same approach as with the type directives the transformation did not work.
Did someone here something similar and could help me or if you guys got any other workaround for this problem, that would be perfect! -> Sadly it is not possible to use enum types in the schema due to legacy code stuff...
Server-Version
- graphql-dgs-spring-boot-starter : 7.3.6
- graphql-java : 21