GithubHelp home page GithubHelp logo

Comments (4)

JoviDeCroock avatar JoviDeCroock commented on April 27, 2024

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.

from graphql-js.

jacob-orbiit avatar jacob-orbiit commented on April 27, 2024

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?).

from graphql-js.

JoviDeCroock avatar JoviDeCroock commented on April 27, 2024

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

from graphql-js.

jacob-orbiit avatar jacob-orbiit commented on April 27, 2024

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

from graphql-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.