Comments (1)
Hi @alefbragin - thanks for the feature request.
Unfortunately doing this for enums would be somewhere between difficult and impossible. Enums are more complicated than scalars. For scalars cynic simply needs to know the type, but for enums we need to care about all the variants, possible fallbacks, renames and maybe other things I'm forgetting about.
Given the schema and some type names it would probably be possible to generate a cynic::Enum
impl - but it'd have to make some assumptions about the shape of your actual enum. And if that impl was wrong in any way the compiler errors probably wouldn't be that nice - there's just not enough info in impl_enum!("my-schema", MyEnum, schema::MyEnum)
that we could use to attach errors to.
And the final problem is the orphan rule - impl_scalar
uses some tricks (specifically this generic parameter on IsScalar
) to work around the orphan rule - usually you wouldn't be able to implement a 3rd party trait on a 3rd party type like it does. The Enum
trait does not have an equivalent parameter, so the orphan rule starts to apply again.
The generic parameter on IsScalar
adds a bit of annoying complexity to cynic. I think it's worthwhile for scalars, because by their nature they tend to be defined in different crates. But I'm not so sure for enums - particularly given the limitations I outlined above.
If re-arranging your crates isn't possible or desired at the moment (which is fair enough) I'd recommend just having two enums and providing some From
impls to easily convert between the two.
There might be some other way I can help cater to this use case in cynic, but I don't know what it is right now. I'll keep this issue open for now to think about it.
from cynic.
Related Issues (20)
- Action Required: Fix Renovate Configuration
- How exactly to build wrapper libraries? HOT 2
- Optionally include GraphQL Query / Mutation in `querygen` output
- invalid type: integer ..., expected a string HOT 7
- Generator fails to handle a fragment
- GraphQL over HTTP compliance
- Could not find a type named [type] in the schema HOT 5
- `querygen-web` generates wrong `arguments` attribute input
- Serialize queries into GraphQL HOT 1
- Trait Bound not satisfied HOT 7
- Breaking API Cleanup
- Extra empty list item in GraphQL output HOT 1
- `cynic-querygen` ignores fragment names HOT 9
- Parsing extensions contained in response HOT 1
- Generator gets variables required-ness wrong
- Next Release? HOT 2
- Omit null values in query variables HOT 7
- `Iter` & `IdRange` + `Copy` concerns
- `generator.cynic-rs.dev` blank site HOT 4
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 cynic.