Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If I change anything on userContext from FieldsMiddleware or IValidationRule the change is not available in resolver. #729

Closed
john1452 opened this issue Jul 6, 2018 · 1 comment

Comments

@john1452
Copy link

john1452 commented Jul 6, 2018

Hi I am trying to experiment something for this i am trying to
change a value on the user context from within FieldMiddleware (tried ValidationRule as well).
But the changed value is not available inside the resolver.

I have prepared a small sample project to demonstrate the problem.
Startup class

public void ConfigureServices(IServiceCollection services)
        {           
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddScoped<IFooService, FooService>();        
            services.AddSingleton<IDocumentExecuter, DocumentExecuter>();      
            services.AddSingleton<UserType>();
            services.AddSingleton<GraphQlQuery>();
            var sp = services.BuildServiceProvider();
            services.AddSingleton<ISchema>(new GraphQlSchema(new FuncDependencyResolver(type => sp.GetService(type))));
        }

GraphQlController - I am setting the _fooService on the userContext. From within the fieldmiddleware, I want to update the two properties of the fooService.

 var executionOptions = new ExecutionOptions
            {
                Schema = _schema,
                Query = param.Query,
                Inputs = inputs,
                UserContext = _fooService,           
            };

FieldsMiddlewareTest

public Task<object> Resolve(
            ResolveFieldContext context,
            FieldMiddlewareDelegate next)
        {
            var fooService = (IFooService)context.UserContext;
            if (fooService != null)
            {
                fooService.GivenName = "InstrumentFieldsMiddleware-GivenName";
                fooService.FamimlyName = "InstrumentFieldsMiddleware-FamilyName";
            }
            return next(context);
        }

GraphQlQuery - Inside my resolver. I am trying to use the values that I have updated in the fieldmiddleware. But the value FamimlyName and givenName remain null. For some reason the middleware changes are not available in the resolver.

 public class GraphQlQuery : ObjectGraphType
    {
        public GraphQlQuery(IFooService fooService)
        {
            Field<UserType>("users",
                resolve: context =>
                {                    
                    return new User() { FamilyName = fooService.FamimlyName??"QueryFamilyName", GivenName = fooService.GivenName??"QueryGivenName" };
                });
        }
    }

@john1452
Copy link
Author

john1452 commented Jul 8, 2018

Closing - See referenced issue.

@john1452 john1452 closed this as completed Jul 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant