ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.27k stars 748 forks source link

HC12 gateway problem with directives, works in HC11 #4400

Closed nightroman closed 1 year ago

nightroman commented 3 years ago

Is there an existing issue for this?

Describe the bug

HC12 gateway problem with directives, works in HC11

HC12GatewayDirective.zip

Please find attached the following projects:

On starting GatewayHC12 it fails with:

HotChocolate.SchemaException: For more details look at the `Errors` property.

1. The argument `roles` value type is wrong. (HotChocolate.Types.DirectiveType)
2. The argument `tier` value type is wrong. (HotChocolate.Types.DirectiveType)
3. The argument `roles` value type is wrong. (HotChocolate.Types.DirectiveType)
4. The argument `tier` value type is wrong. (HotChocolate.Types.DirectiveType)
5. The argument `tier` value type is wrong. (HotChocolate.Types.DirectiveType)
6. The argument `tier` value type is wrong. (HotChocolate.Types.DirectiveType)
7. The argument `roles` value type is wrong. (HotChocolate.Types.DirectiveType)
8. The argument `tier` value type is wrong. (HotChocolate.Types.DirectiveType)
9. The argument `tier` value type is wrong. (HotChocolate.Types.DirectiveType)
10. The argument `roles` value type is wrong. (HotChocolate.Types.DirectiveType)
11. The argument `roles` value type is wrong. (HotChocolate.Types.DirectiveType)
12. The argument `roles` value type is wrong. (HotChocolate.Types.DirectiveType)
13. The argument `tier` value type is wrong. (HotChocolate.Types.DirectiveType)
14. The argument `tier` value type is wrong. (HotChocolate.Types.DirectiveType)
15. The argument `tier` value type is wrong. (HotChocolate.Types.DirectiveType)
16. The argument `tier` value type is wrong. (HotChocolate.Types.DirectiveType)
17. The argument `roles` value type is wrong. (HotChocolate.Types.DirectiveType)

   at HotChocolate.Configuration.TypeInitializer.EnsureNoErrors()
   at HotChocolate.Configuration.TypeInitializer.CompleteTypes()
   at HotChocolate.Configuration.TypeInitializer.Initialize(Func`1 schemaResolver, IReadOnlySchemaOptions options)
   at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types, LazySchema lazySchema)
   at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)

GatewayHC11 works fine, i.e. https://localhost:8001/graphql/ shows the schema and this dummy query

query Attributes {
  attributes {
    id
    name
    group
  }
}

is called successfully with the expected error due to the fake token in this sample.

The problematic directives:

directive @HasPlanTier(tier: PlanTier!) on FIELD_DEFINITION

enum PlanTier {
    FREE
    BASIC
    PRO
    ENTERPRISE
}

directive @BlockAll(roles: [Role!]!) on FIELD_DEFINITION
directive @RequireAny(roles: [Role!]!) on FIELD_DEFINITION

enum Role {
    DISTRIBUTOR
    CADMODELS
    INTERNAL
}

Apparently in HC12 each use of these directives causes an error.

Steps to reproduce

Please see the description and the attached projects for v11 and v12.

Relevant log output

No response

Additional Context?

No response

Product

Hot Chocolate

Version

12.1

nightroman commented 3 years ago

P.S.

(1) The downstream GraphQL service is not HotChocolate.

(2) Not sure if it is useful, some more error details from the debugger:

-       [0] {{
  "message": "The argument `roles` value type is wrong.",
  "code": "TS_ARG_VALUE_TYPE_WRONG",
  "extensions": {
    "Source": "internal_url"
  }
}}  HotChocolate.ISchemaError {HotChocolate.SchemaErrorBuilder.Error}
        Code    "TS_ARG_VALUE_TYPE_WRONG"   string
+       Exception   null    System.Exception
+       Extensions  Count = 1   System.Collections.Immutable.ImmutableDictionary<string, object>
        Message "The argument `roles` value type is wrong." string
        Path    null    System.Collections.Generic.IReadOnlyCollection<object>
+       SyntaxNodes Count = 1   System.Collections.Immutable.ImmutableList<HotChocolate.Language.ISyntaxNode>
+       TypeSystemObject    {HotChocolate.Types.DirectiveType}  HotChocolate.Types.ITypeSystemObject {HotChocolate.Types.DirectiveType}
+       Static members      
+       Non-Public members      
nightroman commented 3 years ago

Do these "problematic" custom directives have any effect in the stitched result schema? It seems all works fine if I simply remove them from the used schema snapshot. Do you think it is a possible workaround?

nightroman commented 3 years ago

A little sad this regression was rescheduled...

michaelstaib commented 3 years ago

We have a certain amount of time to invest and things get moved. It might get moved two or three more times. You can always help and fix it, its open source.

nightroman commented 3 years ago

@michaelstaib I wish I could...

On that note. I tried in the past and gave up due to the failing build.

So I've got the latest today, and ran build.ps1 as suggested. As a result, the build fails:

╬════════════
║ Compile
╬═══

NullReferenceException: Object reference not set to an instance of an object.
   at Build.<get_Compile>b__8_2(DotNetBuildSettings c) in C:\-\ChilliCream\hotchocolate\.build\Build.cs:line 66
   at Nuke.Common.Tools.DotNet.DotNetTasks.DotNetBuild(Configure`1 configurator)
   at Build.<get_Compile>b__8_1() in C:\-\ChilliCream\hotchocolate\.build\Build.cs:line 66
   at Nuke.Common.Execution.BuildExecutor.<>c.<Execute>b__4_2(Action x)
   at Nuke.Common.Utilities.Collections.EnumerableExtensions.ForEach[T](IEnumerable`1 enumerable, Action`1 action)
   at Nuke.Common.Execution.BuildExecutor.Execute(NukeBuild build, ExecutableTarget target, IReadOnlyCollection`1 previouslyExecutedTargets, Boolean failureMode)

═══════════════════════════════════════
Target             Status      Duration
───────────────────────────────────────
Restore            Succeeded       0:50
Compile            Failed        < 1sec   // NullReferenceException: Object reference not set to an instance of an object.
───────────────────────────────────────
Total                              0:50
═══════════════════════════════════════

Build failed on 2021-11-22 12:37:12. (╯°□°))╯︵︵ ┻━┻
michaelstaib commented 3 years ago

I cannot reproduce this neither on windows nor macOS, @tobias-tengler can you?

michaelstaib commented 3 years ago

try build.cmd restore instead of the full build. There seems to be an issue when doing this on a fresh windows...

The core team do all work on macOS or linux.

I will update the contribution file since the full build is not even needed on windows since the build agents run on linux as well.

the restore command will create you the All.sln which can be opened in visual studio. You will need .net6 and vscode, vs2022, rider 2021.3 EAP. For VSCode we have all the smaller solutions. I mostly use vscode but it's up to you.

michaelstaib commented 3 years ago

The contribution Guidelines are now updated: https://github.com/ChilliCream/hotchocolate/blob/main/CONTRIBUTING.md

nightroman commented 3 years ago

@michaelstaib michaelstaib assigned nightroman 44 minutes ago

Hmm. Please reassign back. My "I wish I could..." did not mean "I am taking it if I know how to build".

I will try to look at it regardless. But my commitment does not qualify for assigning for this regression.

nightroman commented 3 years ago

@michaelstaib I still cannot build the whole All.sln but fortunately I can build and run some tests in HotChocolate.Stitching.sln I will describe (today or tomorrow) what to do in one of your tests, in order to repro the bug, and all the details. The nature of why it goes the error path is beyond my familiarity with HC. This is all I can do at this moment, but it's some fair help from me.

nightroman commented 3 years ago

AboutDirectiveIssue4400.graphql.zip

Steps to reproduce in stitching tests

Copy the attached schema AboutDirectiveIssue4400.graphql to src\HotChocolate\Stitching\test\Stitching.Tests\__resources__

Open src\HotChocolate\Stitching\HotChocolate.Stitching.sln in Visual Studio

Open src/HotChocolate/Stitching/test/Stitching.Tests/Integration/RewriteTypesTests.cs Go to the test method AutoMerge_Schema. Replace the first added schema file name with with AboutDirectiveIssue4400.graphql

.AddRemoteSchemaFromString(
    "AdvisorClient",
    FileResource.Open("AboutDirectiveIssue4400.graphql"))

Set the breakpoint in src\HotChocolate\Core\src\Types\Types\DirectiveCollection.cs, line 140 (see >>>> below):

    private void ValidateArguments(ITypeCompletionContext context, Directive directive)
    {
...
                if (!arg.Type.IsInstanceOfType(argument.Value))
                {
>>>>                context.ReportError(
                        DirectiveCollection_ArgumentValueTypeIsWrong(
                            directive.Type,
                            context.Type,
                            directive.ToNode(),
                            _source,
                            arg.Name));
                }
            }
...

Start the test AutoMerge_Schema with debugging. The break point is triggered before throwing the error. The condition causing the error (false) is due to the following values:

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

nightroman commented 2 years ago

Dear stale bot, could you please fix this? v12.8.2 shows the same issue.

RobAltium commented 2 years ago

🤣


Rob Barton @.***

On Wed, 4 May 2022, 12:31 Roman Kuzmin, @.***> wrote:

Dear stale bot, could you please fix this? v12.8.2 shows the same issue.

— Reply to this email directly, view it on GitHub https://github.com/ChilliCream/hotchocolate/issues/4400#issuecomment-1117203765, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASA7PMGENGXFZYSSLTD6UDTVIJN2NANCNFSM5HXAAXGA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

michaelstaib commented 1 year ago

HotChocolate.Stitching is now in legacy mode and is replaced by HotChocolate.Fusion. I am closing this issue as we essentially froze the fusion code.

You can join the preview of Hot Chocolate Fusion now on Slack