Git Product home page Git Product logo

Comments (12)

benmccallum avatar benmccallum commented on September 6, 2024

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.

SimonCropp avatar SimonCropp commented on September 6, 2024

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.

benmccallum avatar benmccallum commented on September 6, 2024

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.

benmccallum avatar benmccallum commented on September 6, 2024

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.

SimonCropp avatar SimonCropp commented on September 6, 2024

@benmccallum does v3 of graphql change this at all?

from graphql.validation.

benmccallum avatar benmccallum commented on September 6, 2024

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.

sungam3r avatar sungam3r commented on September 6, 2024

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.

benmccallum avatar benmccallum commented on September 6, 2024

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.

sungam3r avatar sungam3r commented on September 6, 2024

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

sungam3r avatar sungam3r commented on September 6, 2024

@benmccallum Could you check if this design suits you?

from graphql.validation.

benmccallum avatar benmccallum commented on September 6, 2024

Ah sorry, didn't realise you'd done a PR, nice! Taking a look now.

from graphql.validation.

benmccallum avatar benmccallum commented on September 6, 2024

Done.

from graphql.validation.

Related Issues (15)

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.