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

[Bug]: GraphQL Query failure when mappings exist for relationship fields #2166

Closed
1 task done
severussundar opened this issue Apr 15, 2024 · 0 comments · Fixed by #2175
Closed
1 task done

[Bug]: GraphQL Query failure when mappings exist for relationship fields #2166

severussundar opened this issue Apr 15, 2024 · 0 comments · Fixed by #2175
Assignees
Labels
bug Something isn't working graphql triage issues to be triaged
Milestone

Comments

@severussundar
Copy link
Contributor

severussundar commented Apr 15, 2024

What happened?

When there exists mapping for relationship fields, GraphQL query fails. This happens for all relationship types.

Config File

Entity : Book

"mappings": {
        "id": "identifier"
  },

Authors relationship

"authors": {
          "cardinality": "many",
          "target.entity": "Author",
          "source.fields": [
            "identifier"
          ],
          "target.fields": [
            "id"
          ],
          "linking.object": "book_author_link",
          "linking.source.fields": [
            "book_id"
          ],
          "linking.target.fields": [
            "author_id"
          ]
        }

Review Relationship

        "reviews": {
          "cardinality": "many",
          "target.entity": "Review",
          "source.fields": ["identifier"],
          "target.fields": ["book_id"],
          "linking.source.fields": [],
          "linking.target.fields": []
        }

Query 1

{
  books {
    items {
      identifier
      title
      authors {
        items {
          id
          name
          birthdate
        }
      }
    }
  }
}

image

Query 2

{
  books{
    items{
      identifier
      title
      reviews{
        items{
          book_id
          id
          content
        }
      }
    }
  }

}

image

Version/Branch:

  • Version: 0.12.*
  • Branch: Current Main

What database are you using?

Azure SQL

What hosting model are you using?

Local (including CLI)

Which API approach are you accessing DAB through?

GraphQL

Relevant log output

dbug: Azure.DataApiBuilder.Core.Resolvers.IQueryExecutor[0]
      53542528-a234-4c70-8aaa-e5944b2926b5 Executing query: SELECT TOP 100 [table0].[id] AS [identifier], [table0].[title] AS [title], JSON_QUERY (COALESCE([table1_subq].[data], '[]')) AS [authors] FROM [dbo].[books] AS [table0] OUTER APPLY (SELECT TOP 100 [table1].[id] AS [id], [table1].[name] AS [name], [table1].[birthdate] AS [birthdate] FROM [dbo].[authors] AS [table1] INNER JOIN [dbo].[book_author_link] AS [table5] ON [table5].[author_id] = [table1].[id] WHERE [table5].[book_id] = [table0].[identifier] ORDER BY [table1].[id] ASC FOR JSON PATH, INCLUDE_NULL_VALUES) AS [table1_subq]([data]) WHERE 1 = 1 ORDER BY [table0].[id] ASC FOR JSON PATH, INCLUDE_NULL_VALUES
fail: Azure.DataApiBuilder.Core.Resolvers.IQueryExecutor[0]
      53542528-a234-4c70-8aaa-e5944b2926b5 Query execution error due to:
Invalid column name 'identifier'.
      Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'identifier'.
         at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__211_0(Task`1 result)
         at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
      --- End of stack trace from previous location ---
         at Azure.DataApiBuilder.Core.Resolvers.QueryExecutor`1.ExecuteQueryAgainstDbAsync[TResult](TConnection conn, String sqltext, IDictionary`2 parameters, Func`3 dataReaderHandler, HttpContext httpContext, String dataSourceName, List`1 args) in C:\Users\shyamsundarj\Codes\new_clone\data-api-builder\src\Core\Resolvers\QueryExecutor.cs:line 160
      ClientConnectionId:11ea1f53-24d3-49d8-8118-95cc5117affd
      Error Number:207,State:1,Class:16
fail: Azure.DataApiBuilder.Service.Startup[0]
      A GraphQL request execution error occurred.
      Azure.DataApiBuilder.Service.Exceptions.DataApiBuilderException: Invalid column name 'identifier'.
       ---> Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'identifier'.
         at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__211_0(Task`1 result)
         at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
      --- End of stack trace from previous location ---
         at Azure.DataApiBuilder.Core.Resolvers.QueryExecutor`1.ExecuteQueryAgainstDbAsync[TResult](TConnection conn, String sqltext, IDictionary`2 parameters, Func`3 dataReaderHandler, HttpContext httpContext, String dataSourceName, List`1 args) in C:\Users\shyamsundarj\Codes\new_clone\data-api-builder\src\Core\Resolvers\QueryExecutor.cs:line 160
      ClientConnectionId:11ea1f53-24d3-49d8-8118-95cc5117affd
      Error Number:207,State:1,Class:16
         --- End of inner exception stack trace ---
         at Azure.DataApiBuilder.Core.Resolvers.QueryExecutor`1.ExecuteQueryAgainstDbAsync[TResult](TConnection conn, String sqltext, IDictionary`2 parameters, Func`3 dataReaderHandler, HttpContext httpContext, String dataSourceName, List`1 args) in C:\Users\shyamsundarj\Codes\new_clone\data-api-builder\src\Core\Resolvers\QueryExecutor.cs:line 178
         at Azure.DataApiBuilder.Core.Resolvers.QueryExecutor`1.<>c__DisplayClass19_0`1.<<ExecuteQueryAsync>b__0>d.MoveNext() in C:\Users\shyamsundarj\Codes\new_clone\data-api-builder\src\Core\Resolvers\QueryExecutor.cs:line 102
      --- End of stack trace from previous location ---
         at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult](Func`3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates`1 shouldRetryResultPredicates, Func`5 onRetryAsync, Int32 permittedRetryCount, IEnumerable`1 sleepDurationsEnumerable, Func`4 sleepDurationProvider, Boolean continueOnCapturedContext)
         at Polly.AsyncPolicy.ExecuteAsync[TResult](Func`3 action, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext)
         at Azure.DataApiBuilder.Core.Resolvers.QueryExecutor`1.ExecuteQueryAsync[TResult](String sqltext, IDictionary`2 parameters, Func`3 dataReaderHandler, String dataSourceName, HttpContext httpContext, List`1 args) in C:\Users\shyamsundarj\Codes\new_clone\data-api-builder\src\Core\Resolvers\QueryExecutor.cs:line 90
         at Azure.DataApiBuilder.Core.Resolvers.SqlQueryEngine.ExecuteAsync(SqlQueryStructure structure, String dataSourceName) in C:\Users\shyamsundarj\Codes\new_clone\data-api-builder\src\Core\Resolvers\SqlQueryEngine.cs:line 291
         at Azure.DataApiBuilder.Core.Resolvers.SqlQueryEngine.ExecuteAsync(IMiddlewareContext context, IDictionary`2 parameters, String dataSourceName) in C:\Users\shyamsundarj\Codes\new_clone\data-api-builder\src\Core\Resolvers\SqlQueryEngine.cs:line 81
         at Azure.DataApiBuilder.Service.Services.ExecutionHelper.ExecuteQueryAsync(IMiddlewareContext context) in C:\Users\shyamsundarj\Codes\new_clone\data-api-builder\src\Core\Services\ExecutionHelper.cs:line 79
         at ResolverTypeInterceptor.<>c__DisplayClass5_1.<<-ctor>b__5>d.MoveNext() in C:\Users\shyamsundarj\Codes\new_clone\data-api-builder\src\Core\Services\ResolverTypeInterceptor.cs:line 23
      --- End of stack trace from previous location ---
         at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)
         at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@severussundar severussundar added bug Something isn't working graphql triage issues to be triaged labels Apr 15, 2024
@severussundar severussundar added this to the 0.12rc milestone Apr 15, 2024
@seantleonard seantleonard modified the milestones: 0.12rc, 0.12rc2 Apr 16, 2024
ayush3797 added a commit that referenced this issue Apr 30, 2024
## Why make this change?

Closes #2166
Related to #2139

## What is this change?

When we validate the relationship fields in the config, ie: source
fields and target fields, we use the backing column names to validate
against. Previously we were using aliases if one existed, but instead we
will validate only against the actual names of the backing columns. So,
for example, if someone had an alias for the column "id", so that it
would display as "identifier" when using this alias, we would validate
that the relationship defined with that field was defined in the config
using the name "id", and would throw a validation error if the config
instead used, "identifier."

## How was this tested?

Current test suite passing, along with a regression test for DwSql,
MsSql, MySql, and PostreSql.

## Sample Request(s)

Please see this issue for details on samples to reproduce.

#2166

---------

Co-authored-by: Sean Leonard <sean.leonard@microsoft.com>
Co-authored-by: Ayush Agarwal <34566234+ayush3797@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working graphql triage issues to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants