Comments (4)
@robrichard I need this feature for a project I am working on. So, I have forked the repo and started working on the implementation. However, I ran into a decision issue with the structure of the __arguments
field.
Given the following query
query {
foo {
bars(isQuux: true, limit: 10, status: "active", sort: ["name", "asc"]) {
name
status
}
}
}
We would get something like
{
bars: {
__arguments: [
{
isQuux: {
kind: 'BooleanValue',
value: true,
},
},
{
limit: {
kind: 'IntValue',
value: 10,
},
},
{
status: {
kind: 'StringValue',
value: 'active',
},
},
{
sort: {
kind: 'ListValue',
value: ['name', 'asc'],
},
},
],
name: {},
status: {},
}
}
Now, consider a query like the following where the predicates
argument is an object.
query {
foo {
bars(predicates: { name: { regex: "^Quu?x" }, status: { eq: "active" } }, limit: 10, sort: ["name", "asc"]) {
name
status
}
}
}
There are several possible structures that could be returned.
- Nested
kind
s, backwards convention-compatible
{
bar: {
__arguments: [
{
predicates: {
kind: 'ObjectValue',
value: {
name: {
kind: 'ObjectValue',
value: {
regex: {
kind: 'StringValue',
value: '^Quu?x',
}
},
},
status: {
kind: 'ObjectValue',
value: {
eq: {
kind: 'StringValue',
value: 'active',
}
},
},
},
},
},
{
limit: {
kind: 'IntValue',
value: 10,
},
},
{
sort: {
kind: 'ListValue',
value: ['name', 'asc'],
},
},
],
name: {},
status: {},
}
}
- Top-level
kinds
, backwards convention-compatible
{
bar: {
__arguments: [
{
predicates: {
kind: 'ObjectValue',
value: {
name: {
regex: '^Quu?x',
},
status: {
eq: 'active',
},
},
},
},
{
limit: {
kind: 'IntValue',
value: 10,
},
},
{
sort: {
kind: 'ListValue',
value: ['name', 'asc'],
},
},
],
name: {},
status: {},
}
}
- Simple, not-backwards compatible (good for version 3x). This is the same structure that the
args
argument (second parameter) has for theresolve
function.
{
bar: {
__arguments: {
predicates: {
name: {
regex: '^Quu?x',
},
status: {
eq: 'active',
},
},
limit: 10,
sort: ['name', 'asc'],
},
name: {},
status: {},
}
}
Which structure would you prefer that I return for version 2? Option 1 or 2?
Should we start version 3 now so that we can use the simple structure?
from graphql-fields.
@dhurlburtusa I'd prefer to go with No. 1 to keep consistency. I don't think the improvement in No. 3 is worth the churn of breaking changes
from graphql-fields.
@robrichard Thanks for the timely reply.
BTW, did you notice that the items in a ListValue
are flattened in version 2 (at least for primitives)? We can't change this for version 2 because that would be a breaking change. (Well, maybe we can by saying it is fixing an unintentional bug.) But Lists with Strings really should be like the following if we want to include kind
with each value
:
{
bar: {
__arguments: [
# Same as in previous examples
...
{
sort: {
kind: 'ListValue',
value: [
{
kind: 'StringValue',
value: 'name',
},
{
kind: 'StringValue',
value: 'asc',
},
],
},
},
],
...
}
}
But the current code simply takes the value.value
of the item AST. It does not examine the kind of the items of the List. So, a List of Lists will have undefined
for each item since a List AST doesn't have a value
property of the value
property. It has a values
property instead (notice the s
at the end), i.e., value.values
. Similarly, Object AST doesn't have a value
property of the value
property. It has a fields
property instead, i.e., value.fields
.
This is an unreported bug. Would you like me to open an issue for it? How should we handle the fix? Currently, primitive values get flattened and non-primitives become undefined
. For backwards compatibility, I guess we can keep primitives as flat instead of an object like { kind: ..., value: ... }
but keep them expanded for Lists and Objects. Or we can flatten them when they are items of a list. Which way would you prefer to go?
BTW, wish I could see your talk at JSKongress - 2019 on "Streaming HTTP and GraphQL".
from graphql-fields.
This works for ObjectValue
type arguments.
I'd say this issue could be closed.
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
- Port to TypeScript HOT 1
- Does not take variables in processed arguments into account HOT 1
- Doesn't acknowledge default argument values HOT 3
- Discussion: New API for this package HOT 6
- 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.