graphql-platform: Stitching variables can't be referenced when a query requires an object parameter

Describe the bug The documentation for schema stitching shows it’s possible to reference resolver variables in the path using a special syntax.

extend type Query {
  me: User! @delegate(schema: "users", path: "user(id: $contextData:UserId)")
}

However when trying to access a resolver variable as an object property HotChocolate will throw a SyntaxException: ‘Unexpexcted token: $.’

extend type Query {
  me: User! @delegate(schema: "users", path: "user(where: { id: $contextData:UserId })")
}

To Reproduce Modify the schema stitching example as above to reference a resolver variable within an object rather than a top level parameter and attempt to run the query.

Expected behavior The query should be parsed without an exception and the resolver variable should be included in the request.

Desktop (please complete the following information):

  • OS: Windows 10
  • Hot Chocolate 10.4.3 (also 11 preview 129)

Additional context Stepping through using the PDBs it looks like there would need to be a way to extend/inject the handling of $ variables from HotChocolate.Stitching.Delegation.SelectionPathParser.ParseValueLiteral in to HotChocolate.Parser.ParseValueLiteral as when Parser.ParseValueLiteral calls ParseObject it no longer calls through SelectionPathParser.ParseValueLiteral to have the chance to process stitching variables.

A hacky way to handle it could be to catch the Syntax Exception within SelectionPathParser.ParseValueLiteral and then re-attempt to handle the $ variable there.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 10
  • Comments: 21 (11 by maintainers)

Most upvoted comments

This is unfortunately a deal breaker for me from using this library. I believe it is generally encouraged to use objects for query parameters for flexibility. In my case, for instance, I have:

public class Query
{
    public Order[] GetOrdersByUser(GetOrdersByUserInput input) { ... }
}

public record GetOrdersByUserInput(string userId, string orderType);

Then for my stitching:

extend type User {
    orders(type: String!): [Order] @delegate(path: "orderByUser(input: { userId: $fields:id orderType: $arguments:type })")
}

This seems reasonable to have. But that produces the error described.

Has there been any additional findings with this issue? I’m experiencing the same thing, but not with the query, but when extending a type. Just wanted to check since this is a pretty important piece of functionality when stitching.

Example code below

extend type Request { PersonInformation: [PersonInformation] @delegate(schema: "employeeProfile", path: "personInformations(where: {id: {eq: $fields:employeeProfileId}})") }

Error: "extensions": { "message": "Unexpected token: $.", "stackTrace": " at HotChocolate.Language.Utf8GraphQLParser.ParseValueLiteral(Boolean isConstant)\r\n at HotChocolate.Language.Utf8GraphQLParser.ParseValueLiteral(Boolean isConstant)\r\n at HotChocolate.Language.Utf8GraphQLParser.ParseValueLiteral(Boolean isConstant)\r\n at HotChocolate.Stitching.SelectionPathParser.ParseValueLiteral(Utf8GraphQLParser& parser)\r\n at HotChocolate.Stitching.SelectionPathParser.ParseArgument(Utf8GraphQLParser& parser)\r\n at HotChocolate.Stitching.SelectionPathParser.ParseArguments(Utf8GraphQLParser& parser)\r\n at HotChocolate.Stitching.SelectionPathParser.ParseSelectionPathComponent(Utf8GraphQLParser& parser)\r\n at HotChocolate.Stitching.SelectionPathParser.ParseSelectionPath(Utf8GraphQLParser& parser)\r\n at HotChocolate.Stitching.SelectionPathParser.Parse(String path)\r\n at HotChocolate.Stitching.Utilities.FieldDependencyResolver.CollectFieldNames(DelegateDirective directive, IHasName type, ISet1 dependencies)\r\n at HotChocolate.Stitching.Utilities.FieldDependencyResolver.CollectDelegationDependencies(Context context, IHasName type, IOutputField field)\r\n at HotChocolate.Stitching.Utilities.FieldDependencyResolver.VisitField(FieldNode node, Context context)\r\n at HotChocolate.Language.SyntaxVisitor2.VisitSelection(ISelectionNode node, TContext context)\r\n at HotChocolate.Language.SyntaxVisitor2.VisitMany[T](IEnumerable1 items, TContext context, Action2 action)\r\n at HotChocolate.Language.QuerySyntaxWalker1.VisitSelectionSet(SelectionSetNode node, TContext context)\r\n at HotChocolate.Stitching.Utilities.FieldDependencyResolver.GetFieldDependencies(DocumentNode document, SelectionSetNode selectionSet, INamedOutputType declaringType)\r\n at HotChocolate.Stitching.Delegation.ExtractFieldQuerySyntaxRewriter.RewriteSelectionSet(SelectionSetNode node, Context context)\r\n at HotChocolate.Language.SyntaxRewriter1.Rewrite[TParent,TProperty](TParent parent, TProperty property, TContext context, Func3 visit, Func2 rewrite)\r\n at HotChocolate.Stitching.Delegation.ExtractFieldQuerySyntaxRewriter.RewriteFieldSelectionSet(FieldNode node, IOutputField field, Context context)\r\n at HotChocolate.Stitching.Delegation.ExtractFieldQuerySyntaxRewriter.RewriteField(FieldNode node, Context context)\r\n at HotChocolate.Stitching.Delegation.ExtractFieldQuerySyntaxRewriter.ExtractField(NameString sourceSchema, DocumentNode document, OperationDefinitionNode operation, IFieldSelection selection, INamedOutputType declaringType)\r\n at HotChocolate.Stitching.Delegation.DelegateToRemoteSchemaMiddleware.CreateQuery(IMiddlewareContext context, NameString schemaName, IImmutableStack1 path, IImmutableStack1 reversePath)\r\n at HotChocolate.Stitching.Delegation.DelegateToRemoteSchemaMiddleware.InvokeAsync(IMiddlewareContext context)\r\n at HotChocolate.Utilities.MiddlewareCompiler1.ExpressionHelper.AwaitTaskHelper(Task task)\r\n at HotChocolate.Execution.Processing.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n at HotChocolate.Execution.Processing.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)" }

This is fixed with the new gateway of 13

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.

Any ETA on this? I’m using 13.0.0-rc1, but problem still exists in that version…

@PBTests We are actively working on stitching and this limitation will be removed in v13