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

Validation using custom scalar types #2

Open
audiBookning opened this issue Nov 20, 2018 · 2 comments
Open

Validation using custom scalar types #2

audiBookning opened this issue Nov 20, 2018 · 2 comments
Labels
discussion General subject discussion

Comments

@audiBookning
Copy link

From your video MERN Stack & GraphQL - #7 Server-Side Validation, it seems that you don't approach the subject of using custom scalar types for validation.

There are already several packages that use that idea:

What are your thought about it?

@alex996
Copy link
Owner

alex996 commented Nov 22, 2018

@audiBookning Sounds interesting, I didn't think about it. I like graphql-custom-types but I'm not sure if it plays nicely with Apollo. I'd wait to see if this pattern gets a wider adoption.

@audiBookning
Copy link
Author

audiBookning commented Nov 22, 2018

Thanks for the reply.

but I'm not sure if it plays nicely with Apollo.

I looked for your feedback, because i don't really see Custom Scalar types being used or mentioned very much. Which is strange given that the specs of graphql already have this feature since at least 2015: facebook.github.io Scalars, more info also at graphql.org Scalar types

and also from what i can see, they are already implemented on Apollo Server 2 since the beginning: apollographql.com Custom scalars

The problem that could arise would be with Apollo Client. There is a rich issue about the matter: Support for custom scalars and its follow up from the apollo-feature-requests repo
TL;DR from Apollo site:
'...Note that Apollo Client does not currently have a way to automatically interpret custom scalars, so there’s no way to automatically reverse the serialization on the client...'
I haven't tried yet, but it does makes one wonder nonetheless...

I like graphql-custom-types

The packages are nice, but one doesn't really need to be dependent of them. One could transpose your code used for validation with the Joi package to one's own GraphQLScalarType instance easily: apollographql.com Custom GraphQLScalarType instance. In particular see the Date as a scalar example.

I'd wait to see if this pattern gets a wider adoption.

Your doubts are likely similar to mine. But from what i gleaned, i does look like this should be the best practice to do validation (and much more) with Graphql on the server. There must be others considerations that i don't see at the moment...

@alex996 alex996 added the discussion General subject discussion label Nov 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion General subject discussion
Projects
None yet
Development

No branches or pull requests

2 participants