Comments (11)
Sure thing, I'll have a look later tonight!
from validation.
Definitely!
Would you like to send a Pull Request to address this issue? Remember to add unit tests.
from validation.
I believe to add custom scalar inferring types in inferJSONSchemaType it would need to re-think the way it is building the argument schema in json-schema-validator
https://github.com/mercurius-js/validation/blob/main/lib/validators/json-schema-validator.js#L104.
I found a library graphql-2-json-schema that could be used to transform GraphQL schema into jsonSchema instead of looping schema type in json-schema-validator
, but still, it needs to include the validation in jsonSchema generated and change the way it is generating the final jsonSchema, so I'm not sure if it is a good idea.
There are some grahql scalar types that are not included in inferJSONSchemaType like GraphQLID
and GraphQLBoolean
but for custom ones I believe it will need to define a definitions
property in jsonSchema where are all the references to be used into jsonSchema.
do you guys have another idea to deal with this issue?
from validation.
I believe to add custom scalar inferring types in inferJSONSchemaType it would need to re-think the way it is building the argument schema in json-schema-validator https://github.com/mercurius-js/validation/blob/main/lib/validators/json-schema-validator.js#L104.
How would you do that?
I found a library graphql-2-json-schema that could be used to transform GraphQL schema into jsonSchema instead of looping in each schema type in json-schema-validator but still needs to include the validation in the jsonSchema generated and change the way it is generating the final jsonSchema so I'm not sure if it is a good idea.
I don't think such a library is useful here. It looks like a different library.
There are some grahql scalar types that is not included in inferJSONSchemaType like GraphQLID and GraphQLBoolean but for custom ones I believe it will need to define a definitions property in jsonSchema where are all the references to be used into jsonSchema.
I don't think so. You can define the custom parameter every time.
from validation.
@ramonmulia what's the status of the work on this issue?
from validation.
I didn't have time to back on this.
from validation.
@ramonmulia @sooxt98 would you still be interested in submitting a PR to address this? I'm very happy to help out if needed :)
from validation.
hey @jonnydgreen sure! I wrote my findings on top, but I believe I missed something, could you give me some input about this issue?
from validation.
Hey @ramonmulia have you got an API and associated use-case(s) in mind for this change? This is a good place to start as the solution may change depending on this. Once this is all good, we can iterate on the implementation in a draft PR :)
I believe to add custom scalar inferring types in inferJSONSchemaType it would need to re-think the way it is building the argument schema in json-schema-validator https://github.com/mercurius-js/validation/blob/main/lib/validators/json-schema-validator.js#L104.
Could you provide more details about what you meant by this?
from validation.
hey @jonnydgreen , the function we use to infer JSONSchema is this one:
function inferJSONSchemaType (type, isNonNull) {
if (type === GraphQLString) {
return isNonNull ? { type: 'string' } : { type: ['string', 'null'] }
}
if (type === GraphQLInt) {
return isNonNull ? { type: 'integer' } : { type: ['integer', 'null'] }
}
if (type === GraphQLFloat) {
return isNonNull ? { type: 'number' } : { type: ['number', 'null'] }
}
return {}
}
to add custom types in JSONSchema we need to have a definition
level that will be used as type reference $ref
.
currently this is not current behavior, for custom types they will end up with type: 'object'
in JSONSchema.
So, maybe instead of using the function to build the JSONSchema https://github.com/mercurius-js/validation/blob/main/lib/validators/json-schema-validator.js?rgh-link-date=2022-03-18T11%3A13%3A43Z#L13
it could use this library graphql-2-json-schema to transform a graphqlSchema in JSONSchema and with it in hands we can apply the validation schema on it.
from validation.
@ramonmulia thanks for the clarification about what you meant. By custom types, I presume you mean custom scalar types?
I don't think we need to replace with this library, we just need to adjust the code to add this support. Feel free to start a draft PR for this!
It's also worth noting that, per the title, this issue is also about making the inferJSONSchemaType
customisable through the plugin options
from validation.
Related Issues (9)
- Basic implementation HOT 10
- mercurius-validation doesn't support nullable type correctly HOT 3
- Validation stop working if extendSchema is called. HOT 5
- Validation failures from constraints result in a 500 status code rather than a 400 status code HOT 4
- Array or null validation error HOT 4
- Not compatible with mercurius 12.0.0 HOT 2
- Add example using @constraint in the README HOT 1
- Mercurius-codegen throw error: error TS2304: Cannot find name '_Service'. 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 validation.