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]: REST works, GraphQL does not #2540

Open
JerryNixon opened this issue Jan 24, 2025 · 0 comments
Open

[Bug]: REST works, GraphQL does not #2540

JerryNixon opened this issue Jan 24, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@JerryNixon
Copy link
Contributor

JerryNixon commented Jan 24, 2025

Image

Query

query a {
  characters {
    items {
      Name
    }
  }
}

Error

info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint 'Hot Chocolate GraphQL Pipeline'
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HN9S4N57VFC1", Request id "0HN9S4N57VFC1:00000003": An unhandled exception was thrown by the application.
      Azure.DataApiBuilder.Service.Exceptions.DataApiBuilderException: No relationship exists between Character and Actor
         at Azure.DataApiBuilder.Service.GraphQLBuilder.Sql.SchemaConverter.FindNullabilityOfRelationship(String entityName, DatabaseObject databaseObject, String targetEntityName) in /_/src/Service.GraphQLBuilder/Sql/SchemaConverter.cs:line 470
         at Azure.DataApiBuilder.Service.GraphQLBuilder.Sql.SchemaConverter.GenerateFieldForRelationship(String entityName, DatabaseObject databaseObject, RuntimeEntities entities, String relationshipName, EntityRelationship relationship) in /_/src/Service.GraphQLBuilder/Sql/SchemaConverter.cs:line 276
         at Azure.DataApiBuilder.Service.GraphQLBuilder.Sql.SchemaConverter.CreateObjectTypeDefinitionForTableOrView(String entityName, DatabaseObject databaseObject, Entity configEntity, RuntimeEntities entities, IEnumerable`1 rolesAllowedForEntity, IDictionary`2 rolesAllowedForFields) in /_/src/Service.GraphQLBuilder/Sql/SchemaConverter.cs:line 195
         at Azure.DataApiBuilder.Service.GraphQLBuilder.Sql.SchemaConverter.GenerateObjectTypeDefinitionForDatabaseObject(String entityName, DatabaseObject databaseObject, Entity configEntity, RuntimeEntities entities, IEnumerable`1 rolesAllowedForEntity, IDictionary`2 rolesAllowedForFields) in /_/src/Service.GraphQLBuilder/Sql/SchemaConverter.cs:line 56
         at Azure.DataApiBuilder.Core.Services.GraphQLSchemaCreator.GenerateSqlGraphQLObjects(RuntimeEntities entities, Dictionary`2 inputObjects) in /_/src/Core/Services/GraphQLSchemaCreator.cs:line 214
         at Azure.DataApiBuilder.Core.Services.GraphQLSchemaCreator.GenerateGraphQLObjects() in /_/src/Core/Services/GraphQLSchemaCreator.cs:line 609
         at Azure.DataApiBuilder.Core.Services.GraphQLSchemaCreator.InitializeSchemaAndResolvers(ISchemaBuilder schemaBuilder) in /_/src/Core/Services/GraphQLSchemaCreator.cs:line 155   
         at Azure.DataApiBuilder.Service.Startup.<>c.<AddGraphQLService>b__14_0(IServiceProvider serviceProvider, ISchemaBuilder schemaBuilder) in /_/src/Service/Startup.cs:line 237     
         at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(NameString schemaName, RequestExecutorSetup options, RequestExecutorOptions executorOptions, IServiceProvider serviceProvider, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(NameString schemaN

Error message

No relationship exists between Character and Actor

There is a relationship between Character and Actor. This error is wrong.

Observation

There are TWO relationships. If I remove EITHER it starts working.

Configuration

{
  "$schema": "https://github.com/Azure/data-api-builder/releases/download/v1.3.19/dab.draft.schema.json",
  "data-source": {
    "database-type": "mssql",
    "connection-string": "{conn-string}",
    "options": {
      "set-session-context": false
    }
  },
  "runtime": {
    "host": {
      "cors": {
        "origins": [],
        "allow-credentials": false
      },
      "authentication": {
        "provider": "StaticWebApps"
      },
      "mode": "development"
    }
  },
  "entities": {
    "Character": {
      "source": {
        "object": "dbo.Character",
        "type": "table"
      },
      "permissions": [
        {
          "role": "anonymous",
          "actions": [
            {
              "action": "*"
            }
          ]
        }
      ],
      "relationships": {
        "Actor": {
          "cardinality": "many",
          "target.entity": "Actor",
          "source.fields": [
            "ActorId"
          ],
          "target.fields": [
            "Id"
          ],
          "linking.source.fields": [],
          "linking.target.fields": []
        }
      }
    },
    "Character_Species": {
      "source": {
        "object": "dbo.Character_Species",
        "type": "table"
      },
      "permissions": [
        {
          "role": "anonymous",
          "actions": [
            {
              "action": "*"
            }
          ]
        }
      ],
      "relationships": {
        "Character": {
          "cardinality": "many",
          "target.entity": "Character",
          "source.fields": [
            "CharacterId"
          ],
          "target.fields": [
            "Id"
          ],
          "linking.source.fields": [],
          "linking.target.fields": []
        }
      }
    },
    "Actor": {
      "source": {
        "object": "dbo.Actor",
        "type": "table"
      },
      "permissions": [
        {
          "role": "anonymous",
          "actions": [
            {
              "action": "*"
            }
          ]
        }
      ]
    }
  }
}

Database schema

SET NOCOUNT ON

use [trek];

-- Create Login
IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = 'DabLogin')
    CREATE LOGIN [DabLogin] WITH PASSWORD = 'P@ssw0rd!';
ALTER SERVER ROLE sysadmin ADD MEMBER [DabLogin];

-- Create User
IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = 'DabUser')
    CREATE USER [DabUser] FOR LOGIN [DabLogin];
EXEC sp_addrolemember 'db_owner', 'DabUser';

-- Drop tables in reverse order of creation due to foreign key dependencies
DROP TABLE IF EXISTS Character_Species;
DROP TABLE IF EXISTS Series_Character;
DROP TABLE IF EXISTS Character;
DROP TABLE IF EXISTS Species;
DROP TABLE IF EXISTS Actor;
DROP TABLE IF EXISTS Series;

-- create tables
CREATE TABLE Series (
    Id INT PRIMARY KEY,
    Name NVARCHAR(255) NOT NULL
);

CREATE TABLE Actor (
    Id INT PRIMARY KEY,
    Name NVARCHAR(255) NOT NULL,
    [BirthYear] INT NOT NULL
);

CREATE TABLE Species (
    Id INT PRIMARY KEY,
    Name NVARCHAR(255) NOT NULL
);

CREATE TABLE Character (
    Id INT PRIMARY KEY,
    Name NVARCHAR(255) NOT NULL,
    ActorId INT NOT NULL,
    Stardate DECIMAL(10, 2),
    FOREIGN KEY (ActorId) REFERENCES Actor(Id)
);

CREATE TABLE Series_Character (
    SeriesId INT,
    CharacterId INT,
	Role VARCHAR(500),
    FOREIGN KEY (SeriesId) REFERENCES Series(Id),
    FOREIGN KEY (CharacterId) REFERENCES Character(Id),
    PRIMARY KEY (SeriesId, CharacterId)
);

CREATE TABLE Character_Species (
    CharacterId INT,
    SpeciesId INT,
    FOREIGN KEY (CharacterId) REFERENCES Character(Id),
    FOREIGN KEY (SpeciesId) REFERENCES Species(Id),
    PRIMARY KEY (CharacterId, SpeciesId)
);
@JerryNixon JerryNixon added the bug Something isn't working label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant