feat: f**k the __typename :)

This commit is contained in:
Ivan Li
2021-06-26 23:30:09 +08:00
parent dee2c97ba4
commit 120a720be5
2 changed files with 33 additions and 0 deletions

View File

@ -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({