Is it possible to define a custom GraphQL endpoint/mutation with an argument that contains File or FileRef or javax.servlet.http.Part and mapped to Upload scalar?
Example:
@Data
public class SomeDto {
private File file;
}
@GraphQLApi @Service(“GraphQLService”)
public class GraphQLService { @GraphQLMutation
public void mutateDto(@GraphQLInputField SomeDto dto) {
/// Some logic…
}
}
at this point the file is already saved on the server.
Response contains FileRef string representation of saved file.
Then file ref could be send on server as part of dto via custom mutation. In custom mutation method on back end string representation could be converted to object of FileRef class using FileRef::fromString method.
@JmixEntity(name = "petclinic_PetDto")
public class PetDto {
@JmixGeneratedValue
@JmixId
@JmixProperty(mandatory = true)
private UUID id;
@JmixProperty
private String photoFileRef;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getPhotoFileRef() {
return photoFileRef;
}
public void setPhotoFileRef(String photoFileRef) {
this.photoFileRef = photoFileRef;
}
}
@Service
@GraphQLApi
public class PetDtoService {
@GraphQLMutation
public PetDto createPetDto(PetDto petDto) {
FileRef photoFile = FileRef.fromString(petDto.getPhotoFileRef());
System.out.println("photoFile = " + photoFile);
return petDto;
}
}