- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 68
Add missing instances (Decode, Encode) #479
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
Add missing instances (Decode, Encode) #479
Conversation
| instance Decode a => Decode (NonEmpty.NonEmpty a) where | ||
| decode = withRefinedList (maybe (Left "Expected a NonEmpty list") Right . NonEmpty.nonEmpty) decode | ||
|  | ||
| -- | Should this instance dedupe silently or fail on dupes ? | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, it's more coherent with the other behaviors (i.e. non empty)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or directive @Uniq will validate duplicates. and with assumption that there are no dups, decode will dedupe silently.
what do you think?
| with this way Graphql client can't distinguish difference between set, non-empty and regular list. that why may it will be better approach to add them directives? for example:  data MyInput = MyInput {  
    list1 :: NonEmpty Int,
    list2 :: Set Int,
    list3 :: [int] 
 }that can be represented as: directive @NonEmty () on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @Uniq () on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
input MyInput {  
    list1: [Int!]! @NonEmpty
    list2: [Int!]! @Uniq
    list3: [int!]! 
 } | 
| you can define custom directives at  to assign dirctives to fields see: 
 | 
| 
 Yeah that's a really good idea ! I was annoyed by the missing differences on the client too ! | 
| no. introspection does not render directives. so. we can't assign them directives. :( | 
| only way would be: data MyInput = MyInput {  
    list1 :: NonEmpty Int,
    list2 :: Set Int,
    list3 :: [int] 
 }to wrapp and generate custom types for them: input InputNonEmpty_Int {
   elems : [Int!]!
}
input InputSet_Int {
   elems : [Int!]!
}
input MyInput {  
    list1: InputNonEmpty_Int
    list2: InputSet_Int
    list3: [int!]! 
 }is kind a too verbose but, what we can do? | 
| Is it explicitly out of the introspection query or is it just "not mentioned" in the spec ? (I didn't find any reference to schema directives presence or absence in the introspection query). 
 At least that's the only options I see, for input types. Personally, I'm ok with 2, 3, 4 options and like 3 and 4 better. | 
| for custom specifications compatibility problems with all graphql clients may occur. but i still think that, GraphQL should support this datatypes some way (for both  one solution can be  # is kind of wrapper
# rights side can of "=" :
#   - only can  appear wrapper types (like lists and custom wrappers)
#   - wrapper "!" is not allowed. e.g [a!] is invalid
wrapper NonEmpty a = [a]
wrapper Set a = [a]
wrapper Pair a b = [a, b]
wrapper Map a b = [Pair a b]wrapper NonEmpty a =  [a]
wrapper Set a = [a]
input MyInput {
  list1: (NonEmpty Int!)!
  list2: (Set Int!)!
  list3: [int!]!
  map: (Map String! Int!)!
}
type MyOutput {
  list1: (NonEmpty Int!)!
  list2: (Set Int!)!
  list3: [int!]!
  map: (Map String! Int!)!
}we can formalize it . and make a proposal as an issue for it on: https://github.com/graphql/graphql-spec/issues | 
| @theobat what do you think? | 
| server must define serialization methods for wrappers. haskell class Wrapper wrapper  where
    fromList :: [a] -> Either String (wrapper a)
    toList ::  wrapper a -> [a]
instance Wrapper NonEmpty where
   fromList x = ...
   toList x = js const fromList = xs => {}
const toList = nonempty => [....]
const resolverMap = {
  NonEmpty: new GraphQLWrapperType({
    name: 'NonEmpty',
    description: 'NonEmpty list',
    parseValue: fromList,
    serialize: toList,
  })
} | 
| Yeah it feels like the right way to do it, besides the main graphql implementation is in javascript and they already have added Set so, it feels like the way to go. | 
| So let's work on the proposal to graphql then, cause it seems like the way to go. | 
| For the record, I'm working on this: I think it would be interesting to reach people at https://github.com/hasura/graphql-engine, https://github.com/graphql-java/graphql-java, https://github.com/sangria-graphql/sangria and maybe even https://github.com/graphql-rust/juniper, to get more leverage; but let's waait for a better version of the proposal (in particular I'd like to tackle the actual spec changes before submitting and requesting comments). | 
| @nalchevanidze I'd like your review on my draft proposal when you have time. If you find it OK, I'll probably talk about the idea in other graphql libraries before submitting it to the graphql-spec process. | 
| @theobat can you merge your version with my draft. | 
| @nalchevanidze I think we should do the server-side only (simple Encode, Decode like lists) for  That is to say, I don't think calling a list [Person] or Vector Person on the client really important introspection wise, they behave the same... (but maybe that's just me though). | 
| @theobat for now we can just add missing instances without waiting of proposal  | 
| Right, I'm going to rebase and clean this | 
0a31453    to
    bb2bbf0      
    Compare
  
    cc0c62d    to
    39f1ff3      
    Compare
  
    | @nalchevanidze, This should be ready now ! | 
| @theobat hi thanks, sorry for late response. could you update changelog too? | 
| Hi yeah sure, I guess I should add a test too | 
| i approved. you don't have to, but would be great if you would. you can add them in different merge request. | 
No description provided.