Skip to content
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

Type definition for DefinitionNode appears to be wrong #4012

Closed
jacob-orbiit opened this issue Jan 23, 2024 · 4 comments
Closed

Type definition for DefinitionNode appears to be wrong #4012

jacob-orbiit opened this issue Jan 23, 2024 · 4 comments

Comments

@jacob-orbiit
Copy link

Property 'selectionSet' does not exist on type 'DefinitionNode'.
  Property 'selectionSet' does not exist on type 'SchemaDefinitionNode'.ts(2339)

I've inspected parse(op).definitions[0].selectionSet, and it does indeed exist.

I see DefinitionNode includes ExecutableDefinitionNodeOperationDefinitionNode, and OperationDefinitionNode has selectionSet, but the definition doesn't seem to follow that deep.

@JoviDeCroock
Copy link

A DefinitionNode can also be part of the SchemaDefinition part of the GraphQL lanaguage, this means that to efficiently narrow the type you would have to do.

if (definition.kind === Kind.OPERATION_DEFINITION || definition.kind === Kind.FRAGMENT_DEFINITION) {}

Doing the above ensures that you are dealing with the query-language and hence have a selection-set.

@jacob-orbiit
Copy link
Author

Ah, that does solve the initial selectionSet issue. But then it reveals:

Property 'alias' does not exist on type 'SelectionNode'.
  Property 'alias' does not exist on type 'FragmentSpreadNode'.
Property 'name' does not exist on type 'SelectionNode'.
  Property 'name' does not exist on type 'InlineFragmentNode'.
Property 'operation' does not exist on type 'OperationDefinitionNode | FragmentDefinitionNode'.
  Property 'operation' does not exist on type 'FragmentDefinitionNode'.

There surely must be a way to do this would a bunch of narrowing because the code actually works fine (perhaps because my inputs are uniform?).

@JoviDeCroock
Copy link

I mean, these are all valid type errors and your code will fail for other permutations of the query-language. 😅

the first one is the distinction between

query { x { alias: field ...fragment } }

Where you can see whether the .kind is a FragmentSpreadNode, same goes for the second where the distinction is between an inline fragment and a selectionNode as an inline fragment has no name only a potential type-condition and the last one is the distinction between defining an operation and defining a fragment. All of these are valid issues to point out

@jacob-orbiit
Copy link
Author

Ahh, yes. Sorry, of course 🤦‍♂️ Thanks for the explanation.

@jacob-orbiit jacob-orbiit closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants