Comments (6)
graphql-parse-resolve-info looks like it solves all the issues mentioned in the original post. I recommend using that going forward.
from graphql-fields.
I tried working on a new API this last weekend. I haven't yet come up with a useful API that takes into account aliases, arguments, named fragments (derived from FragmentSpread and FragmentDefinition), inline fragments, interfaces, unions, and sub-fields of objects or lists of objects.
One attempt used aliases as keys of an object. Unfortunately, I didn't find this too useful on the server-side since the server isn't going to know what aliases the client will be sending. I still have to traverse the tree to find the field information. When I am trying to identify the columns (aka projections) and associated data models to include, I don't care much about the alias.
I can post some of the structures here if it helps. I am hesitant to do it here because it may just obscure this discussion. Maybe we can post them in a Gist or something.
After a lot of trial-and-error, each field in the tree can have four pieces of information for each alias/type pair that could potentially be associated. The four pieces are the alias, args, the interface or concrete type of the containing object, and sub-fields for object or list fields.
I can provide some concrete examples for the above. Let me know if you would like them posted here.
from graphql-fields.
graphql-parse-resolve-info seems to support aliased fields.
from graphql-fields.
I think we're mostly on the same page. I think we need a structured class object with methods to access selections as iterables.
I don't think we should expose the alias used by the client, since that should not change what results the GraphQL server returns, but we do need to make sure that all selections and args are available.
query {
pet(id: "foo") {
fullName: name(type: "full")
name
... on Cat {
breed
}
... on Dog {
breed
group
}
}
}
const field = new GraphQLField(info); // info from pet resolver
field.hasSelection('name') // true
field.hasSelection('fullName') // false, aliases don't count
const nameSelections = field.getSelections('name') // returns `GraphQLField`s for `name` and `fullName` selection
// field.getSelections() is an iterable of GraphQLField objects
for (const selection of field.getSelections()) {
console.log(selection.name, selection.type);
// selection.getArgs() is an iterable
for (const arg of selection.getArgs()) {
console.log('args:', arg.name, arg.value);
}
}
/* logs
name, Pet
args: type, full
name, Pet
breed, Cat
breed, Dog
group, Dog
*/
This is just a really rough draft that I haven't put a ton of thought into. We'll need to find a balance between being easy to use and exposing all of the necessary data.
from graphql-fields.
That is along the lines of what I have started. I have a class, GraphQlResolveInfoInspector
, where you can pass in the resolveInfo into the constructor. I have a method named isSelected
that takes a dot separated or an array of field names. I'll need to update it to return an iterable of some type of object such as the GraphQlFields
. I have a couple other methods but I am not sure if they'll be useful.
from graphql-fields.
FWIW here are a few things I've encountered that don't work with the arguments feature:
- arguments sent as variables
my_query(search: $search)
- arguments of type object
my_query(params: { a: 1 })
- default argument values (defined in schema)
input my_input { size: Int = 1 }
from graphql-fields.
Related Issues (20)
- Parsing arguments of nested fields HOT 4
- Please add CHANGELOG
- There is no support for aliased fields HOT 5
- Does not return Object type arguments HOT 4
- Port to TypeScript HOT 1
- Does not take variables in processed arguments into account HOT 1
- Doesn't acknowledge default argument values HOT 3
- variables don't pass information of their kind
- Doesn't coerce single item to list
- if arguments = null not include
- Support graphql 15? HOT 4
- [FR] extract field extensions
- Examples with buildSchema
- (0 , graphql_fields_1.default) is not a function HOT 2
- How to incorporate this library when unit testing components
- End leafs are object literal HOT 3
- Keep maintaining this library
- The example in the README is misleading HOT 2
- Compiled module breaks IE11 HOT 4
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-fields.