kandimat/redaktions-app/src/backend/queries/answer.ts
2021-01-09 12:49:28 +01:00

99 lines
2.2 KiB
TypeScript

import { gql } from "@apollo/client";
import { BasicQuestionFragment, BasicQuestionResponse } from "./question";
import { CandidatePosition } from "../../components/CandidatePositionLegend";
export const FullAnswerFragment = gql`
fragment FullAnswerFragment on Answer {
id
text
position
questionRowId
personRowId
}
`;
export interface FullAnswerResponse {
id: string;
text: string | null;
position: CandidatePosition;
questionRowId: number;
personRowId: number;
__typename: "Answer";
}
export const GET_ANSWER_BY_QUESTION_AND_PERSON = gql`
query GetAnswerByQuestionAndPerson($questionRowId: Int!, $personRowId: Int!) {
answerByQuestionRowIdAndPersonRowId(
personRowId: $personRowId
questionRowId: $questionRowId
) {
...FullAnswerFragment
}
}
${FullAnswerFragment}
`;
export interface GetAnswerByQuestionAndPersonResponse {
answerByQuestionRowIdAndPersonRowId: FullAnswerResponse | null;
}
export interface GetAnswerByQuestionAndPersonVariables {
personRowId: number;
questionRowId: number;
}
export const AnswerPositionFragment = gql`
fragment AnswerPositionFragment on Answer {
id
position
}
`;
export interface AnswerPositionResponse {
id: string;
position: CandidatePosition;
__typename: "Answer";
}
export const QuestionAnswerFragment = gql`
fragment QuestionAnswerFragment on Question {
...BasicQuestionFragment
answersByQuestionRowId(condition: { personRowId: $personRowId }) {
nodes {
...AnswerPositionFragment
}
}
}
${BasicQuestionFragment}
${AnswerPositionFragment}
`;
export interface QuestionAnswerResponse extends BasicQuestionResponse {
answersByQuestionRowId: {
nodes: Array<AnswerPositionResponse>;
__typename: "AnswersConnection";
};
}
export const GET_ALL_QUESTION_ANSWERS = gql`
query AllQuestionAnswers($personRowId: Int) {
allQuestions(orderBy: CATEGORY_ROW_ID_ASC) {
nodes {
...QuestionAnswerFragment
}
}
}
${QuestionAnswerFragment}
`;
export interface GetAllQuestionAnswersResponse {
allQuestions: {
nodes: Array<QuestionAnswerResponse>;
__typename: "QuestionsConnection";
};
}
export interface GetAllQuestionAnswersVariables {
personRowId?: number | null;
}