Comments (12)
Just realised that the UserContext is added to the ContextData of the validator before it's executed. This offers a way in to resolve services off that, inside custom validator functions. Maybe that's enough for now.
from graphql.validation.
my understanding of how fluentvalidation worked is that it is expensive to spin up validator instances. so they should be spun up and cached, and use the context to run diff scnarios.
from graphql.validation.
Yea I'm not too sure on that tbh. Looking at ASP.NET Core MVC setup here it seems a ServiceProviderValidatorFacrory resolves validators after they're registered from assemblies using extensions in here with the default Transient lifetime.
So I guess if that's the default it can't be too expensive.
from graphql.validation.
Since DI in Graph is already kinda weird, happy to ignore this for now and rely on the UserContext being in the validation context. Perhaps we could document it though. Lemme know what you wanna do.
from graphql.validation.
@benmccallum does v3 of graphql change this at all?
from graphql.validation.
There's been some developments over there around DI, but I haven't been keeping up. I don't know if it would change anything here though. Do you have any notes you could share @sungam3r?
from graphql.validation.
graphql-dotnet/graphql-dotnet#1160 was closed in favor of https://github.com/sungam3r/SteroidsDI . I did not watch this repository yet. Does this project need any DI support from graphql-dotnet?
from graphql.validation.
Essentially this project uses Activator.CreateInstance
to init a bunch of validators up front, and as such, they're singleton. I was keen to make them transient (like FluentValidation does by default) and then have them init as required, but hadn't got too far into the plumbing yet.
from graphql.validation.
@benmccallum does v3 of graphql change this at all?
@benmccallum @SimonCropp Yes, in fact, we really made one change that will make it easy to add DI support. Schema
now explicitly implements IServiceProvider
. See #111.
from graphql.validation.
@benmccallum Could you check if this design suits you?
from graphql.validation.
Ah sorry, didn't realise you'd done a PR, nice! Taking a look now.
from graphql.validation.
Done.
from graphql.validation.
Related Issues (15)
- Add FluentValidationExtensions.AddCacheToContext to make unit testing easier
- Make ArgumentValidation public HOT 4
- Extension methods off IResolveFieldContext now HOT 5
- Clarify the term "Validation" HOT 1
- Fix GraphQL version to match NuGet versions HOT 2
- Dont work validation for different names. HOT 1
- How i can change exceptions. HOT 4
- UseFluentValidation now also required on Schema instance
- Update to AspNetCore 6
- Validation not firing HOT 5
- Validation on non-object argument types HOT 3
- Unable to resolve the Validator HOT 2
- Make ArgumentValidation public for manual calling HOT 7
- Remove redundant resolvers
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 graphql.validation.