This repository was archived by the owner on Oct 2, 2024. It is now read-only.
Replies: 2 comments 2 replies
-
Giving access to this fields will miss lead the user and could lead to long lasting debug. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Currently I can break my query on to fragments and refer to them in classes. I can pass the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Proposal
This proposal aims to facilitate the use of generated code and enhance it with nnbd (non-nullable by default), available since Dart 2.9.
Problem
Currently,
simple
/pathedWithFields
naming schemes:simple
generates easier to read code (smaller classes names) which will clash if the same class happen to be used in more than one place of the query (with different selection sets)[1.a], whilepathedWithFields
will not clash, but the generated classes won't be compatible[1.b], unless generated with fragments[2.a];!
[3];[1] Example:
[1.a] `simple` output:
[1.b] `pathedWithFields` output:
[2] Example:
`pathedWithFields` + fragment output:
[3] Example:
We also talk a lot about "canonicality" (i.e. Any Dart type generation with a 1:1 relationship with its GraphQL counterpart, where every field and property of canonical types should be applied into the class generation). In theory scalars, enums and input objects, as input values, are canonical. Also, query fragments can also be generated canonically.
It would be better to have objects classes also generated canonically, so users wouldn't have to use fragments or depend on class deduplication to have two or more entries of the same class compatible. However, if objects would've been generated as canonical, they'd include all GraphQL fields, even thought the query wouldn't select them.
Solution
The proposed solution aims to generate code based on canonical classes, mapping selection sets generically, and making them accessible via a
$
shorthand. By doing this, we minimize breaking changes (as the "default" getter would still be valid, although nullable) and we won't need to deal with naming schemes anymore.GraphQL schema:
GraphQL query:
Suggested generated file (without ArtemisClient query/helpers). Keep in mind this code was done manually and is prone to typos and/or errors:
Drawbacks
Business
instead ofBusiness<_Business_SelectionSet_Query$Blah>
and the generic type would be lost. We could remove the_
making SelectionSets public, which wouldn't help with the long-naming problem.fieldName$FieldType
getter (and so we can still avoid leaking/exposing the generated SelectionSet classes).Beta Was this translation helpful? Give feedback.
All reactions