Giter Site home page Giter Site logo

Comments (9)

teh avatar teh commented on September 13, 2024

I'm not super sure what this means. Is this to catch a query like this:

{
  a
  a
  b
}

?

from graphql-api.

jml avatar jml commented on September 13, 2024

It's kind of detailed actually. I'll try to sum up:

Handle fragment spreads

e.g. This is a valid query:

{
  foo
  bar
  ... myFrag
}

fragment myFrag {
  bar
  qux
}

And the output should look something like:

{
  "foo": 1,
  "bar": 2,
  "qux": 3,
}

Aggregate identical fields

e.g.

{
  a
  b
  b
}

Should just be processed as if it were:

{
  a
  b
}

Bork on non-identical fields

{
  a
  b
  b(1)
}

from graphql-api.

jml avatar jml commented on September 13, 2024

Relevant parts of the spec:

Reason all these are together is because the implementation for all of them will involve changing the type of SelectionSet in validation. Currently, it's a list of Selection, but it'll probably become some sort of OrderedMap or at least something more structured.

Probably also FragmentSpread will disappear from the fully-resolved type, which will be a mercy.

Anyway, as you can guess from this commentary, I'm at the level where it's easier for me to code it than to explain it.

from graphql-api.

jml avatar jml commented on September 13, 2024

Also!

{
  a {
    foo
  }
  a {
    bar
  }
}

=>

{
  "a": {
    "foo": 1,
    "bar": 2
  }
}

from graphql-api.

jml avatar jml commented on September 13, 2024

The way this works in the spec is that validation confirms that everything is mergeable and at execution each selection set gets flattened to fields only (one level at a time), and then evaluated.

The natural thing to do in our approach would be to flatten everything in the validator, but we this doesn't chime with the way we're doing unions (which I understand less now than I did before I started reading the spec).

Will continue to mull.

from graphql-api.

jml avatar jml commented on September 13, 2024

Here's where I've got to conceptually. Don't know how this fits into our code.

  • after validation, each selection set will be a thing that contains:
    • fields
    • inline fragments with type conditions
    • no fragment spreads
    • i.e. a slightly narrower Selection (with no need for spread type parameter!)
  • although validation can check for uniqueness across those, it'll be extremely difficult to construct a value that guarantees uniqueness (e.g. a map)
  • however, instead of thinking of it like a mixed bag of Selection as we currently do, we can think of is like a function: TypeName -> OrderedMap FieldName Field
    • that is, once we know the type that the selection set is for, we can immediately flatten it to an ordered map of unique fields
    • might be an error condition in the type too, if the type name is not one that's in the selection set
    • if we do this, the Resolver becomes a thing that operates only on SelectionSets and Fields—a nice property, IMO—also eliminates possibility of duplicate fields and gives us the merging behaviour above "for free"

Still mulling though.

I think this (and lots of other things) will be easier with end-to-end, which will allow for easier experimentation.

from graphql-api.

teh avatar teh commented on September 13, 2024

Thanks, that was useful! My initial reaction is that after FragmentSpread has been resolved it should be possible to rewrite the nested SelectionSets into a single, well-formed SelectionSet query, including union for which we can treat each InlineFragment separately: it's a sum type and we'll chose exactly one. I'm sure I'm missing something so let's chat tomorrow!

from graphql-api.

teh avatar teh commented on September 13, 2024

After discussing this in person we can probably implement this by rewriting the selectionSet in the HasGraph m (API.Union unionName objects) instance. Whether we do that by making all selectionSets a function that take e.g. a PickBranch Name or whether we do that locally in just the Union instance depends on which design will be easier in the end.

from graphql-api.

jml avatar jml commented on September 13, 2024

from graphql-api.

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.