feat: f**k the __typename :)
This commit is contained in:
@ -15,6 +15,7 @@ import { onError } from "@apollo/client/link/error";
|
||||
import { WebSocketLink } from "@apollo/client/link/ws";
|
||||
import { getMainDefinition } from "@apollo/client/utilities";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { deepOmit } from "../../utils/deep-omit";
|
||||
|
||||
const schema = buildClientSchema(
|
||||
introspectionResult as unknown as IntrospectionQuery
|
||||
@ -24,6 +25,15 @@ const typesMap = {
|
||||
DateTime: DateTimeResolver,
|
||||
};
|
||||
|
||||
const cleanTypeName = new ApolloLink((operation, forward) => {
|
||||
if (operation.variables) {
|
||||
operation.variables = deepOmit(["__typename"], operation.variables);
|
||||
}
|
||||
return forward(operation).map((data) => {
|
||||
return data;
|
||||
});
|
||||
});
|
||||
|
||||
export const FennecApolloClientProvider: FC = ({ children }) => {
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
const errorLink = onError(({ graphQLErrors, networkError }) => {
|
||||
@ -71,6 +81,7 @@ export const FennecApolloClientProvider: FC = ({ children }) => {
|
||||
const link = ApolloLink.from([
|
||||
errorLink,
|
||||
withScalars({ schema, typesMap }) as unknown as ApolloLink,
|
||||
cleanTypeName,
|
||||
splitLink,
|
||||
]);
|
||||
const client = new ApolloClient({
|
||||
|
Reference in New Issue
Block a user