Last active
March 18, 2019 20:23
-
-
Save Loschcode/f1a4302bfc47cf48aa2fdc3163bd95b3 to your computer and use it in GitHub Desktop.
If anyone wonders why the JS world is a fucking mess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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