-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add getMainDefinition
back to @apollo/client/utilities
#12725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: cf54a50 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
size-limit report 📦
|
src/utilities/getMainDefinition.ts
Outdated
@@ -24,19 +21,13 @@ export function getMainDefinition( | |||
|
|||
for (let definition of queryDoc.definitions) { | |||
if (definition.kind === "OperationDefinition") { | |||
const operation = (definition as OperationDefinitionNode).operation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of these type-casts were unnecessary since TypeScript already narrowed the type based on the .kind
check above.
operation
is also a non-null property with only 3 operation types, so I went ahead and removed the check here since we can assume GraphQL will always return a valid operation type.
As an alternative, what do you think about adding That should cover all our documented use cases and even save users from fiddling on AST nodes. |
f94b559
to
702e9d3
Compare
getMainDefinition
back to @apollo/client/utilities
getMainDefinition
back to @apollo/client/utilities
Fixes #12722
We recommend this in our docs so we should continue to support this as a public utility.