Я пытаюсь войти в GraphQL, и я последовал руководству по простому приложению GraphQL + Spring + MySQL и переделал его для своей собственной базы данных. Но когда я пытаюсь выполнить свой запрос findAllDocuments , я получаю следующий ответ в Postman:
"data": null,
"errors": [
{
"message": "Validation error of type FieldUndefined: Field 'findAllDocuments' in type 'query' is undefined @ 'findAllDocuments'",
"locations": [
{
"line": 2,
"column": 5,
"sourceName": null
}
],
"description": "Field 'findAllDocuments' in type 'query' is undefined",
"validationErrorType": "FieldUndefined",
"queryPath": [
"findAllDocuments"
],
"errorType": "ValidationError",
"path": null,
"extensions": null
}
]
}
Это сущность, которую я пытаюсь получить (у нее есть несколько сложных типов данных, таких как Group или носители, которые имеют реализацию, аналогичную классу Document , я не включил их для экономии места):
@Table(name = "documents")
public class Document {
@Id
@Column(name = "doc_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "title")
private String title;
@Column(name = "data")
private String data;
@Column(name = "data_asc")
private String dataAsc;
@Column(name = "external_link")
private String externalLink;
@OneToMany
@JoinColumn(name = "doc_id")
private List<DocumentForum> forums;
@Column(name = "navbar")
private String navbar;
@Column(name = "date_created")
private Date dateCreated;
@Column(name = "publish_start")
private Date publishStart;
@Column(name = "publish_end")
private Date publishEnd;
@OneToOne
@JoinColumn(name = "user_id")
private UserDetails author;
@OneToOne
@JoinColumn(name = "group_id")
private Group group;
@OneToMany(mappedBy = "document")
private List<Media> media;
@Column(name = "temp_id")
private Integer tempId;
@Column(name = "views_total")
private int viewsTotal;
@Column(name = "views_month")
private int viewsMonth;
@Column(name = "searchable")
private boolean searchable;
@Column(name = "available")
private boolean available;
@Column(name = "cacheable")
private boolean cacheable;
@Column(name = "file_name")
private String fileName;
@Column(name = "file_change")
private Date fileChange;
@Column(name = "sort_priority")
private int sortPriority;
@Column(name = "header_doc_id")
private int headerDocId;
@Column(name = "menu_doc_id")
private int menuDocId;
@Column(name = "footer_doc_id")
private int footerDocId;
@Column(name = "password_protected")
private String passwordProtected;
@Column(name = "html_head")
private String htmlHead;
@Column(name = "perex_place")
private String perexPlace;
@Column(name = "perex_image")
private String perexImage;
@Column(name = "perex_group")
private String perexGroup;
@Column(name = "show_in_menu")
private boolean showInMenu;
@Column(name = "event_date")
private Date eventDate;
@Column(name = "virtual_path")
private String virtualPath;
@Column(name = "sync_id")
private int syncId;
@Column(name = "sync_status")
private int syncStatus;
@Column(name = "logon_page_doc_id")
private int logonPageDocId;
@Column(name = "right_menu_doc_id")
private int rightMenuDocId;
@Column(name = "field_a")
private String fieldA;
@Column(name = "field_b")
private String fieldB;
@Column(name = "field_c")
private String fieldC;
@Column(name = "field_d")
private String fieldD;
@Column(name = "field_e")
private String fieldE;
@Column(name = "field_f")
private String fieldF;
@Column(name = "field_g")
private String fieldG;
@Column(name = "field_h")
private String fieldH;
@Column(name = "field_i")
private String fieldI;
@Column(name = "field_j")
private String fieldJ;
@Column(name = "field_k")
private String fieldK;
@Column(name = "field_l")
private String fieldL;
@Column(name = "disable_after_end")
private boolean disableAfterEnd;
@Column(name = "forum_count")
private int forumCount;
@Column(name = "field_m")
private String fieldM;
@Column(name = "field_n")
private String fieldN;
@Column(name = "field_o")
private String fieldO;
@Column(name = "field_p")
private String fieldP;
@Column(name = "field_q")
private String fieldQ;
@Column(name = "field_r")
private String fieldR;
@Column(name = "field_s")
private String fieldS;
@Column(name = "field_t")
private String fieldT;
@Column(name = "require_ssl")
private boolean requireSsl;
@Column(name = "root_group_l1")
private Integer rootGroupL1;
@Column(name = "root_group_l2")
private Integer rootGroupL2;
@Column(name = "root_group_l3")
private Integer rootGroupL3;
*********SETTER AND GETTERS*********
Это файл .graphqls для Document class:
scalar Date
type Document{
id: Int!
title: String!
data: String!
dataAsc: String!
externalLink: String!
forums: [DocumentForum]!
navbar: String!
dateCreated: Date!
publishStart: Date
publishEnd: Date
author: UserDetails!
group: Group!
media: [Media]!
tempId: Int!
viewsTotal: Int!
viewsMonth: Int!
searchable: Boolean!
available: Boolean!
cacheable: Boolean!
fileName: String
fileChange: Date
sortPriority: Int!
headerDocId: Int!
menuDocId: Int!
footerDocId: Int!
passwordProtected: String
htmlHead: String!
perexPlace: String!
perexImage: String!
perexGroup: String
showInMenu: Boolean!
eventDate: Date
virtualPath: String!
syncId: Int!
syncStatus: Int!
logonPageDocId: Int!
rightMenuDocId: Int!
fieldA: String!
fieldB: String!
fieldC: String!
fieldD: String!
fieldE: String!
fieldF: String!
fieldG: String!
fieldH: String!
fieldI: String!
fieldJ: String!
fieldK: String!
fieldL: String!
disableAfterEnd: Boolean!
forumCount: Int!
fieldM: String!
fieldN: String!
fieldO: String!
fieldP: String!
fieldQ: String!
fieldR: String!
fieldS: String!
fieldT: String!
requireSsl: Boolean!
rootGroupL1: Int
rootGroupL2: Int
rootGroupL3: Int
}
type Query {
findAllDocuments: [Document]!
}
Это Запрос Класс распознавателя:
public class Query implements GraphQLQueryResolver {
private final DocumentRepository documentRepository;
private final DocumentForumRepository documentForumRepository;
private final GroupRepository groupRepository;
private final MediaRepository mediaRepository;
private final UserDetailsRepository userDetailsRepository;
@Autowired
public Query(DocumentRepository documentRepository,
DocumentForumRepository documentForumRepository,
GroupRepository groupRepository,
MediaRepository mediaRepository,
UserDetailsRepository userDetailsRepository){
this.documentRepository = documentRepository;
this.documentForumRepository = documentForumRepository;
this.groupRepository = groupRepository;
this.mediaRepository = mediaRepository;
this.userDetailsRepository = userDetailsRepository;
}
public Iterable<Document> findAllDocuments(){
return documentRepository.findAll();
}
public Iterable<DocumentForum> findAllDocumentForums(){
return documentForumRepository.findAll();
}
public Iterable<Group> findAllGroups(){
return groupRepository.findAll();
}
public Iterable<Media> findAllMedia(){
return mediaRepository.findAll();
}
}
И это DocumentResolver Класс:
public class DocumentResolver implements GraphQLResolver<Document> {
private DocumentForumRepository documentForumRepository;
private GroupRepository groupRepository;
private MediaRepository mediaRepository;
private UserDetailsRepository userDetailsRepository;
@Autowired
public DocumentResolver(DocumentForumRepository documentForumRepository,
GroupRepository groupRepository,
MediaRepository mediaRepository,
UserDetailsRepository userDetailsRepository){
this.documentForumRepository = documentForumRepository;
this.groupRepository = groupRepository;
this.mediaRepository = mediaRepository;
this.userDetailsRepository = userDetailsRepository;
}
public List<DocumentForum> getForums(Document document){
return documentForumRepository.findAllById(document.getId());
}
public UserDetails getAuthor(Document document) throws ObjectNotFoundException {
Optional<UserDetails> optionalUserDetails = userDetailsRepository.findById(document.getId());
if(optionalUserDetails.isPresent()){
return optionalUserDetails.get();
}else{
throw new ObjectNotFoundException();
}
}
public Group getGroup(Document document) throws ObjectNotFoundException {
Optional<Group> optionalGroup = groupRepository.findById(document.getId());
if(optionalGroup.isPresent()){
return optionalGroup.get();
}else{
throw new ObjectNotFoundException();
}
}
public List<Media> getMedia(Document document) {
return mediaRepository.findAllById(document.getId());
}
}
Запрос, который я пытаюсь отправить от Почтальона:
{
findAllDocuments{
id
title
data
}
}
Все работает в моем меньшем проекте, и я не могу точно определить, в чем здесь проблема. Если что-то еще нужно, пожалуйста, дайте мне знать, и я предоставлю это. Спасибо.