-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraphQL: Inline Fragment on Array Fields #5908
GraphQL: Inline Fragment on Array Fields #5908
Conversation
@davimacedo Do you have any feedback on the |
It looks really good to me! It's for sure the best solution for the issue. Let's move forward with this spec. |
So a bad news is that |
So what do you think about the schema below? type ArrayItem {
value: Any
pointer: Class # we already have an interface called Class
}
type SomeClass {
arrayField: [ArrayItem!]
} |
The new spec look like this: query GetCustomer($objectId: ID!) {
objects {
getCustomer(objectId: $objectId) {
objectId
manyRelations {
... on CustomerClass {
objectId
someCustomerField
arrayField {
... on Element {
value
}
}
}
... on SomeClassClass {
objectId
someClassField
}
}
createdAt
updatedAt
}
}
} |
With my suggestion it would be: query GetCustomer($objectId: ID!) {
objects {
getCustomer(objectId: $objectId) {
objectId
manyRelations {
pointer {
... on CustomerClass {
objectId
someCustomerField
arrayField {
value
}
}
... on SomeClassClass {
objectId
someClassField
}
}
}
createdAt
updatedAt
}
}
} It is little bit harder for returning the pointers (but still intuitive) and a lot easier for returning no pointer values (most common scenario). |
You can also return query GetCustomer($objectId: ID!) {
objects {
getCustomer(objectId: $objectId) {
objectId
manyRelations {
pointer {
objectId
createdAt
updatedAt
}
}
createdAt
updatedAt
}
}
} |
Codecov Report
@@ Coverage Diff @@
## master #5908 +/- ##
===========================================
- Coverage 93.69% 82.95% -10.74%
===========================================
Files 153 153
Lines 10769 10801 +32
===========================================
- Hits 10090 8960 -1130
- Misses 679 1841 +1162
Continue to review full report at Codecov.
|
I think inline fragment will do the job to dive into arrays, i don't really see real benefits of data architecture like: type ArrayItem {
value: Any
pointer: Class # we already have an interface called Class
} because it's the native behavior of It's now fully functional and tested, i invite you to give it a try on localhost 🚀 |
I currently don't understand why Postgres fail, do you have an idea @davimacedo ? |
I am not sure but I guess it is something related to the selectedFields. Because of the inline fragment, it is probably returning more keys than what you expected, you are sending these keys to Postgres and it is failing because the field does not exist in the class. Try to debug the selectedValues that you are passing to the rest api. If you prefer I can also take a look on this later today. |
@davimacedo so the postgres error is due to Effects: More data returned to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! I added few questions.
Everything else seems good to me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! LGTM!
* Inline Fragment Spec * Inline Fragment on Arrays * Fix Test * Only select the root field * Requested Changes * Lazy Loaded ArrayResult
#5894
#5863
Allow to dive into pointers contained in an array field