Title: Can't resolve fields of inline fragments when inspecting a query · Issue #1718 · graphql-java/graphql-java · GitHub
Open Graph Title: Can't resolve fields of inline fragments when inspecting a query · Issue #1718 · graphql-java/graphql-java
X Title: Can't resolve fields of inline fragments when inspecting a query · Issue #1718 · graphql-java/graphql-java
Description: I've ran into similar issue as in already reported #973 but with no information about how to go around it. Background What we are doing is that, at the beginning of query execution, we inspect the whole query to create our custom graph d...
Open Graph Description: I've ran into similar issue as in already reported #973 but with no information about how to go around it. Background What we are doing is that, at the beginning of query execution, we inspect the ...
X Description: I've ran into similar issue as in already reported #973 but with no information about how to go around it. Background What we are doing is that, at the beginning of query execution, we inspect ...
Opengraph URL: https://github.com/graphql-java/graphql-java/issues/1718
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Can't resolve fields of inline fragments when inspecting a query","articleBody":"I've ran into similar issue as in already reported **https://github.com/graphql-java/graphql-java/issues/973** but with no information about how to go around it. \r\n\r\n**Background**\r\nWhat we are doing is that, at the beginning of query execution, we inspect the whole query to create our custom graph data fetching strategy before the GQL data fetchers are called. Data fetchers, in the end, should just access the graph data fetching result, and should not do any DB fetching. The whole fetching should happen at once at the beginning of the query, not lazily.\r\n\r\nSo the pipeline goes something like this:\r\n\r\nGQL query -> query inspection -> our graph selection strategy -> our strategy execution -> graph object result -> GQL data fetchers simply accessing the result\r\n\r\n**Inspection phase**\r\nTo understand what to fetch in our fetching strategy, we are going through the query by using the root *DataFetchingEnvironment* and going through the *SelectedField*s coming from *DataFetchingFieldSelectionSet*s. Thus resolving all the arguments, and all the nested fields we need to fetch. \r\n\r\nThis works fine.\r\n\r\n**The issue**\r\nThe issue comes when the query contains inline fragments that contain additional fields (that we want to know about beforehand). From the above inspection, the GQL java API doesn't return such information (inline fragments are ignored, and the fields below don't get resolved), and so we don't know what to fetch.\r\n\r\nWe get that information only in the data fetcher of that field when it comes to it. But that is already late, as we want to make the whole graph fetching eager at the beginning, not lazily (based on the data fetchers of individual fields).\r\n\r\n**Example**\r\n\r\n {\r\n parent {\r\n ...on ChildA {\r\n fieldA\r\n }\r\n ...on ChildB {\r\n fieldB\r\n }\r\n }\r\n }\r\n\r\nGoing through the `env.getSelectionSet()` of that query, the fields `fieldA` and `fieldB` are nowhere to be found.\r\n\r\n**Investigation**\r\nThere is a piece of code in the GQL java which is connected to this issue:\r\n\r\n // DataFetchingFieldSelectionSetImpl.java\r\n\r\n private void traverseFields(MergedField fieldList, GraphQLFieldsContainer parentFieldType, String fieldPrefix) {\r\n\r\n FieldCollectorParameters parameters = FieldCollectorParameters.newParameters()\r\n .schema(graphQLSchema)\r\n .objectType(asObjectTypeOrNull(parentFieldType)) \u003c-------------- this is important part\r\n .fragments(fragmentsByName)\r\n .variables(variables)\r\n .build();\r\n\r\nHere the `parentFieldType` refers to the type of the `parent` field, which is, in this case, an interface. The information about the inline fragment and the type the fragment refers to is not present at this point, so the `asObjectTypeOrNull()` returns `null`. This causes the `FieldCollector` not to collect the fields of the inline fragment (`checkTypeCondition()` returns false).\r\n\r\n**Question**\r\nNow, I don't know if this is a bug or it's by design. The concrete GQL type of the inline fragment is known (childA, or childB), thus the fields should be possible to be resolved.\r\n\r\nIf it isn't a bug, how can I get the complete information about what graph structure I'm fetching before actually calling the GQL java data fetchers?\r\n\r\nNote: as I need to resolve the arguments, and variables, etc. I can't use the MergedField API to get that information (that one contains the whole tree, as in the query, but it is unresolved)","author":{"url":"https://github.com/redhead","@type":"Person","name":"redhead"},"datePublished":"2019-12-19T12:41:40Z","url":"https://github.com/graphql-java/graphql-java/issues/1718"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2cbf888c-bf9a-4b77-63da-347323d3f805 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E3A2:1DC4CC:308CD6:40CEEE:6B0190B9 |
| html-safe-nonce | 77dcf47e04d5e8d18887f9c6b06bbd9fcb9c71e25d76d3d9cdc90296df883fa4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0EyOjFEQzRDQzozMDhDRDY6NDBDRUVFOjZCMDE5MEI5IiwidmlzaXRvcl9pZCI6IjI2Mjc1ODk3Mzk5ODA2MjQwNTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0f1e32baa6ec48d549b1d7431e675f0be61586359b71fbfef8c3ef334d6acb88 |
| hovercard-subject-tag | issue:540290456 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/graphql-java/graphql-java/1718/issue_layout |
| twitter:image | https://opengraph.githubassets.com/df9d81cf24376e6087f0071947c38d945553f5b224d7e697f7390acc01961c0b/graphql-java/graphql-java/issues/1718 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/df9d81cf24376e6087f0071947c38d945553f5b224d7e697f7390acc01961c0b/graphql-java/graphql-java/issues/1718 |
| og:image:alt | I've ran into similar issue as in already reported #973 but with no information about how to go around it. Background What we are doing is that, at the beginning of query execution, we inspect the ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | redhead |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/graphql-java/graphql-java git https://github.com/graphql-java/graphql-java.git |
| octolytics-dimension-user_id | 14289921 |
| octolytics-dimension-user_login | graphql-java |
| octolytics-dimension-repository_id | 38602457 |
| octolytics-dimension-repository_nwo | graphql-java/graphql-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 38602457 |
| octolytics-dimension-repository_network_root_nwo | graphql-java/graphql-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width