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

Field middleware not working for introspection fields #853

Closed
mIkhail-zaretsky opened this issue Jun 19, 2019 · 4 comments · Fixed by #962
Closed

Field middleware not working for introspection fields #853

mIkhail-zaretsky opened this issue Jun 19, 2019 · 4 comments · Fixed by #962
Assignees
Milestone

Comments

@mIkhail-zaretsky
Copy link

Describe the bug
Field middleware is not executing for introspection fields

To Reproduce
Steps to reproduce the behavior:

  1. Please check [WIP] DO NOT MERGE! Just for introduce how to reproduce disregard of introspection query by middleware caller #852
  2. Data for introspection field is not touched

Expected behavior
Middleware should work for all fields. As an option, could you please suggest how I can distinguish introspection query and add additional logic for it.

Desktop (please complete the following information):

  • OS: Windows 10
  • Version 9.0.4
@michaelstaib michaelstaib added the ❓ question This issue is a question about feature of Hot Chocolate. label Jun 19, 2019
@michaelstaib
Copy link
Member

Sorry for the wait ... will tell you how this works tomorrow.

@michaelstaib michaelstaib self-assigned this Jun 19, 2019
@mIkhail-zaretsky
Copy link
Author

@michaelstaib , sorry for disturbing you, but could you please point me to the right place where I can add additional security check (special scope) for introspection query?
Thanks in advance

@michaelstaib
Copy link
Member

Hi, sorry for letting that hang so long. When we designed hc we did on purpose exclude middlewares from introspection resolvers since by adding transformations you could make your server non-spec compliant.

Reflecting on that we could opt to allow this with an additional schema option. I will move this to the next release.

@michaelstaib michaelstaib added this to the 10.0.0 milestone Jul 26, 2019
@michaelstaib michaelstaib added enhancement and removed ❓ question This issue is a question about feature of Hot Chocolate. labels Jul 26, 2019
@michaelstaib
Copy link
Member

OK, this one is supported with 9.1 preview 44

[Fact]
        public async Task FieldMiddlewareHasAnEffectOnIntrospectIfSwitchedOn()
        {
            // arrange
            string query = "{ __typename a }";

            ISchema schema = SchemaBuilder.New()
                .AddQueryType<Query>()
                .Use(next => async context =>
                {
                    await next.Invoke(context);

                    if (context.Result is string s)
                    {
                        context.Result = s.ToUpperInvariant();
                    }
                })
                .ModifyOptions(o =>
                    o.FieldMiddleware = FieldMiddlewareApplication.AllFields)
                .Create();

            IQueryExecutor executor = schema.MakeExecutable();

            // act
            IExecutionResult result = await executor.ExecuteAsync(query);

            // assert
            Assert.Empty(result.Errors);
            result.MatchSnapshot();
        }

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

Successfully merging a pull request may close this issue.

2 participants