Skip to content
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

Think about custom scalars that aren't strings #9

Closed
tomhoule opened this issue Jun 20, 2018 · 7 comments
Closed

Think about custom scalars that aren't strings #9

tomhoule opened this issue Jun 20, 2018 · 7 comments
Labels
help wanted Extra attention is needed
Milestone

Comments

@tomhoule
Copy link
Member

I am not clear on whether the spec allows that.

@tomhoule
Copy link
Member Author

After a new reading it seems that yes, it is allowed (it just says that custom scalars should have a string representation, presumably for allowing embedding them into JSON).

What is the best way to allow for maximum flexibility there?

If we have a custom scalar called Bytes, we could generate type Bytes = Vec<u8>; (with an annotation on the struct to say what Bytes corresponds to).

I think it would probably be better to leave that out, and allow users to inject use statements inside the generated module directly, that way you would define your Bytes (or Date, for example) scalar in another module, and inject an import for it. This seems more flexible.

@tomhoule tomhoule added the help wanted Extra attention is needed label Jun 23, 2018
@tomhoule tomhoule added this to the 0.2 milestone Jun 23, 2018
@tomhoule
Copy link
Member Author

@tomhoule
Copy link
Member Author

tomhoule commented Jul 2, 2018

apollo-codegen has that

  --passthroughCustomScalars                 Use your own types for custom scalars

https://github.com/apollographql/apollo-cli

@xtian
Copy link

xtian commented Jul 17, 2018

There is also an RFC to allow the serialization type of a custom scalar to be defined: graphql/graphql-spec#326

@tomhoule
Copy link
Member Author

We should definitely support that when it makes it into the spec, thanks for the link!

@tomhoule tomhoule modified the milestones: 0.2, 0.3 Jul 22, 2018
@tomhoule
Copy link
Member Author

tomhoule commented Aug 5, 2018

Custom target types for custom scalars are implemented in #74

@tomhoule
Copy link
Member Author

tomhoule commented Aug 6, 2018

This is implemented, let's move the discussion on the RFC to #75

@tomhoule tomhoule closed this as completed Aug 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants