Giter Club home page Giter Club logo

Comments (11)

jonnydgreen avatar jonnydgreen commented on July 29, 2024 1

Sure thing, I'll have a look later tonight!

from validation.

mcollina avatar mcollina commented on July 29, 2024

Definitely!

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

from validation.

ramonmulia avatar ramonmulia commented on July 29, 2024

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.

mcollina avatar mcollina commented on July 29, 2024

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.

simoneb avatar simoneb commented on July 29, 2024

@ramonmulia what's the status of the work on this issue?

from validation.

ramonmulia avatar ramonmulia commented on July 29, 2024

I didn't have time to back on this.

from validation.

jonnydgreen avatar jonnydgreen commented on July 29, 2024

@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.

ramonmulia avatar ramonmulia commented on July 29, 2024

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.

jonnydgreen avatar jonnydgreen commented on July 29, 2024

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.

ramonmulia avatar ramonmulia commented on July 29, 2024

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.

jonnydgreen avatar jonnydgreen commented on July 29, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.