Comments (2)
Hey @Hazelfire, thanks for the discussion. I see what you're saying there, that's an interesting point.
I think you're right that the selectFromCourse
type signature would be one way to support that.
Another idea, though a much more drastic change, would be to use Records as the Phantom Types. So taking this example from the Star Wars API example, since I'm looking at this source code in the examples folder for this one:
elm-graphql/examples/src/Swapi/Object/Human.elm
Lines 60 to 64 in 8dcf2b4
elm-graphql/examples/src/Swapi/Interface/Character.elm
Lines 81 to 85 in 8dcf2b4
elm-graphql/examples/src/Swapi/Query.elm
Lines 72 to 85 in 8dcf2b4
What if it was something like this:
-- in Swapi.Interface.Character
name : SelectionSet String { objectHuman : () }
name =
Object.selectionForField "String" "name" [] Decode.string
-- in Swapi.Interface.Character
name : SelectionSet String { interfaceCharacter : (), objectHuman : (), objectDroid : () }
name =
Object.selectionForField "String" "name" [] Decode.string
hero :
(HeroOptionalArguments -> HeroOptionalArguments)
-> SelectionSet decodesTo { character | interfaceCharacter : () }
-> SelectionSet decodesTo RootQuery
This would allow you to have
Benefits of Record Approach
This is lightweight in a few ways.
- You can intermix things that need the
name
field as part of aCharacter
interface, or as part of one of its Object implementors (Droid
orHuman
) - No import needed for the named types (
Swapi.Interface.Character
, etc.) - they are just records now, so they're structurally typed rather than nominally typed
Downsides of Record Approach
- Is it more cumbersome or confusing to have these records rather than named types?
- More type variables in a few places. Could that be confusing for some users? Could that be cumbersome at all in any cases even for users who are familiar with that technique?
- In an API with a ton of types, this could become unwieldy. For example, the
Node
type in GitHub has almost 80 different implementors:elm-graphql/examples/src/Github/Interface/Node.elm
Lines 23 to 102 in 8dcf2b4
Thoughts
Anyway, just throwing an idea out there, still need to think on it a little to decide if it's good or not. But seems like it might be worth considering that direction more seriously.
from elm-graphql.
I've come back to this several times, trying to understand what you mean and how it could be implemented.
The fact that I still don't understand it is a bit of a concern.
I think I get the general idea, but I do think that it might be a bit too on the nose of what's possible, and a much simpler implementation with much more obvious ways to do this might be preferable, at least in my eyes.
from elm-graphql.
Related Issues (20)
- Enhancement - Add support for Dgraph HOT 1
- non null list of non null list ofโฆ HOT 6
- Include an exhaustive query for each type HOT 3
- elm-graphql generation fails if there are no columns selected (Hasura) HOT 6
- Add operationName to mutation request body HOT 1
- Enum with underscore as a leading character, changed after generating elm code. HOT 1
- Scalar decoder fails when the field contains an object. HOT 1
- Scalars should not be encoded as json in mutations HOT 3
- Enforce nonempty list in required list arguments HOT 3
- Corrupt package data for 5.0.5? HOT 1
- Requesting feedback on the following changes to the serializeChildren function regarding field hashing HOT 2
- Can not find ScalarCodecs HOT 1
- Feature request: Convenience functions for primitive comparisons HOT 3
- Idea: serialize invalid JSON Input Values as arguments
- Missing fragment in Interface `Fragments` type HOT 1
- Idea: include deprecation warnings into the generated code as comments HOT 1
- Building large queries takes a long time and pauses the UI HOT 2
- Encode function for enums is missing HOT 1
- Generate input object helpers HOT 1
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 elm-graphql.