-
-
Notifications
You must be signed in to change notification settings - Fork 606
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
[WIP] Investigate GraphQL for JSON introspection/filtering #7830
Conversation
Thanks for your pull request, @marler8997! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
That looks like over-engineering and re-inventing the wheel. I would generally recommend to ask for feedback on the NG or Slack before you start such big projects like this one. Except for the dmd -Xf- | jq .modules assuming we teach dmd to output the JSON on stdout if requested. OTOH I have to admit that I like |
Well I wanted to see if I could convince myself first :) The best way I saw to do that was to see what the implementation might look like. This GraphQL stuff is interesting so this is mostly just an exploration for me and I welcome others feedback along the way.
Well, I was kinda seeing if we could prevent "re-inventing" the wheel by leveraging the solutions that other engineers have already found to these problems. GraphQL gives complete freedom to any application to not only query the exact data it needs, but also to introspect on the data. With a flag like P.S. I was already planning on developing a GraphQL library, I was just using DMD as a guinea pig user of it. It helps to have one real-world application when developing a library. |
maybe add an example with field1 and field2? |
looks like superseeded by #7838 ? |
This is an optional enhancement of #7838, though, I'm leaning on the side of this being "more trouble than it's worth". |
DISCLAIMER: Note that supporting the full GraphQL spec would surely be overkill for this application. This PR is just exploring whether we could leverage a subset of GraphQL to take advantage of the solutions it provides for what we need. Also note that I'm not convinced myself whether this is a good fit for dmd, but I thought seeing if we could leverage the latest technology was worth looking into.
Seeing the new
-probe
flag being proposed (#7521) and the new data being added to the JSON file (#7757 (review)), I noticed that these use cases and more were just a subset of what you get from using graphql (http://graphql.org/). I decided to look into using a "subset" of graphql for both "filtering json output" and also supporting "introspection" on the json format. For those familair with graphql, I only plan on supporting SelectionSets with Fields (no fragments) (see http://facebook.github.io/graphql/October2016/#sec-Language.Operations). The advantage of graphql is that it will keep the JSON format specification in sync with the JSON that is generated, this being a good application of the DRY principle (see http://graphql.org/learn/schema and http://graphql.org/learn/execution for more info). Here are some examples of it's use:Here's an example of deeper filtering:
Note that for backwards compatibility, if no graphql query is given, it will default to the original format , namely, an array of objects representing the module files. However, if you want to select that data in graphql, you could do:
and get
The filtering is nice, but the main benefit of using graphql will be the introspection. You will be able to use it to query the JSON type system, to know what fields are available. I still need to learn a bit more about GraphQL to provide a good example, so I'll try to update this as I learn a bit more.