Skip to content

Instantly share code, notes, and snippets.

@Loschcode
Last active March 18, 2019 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Loschcode/f1a4302bfc47cf48aa2fdc3163bd95b3 to your computer and use it in GitHub Desktop.
Save Loschcode/f1a4302bfc47cf48aa2fdc3163bd95b3 to your computer and use it in GitHub Desktop.
If anyone wonders why the JS world is a fucking mess
// those 2 abstract of the same library are supposed to do the exact same thing, but are written totally differently
// because no one cared about restricting the way you should use their public API.
// because there's no real public API, because JS.
const hasSubscriptionOperation = ({ query: { definitions } }) => {
return definitions.some(
({ kind, operation }) =>
kind === 'OperationDefinition' && operation === 'subscription'
)
}
// VS
import { getMainDefinition } from 'apollo-utilities';
const subscription = ({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment