Получить объект none в файле upload в Apollo graphql
После загрузки файла на сервер возвращается объект none.
настройка клиента apollo.используйте модуль apollo-upload-client и установите graphql uri
const apolloLink = createUploadLink({
uri: API_URL,
credentials: "same-origin",
});
export const apolloFetch = createApolloFetch({ uri: API_URL });
const apolloCache = new InMemoryCache();
const authLink = setContext((_, { headers }) =>
getAuth().then(jwt => ({
headers: {
...headers,
Authorization: jwt?.token ? `JWT ${jwt.token}` : "",
},
}))
);
const refreshTokenLink = new ApolloLink((operation, forward) => {
operation.setContext((_: any) =>
isAuthenticated().then(is => {
!is &&
getAuth().then(rt => {
rt != null &&
apolloFetch({
query: gqlPrint(mutations.REFRESH_TOKEN),
variables: { token: rt?.token },
}).then(
({
data: {
user: { refreshToken },
},
}: any) => {
if (refreshToken.success) setAuth(refreshToken.token);
else clearAuth();
}
);
});
})
);
return forward(operation);
});
export const gplClient = new ApolloClient({
link: from([refreshTokenLink, authLink, apolloLink]),
cache: apolloCache,
});
и настройка мутации загружает файл .Я уверен, что эта часть правильная и думаю, что ссылка set apollo неправильная
import React, { useCallback } from "react";
import { useDropzone } from "react-dropzone";
import gql from "graphql-tag";
import { useMutation } from "@apollo/react-hooks";
import { filesQuery } from "./Files";
const uploadFileMutation = gql`
mutation UploadFile($file: Upload!) {
uploadFile(file: $file)
}
`;
export const Upload = () => {
const [uploadFile] = useMutation(uploadFileMutation);
const onDrop =
([file]) => {
uploadFile({ variables: { file } });
}
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
return (
<div {...getRootProps()}>
<input {...getInputProps()} />
{isDragActive ? (
<p>Drop the files here ...</p>
) : (
<p>Drag 'n' drop some files here, or click to select files</p>
)}
</div>
);
};
пробовали решение Возвращение пустого объекта после загрузки файла - Apollo graphql
но все равно не работает :|
спасибо за помощь