Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
case 'commands':
return 'Command';
case 'products':
return 'Product';
case 'reviews':
return 'Review';
default:
throw new Error(`Unknown resource ${resource}`);
}
};
return buildApolloClient({
clientOptions: {
uri: 'http://localhost:4000/graphql',
},
}).then(dataProvider => (type, resource, params) =>
dataProvider(type, getGqlResource(resource), params)
);
};
export default () => {
return buildApolloClient({
clientOptions: {
uri: 'http://localhost:4000/graphql',
},
introspection: {
operationNames: {
[DELETE]: resource => `remove${resource.name}`
}
},
buildQuery: customBuildQuery
}).then(dataProvider => (type, resource, params) =>
dataProvider(type, getGqlResource(resource), params)
);
};
const customBuildQuery = introspectionResults => {
const buildQuery = buildQueryFactory(introspectionResults);
return (type, resource, params) => {
if (type === DELETE) {
return {
query: gql`mutation remove${resource}($id: ID!) {
remove${resource}(id: $id)
}`,
variables: { id: params.id },
parseResponse: ({ data }) => {
if (data[`remove${resource}`]) {
return { data: { id: params.id } };
}
throw new Error(`Could not delete ${resource}`);
}
}
case 'songs':
return 'Song';
case 'playlistSongs':
return 'PlaylistSong';
case 'historySongs':
return 'HistorySong';
default:
throw new Error(`Unknown resource ${resource}`);
}
};
return buildApolloClient({
clientOptions: {
link: authLink.concat(httpLink),
cache: new InMemoryCache()
}
})
.then((dataProvider: any) => (type: any, resource: string, params: any) =>
dataProvider(type, getGqlResource(resource), params)
)
.catch(() => {
localStorage.clear();
window.location.reload();
});
};