Coder Social home page Coder Social logo

Validation example about juniper HOT 4 CLOSED

graphql-rust avatar graphql-rust commented on August 15, 2024
Validation example

from juniper.

Comments (4)

TheServerAsterisk avatar TheServerAsterisk commented on August 15, 2024

I can't speak on the jwt aspect due to lack of familiarity. However, to answer your question on http header validation, it would be my suggestion to implement the BeforeMiddleware trait for some struct and adding your implementation to the iron's instance chain. This way you can access the request object, validate, and need be return the appropriate response if it fails to meet your conditions before it even hits juniper.

from juniper.

mmacedoeu avatar mmacedoeu commented on August 15, 2024

I think your solution to block invalid request is good, I just need to read the docs to figure out how to block the chain for further processing. But I also have another requeriment, to write auditing fields alongside the business fields, things like remote addr, update and include username, update and include timestamp. So I still need to inject fields not coming directly from the GQL request but directly or indirectly from http request. I think need to put it first on context and get from there, but all the details I still need to read the source code as there is no docs or examples related to that. It would also be good to take already computed fields from the BeforeMiddleware trait implementation you mentioned and inject somehow into context to evict recomputation.

from juniper.

TheServerAsterisk avatar TheServerAsterisk commented on August 15, 2024

Sorry, for the late response.

I just need to read the docs to figure out how to block the chain for further processing

You mind clarifying what you mean. Typically you can deal with erroneous request in the catch function or if you don't want to further process request then sending the error along down the chain shouldn't introduce any significant overhead as it will be only the catch functions be executed and most of the time the catch function just passes the error along the chain. If you want to stop the process all together I think the answer afaik is to panic the thread which is not a great solution.

but all the details I still need to read the source code as there is no docs or examples related to that

Unfortunately, that is an iron specific thing so I am not sure if it would be wise to write examples like that as someone could just as easily leverage hyper to run this or one of the other http libraries out there, but it is up to @mhallin on how detailed the examples should be.

It would also be good to take already computed fields from the BeforeMiddleware trait implementation you mentioned and inject somehow into context to evict recomputation.

You can! When you are building the context factory see the example found here you still have access to the request object. More importantly, the context factory is leveraged as a part of the handler so you'll receive the altered request object that was worked upon in the before middleware trait.

from juniper.

theduke avatar theduke commented on August 15, 2024

@mmacedoeu I'm closing this due to inactivity.

Feel free to reopen if you have further questions.

from juniper.

Related Issues (20)

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.