Comments (9)
I'm not super sure what this means. Is this to catch a query like this:
{
a
a
b
}
?
from graphql-api.
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.
Relevant parts of the spec:
- https://facebook.github.io/graphql/#sec-Field-Selection-Merging
- https://facebook.github.io/graphql/#sec-Field-Collection
- https://facebook.github.io/graphql/#sec-Value-Completion (esp.
MergeSelectionSet
)
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.
Also!
{
a {
foo
}
a {
bar
}
}
=>
{
"a": {
"foo": 1,
"bar": 2
}
}
from graphql-api.
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.
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 forspread
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.
Thanks, that was useful! My initial reaction is that after FragmentSpread
has been resolved it should be possible to rewrite the nested SelectionSet
s 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.
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 selectionSet
s 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.
from graphql-api.
Related Issues (20)
- Domain errors on Mutations HOT 1
- Deriving instance FromValue - guideline for using underscore in Record field names HOT 2
- Do the warnings 'No explicit implementation for ToValue' cause errors elsewhere
- Thinking about Subscriptions HOT 1
- ValidationError VariableTypeNotFound despite presence in the schema HOT 4
- Simplify code by using DuplicateRecordFields and NamedFieldPuns HOT 3
- Refactor Value kind definition
- Simplify Value related function
- Provide a way to pass initialValue between resolver calls HOT 1
- Should graphql's selection sets be subtypes or records in haskell (as opposed to JSON-like AST) ?
- Latest release points to 0.1.1 (not 0.3.0) HOT 1
- How to construct a complex Object from Record? HOT 6
- Intergrating GraphQL and Servent Generically HOT 1
- List of Object makes an error (Tried to treat object as if it were leaf field)
- Is this project still under development ? HOT 1
- Issue with parsing non-nullable types
- Parsing documents with comments HOT 1
- How Integrate with DB provider?
- Question regarding updated features HOT 2
- Build error in `src/GraphQL/Internal/Syntax/Parser.hs`: No instance for (ConvertText Text ByteString)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-api.