Comments (6)
Ah, querying a database where you want to SELECT *
does make sense. That plus the test use case seems like enough reason to add this feature, albeit still probably with some warnings. Limiting depth, maybe as __all(depth: Int)
seems like a great mechanism, not sure why I didn't think of that!
from genqlient.
Another issue to think about here is it's not obvious what __all
would expand to for non-leaf fields. For example suppose you have
type Query { a: A }
type A { b: B }
type B { a: A }
query { a { __all } }
We can't expand all fields recursively, because it would go on forever! Do we just never expand non-leaf fields? Do we expand everything we can do without circular references?
from genqlient.
@benjaminjkraft That will be a really nice feature. There is a case in generating all the fields with __all
that makes absolute sense. I can give you an example. I already have a graphql server generated with the 99designs generator. The filtering and the fields are already being handled by this server based on what the user requests. From the server side, we need to reach out to the database using graphql as well, but instead, we need to take the whole object in order to control the response to the user.
from genqlient.
Also, you will need to implement a way to control the depth of the fields. Otherwise, this can end up in an endless loop for the reversed fields.
from genqlient.
I wrote a quick POC on benkraft.__all
, implementing this for depth: 1
only, without real error handling or documentation, and with some other limitations. (You can see a sample of the syntax and what it expands to in the tests.) It looks like it should be plenty doable, maybe later this weekend I'll have some time to finish it off. The only significant question I ran into so far is what to do about fields with required arguments: maybe just skip them just as we skip non-leaf fields (with depth 1 that is).
One question about depth is: is it going to be enough? What if you want to fetch, say, all leaf fields plus field { id }
for non-leaf fields? I guess you can manually enumerate the non-leaf fields, or eventually we could support something like __all { id }
that expands to include all fields with a child field id
(although that would be a bit more work).
from genqlient.
I think it would be better to start by supporting only _all
with depth and then if it is needed, non-leaf fields can be supported as well. But the POC looks super OK.
from genqlient.
Related Issues (20)
- config option `optional` is not validated HOT 1
- Add Go 1.20 to tests
- Drop Go <1.18 HOT 3
- Global omitempty option HOT 12
- Make it easier to integration test config options
- Premarshal struct does not maintain JSON tags (omitempty) HOT 6
- Handling enums with strings that have variations of character casing HOT 2
- genqlient: command not found HOT 2
- [Meta] Document and improve support for Hasura & Dgraph schemas HOT 7
- Nullable list in optional pointer mode generates non-pointer slice HOT 2
- invalid character '<' looking for beginning of value HOT 4
- Inline fragments not working with `use_struct_references: true` and `pointer: optional` HOT 4
- codegen error: 'data' redeclared in this block HOT 1
- Split `TestGenerateWithConfig` cases
- Binding to a type in the same package as generated code produces invalid output HOT 4
- Cannot use Go keywords as variable names in mutation. HOT 1
- panic: runtime error: invalid memory address -- generate.go:403 HOT 4
- `# @genqlient(for: "Input.nonOptionalField", omitempty: false)` not working HOT 4
- Test that all snapshots are used
- Is there a way to access the raw http response? HOT 2
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 genqlient.