Add more graphql support to Link
This commit is contained in:
parent
d7f8c87ccb
commit
60f6061d49
14 changed files with 251 additions and 159 deletions
|
|
@ -1,84 +1,24 @@
|
|||
import { GetServerSideProps, GetServerSidePropsContext } from "next";
|
||||
import Head from "next/head";
|
||||
import useSWR from "swr";
|
||||
import { request, gql } from "graphql-request";
|
||||
import { NextPage } from "next";
|
||||
import { Grid } from "@mui/material";
|
||||
import { Layout } from "components/Layout";
|
||||
import { TicketDetail } from "components/TicketDetail";
|
||||
import { TicketEdit } from "components/TicketEdit";
|
||||
import { getTicketQuery } from "graphql/getTicketQuery";
|
||||
|
||||
type TicketProps = {
|
||||
id: string;
|
||||
};
|
||||
|
||||
const Ticket: NextPage<TicketProps> = ({ id }) => {
|
||||
const origin =
|
||||
typeof window !== "undefined" && window.location.origin
|
||||
? window.location.origin
|
||||
: "";
|
||||
const graphQLFetcher = async ({ document, variables }: any) => {
|
||||
const data = await request({
|
||||
url: `${origin}/graphql`,
|
||||
document,
|
||||
variables,
|
||||
});
|
||||
console.log({ data });
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
const { data: ticketData, error: ticketError }: any = useSWR(
|
||||
{
|
||||
document: gql`
|
||||
query getTicket($ticketId: Int!) {
|
||||
ticket(ticket: { ticketInternalId: $ticketId }) {
|
||||
id
|
||||
internalId
|
||||
title
|
||||
note
|
||||
number
|
||||
createdAt
|
||||
updatedAt
|
||||
closeAt
|
||||
articles {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
body
|
||||
internal
|
||||
sender {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { ticketId: parseInt(id, 10) },
|
||||
document: getTicketQuery,
|
||||
variables: { ticketId: `gid://zammad/Ticket/${id}` },
|
||||
},
|
||||
graphQLFetcher,
|
||||
{ refreshInterval: 1000 }
|
||||
);
|
||||
|
||||
const { data: graphqlData2, error: graphqlError2 } = useSWR(
|
||||
{
|
||||
document: gql`
|
||||
{
|
||||
__schema {
|
||||
queryType {
|
||||
name
|
||||
fields {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {},
|
||||
},
|
||||
graphQLFetcher
|
||||
{ refreshInterval: 100000 }
|
||||
);
|
||||
|
||||
const shouldRender = !ticketError && ticketData;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue