Skip to content

Cannot filter using fields in relationship #825

@yorek

Description

@yorek

I have this GraphQL that is trying to filter all the books that belongs to the "Foundation" series:

{
  books(filter: { series: { name: { eq: "Foundation" }}} )  {
    items {
      id
      title      
      series {
        name
      }
    }
  }
}

when I run it I get the following error:

{
  "errors": [
    {
      "message": "Operation name on int type not supported.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "books"
      ]
    }
  ]
}

Here's the SQL code and the DAB config to repro the problem:

drop table if exists dbo.books_authors;
drop table if exists dbo.books;
drop table if exists dbo.authors;
drop table if exists dbo.series;
drop sequence if exists dbo.globalId;
go

create sequence dbo.globalId
as int
start with 1000000
increment by 1
go

create table dbo.books
(
    id int not null primary key default (next value for dbo.globalId),
    title nvarchar(1000) not null,
    [year] int null,
    [pages] int null
)
go

create table dbo.authors
(
    id int not null primary key default (next value for dbo.globalId),
    first_name nvarchar(100) not null,
    middle_name  nvarchar(100) null,
    last_name nvarchar(100) not null
)
go

create table dbo.books_authors
(
    author_id int not null foreign key references dbo.authors(id),
    book_id int not null foreign key references dbo.books(id),
    primary key (
        author_id,
        book_id
    )
)
go

create nonclustered index ixncu1 on dbo.books_authors(book_id, author_id)
go

insert into dbo.authors values
    (1, 'Isaac', null, 'Asimov'),
    (2, 'Robert', 'A.', 'Heinlein'),
    (3, 'Robert', null, 'Silvenberg'),
    (4, 'Dan', null, 'Simmons')
go

insert into dbo.books values
    (1000, 'Prelude to Foundation', 1988, 403),
    (1001, 'Forward the Foundation', 1993, 417),
    (1002, 'Foundation', 1951, 255),
    (1003, 'Foundation and Empire', 1952, 247),
    (1004, 'Second Foundation', 1953, 210),
    (1005, 'Foundation''s Edge', 1982, 367),
    (1006, 'Foundation and Earth', 1986, 356),
    (1007, 'Nemesis', 1989, 386),
    (1008, 'Starship Troopers', null, null),
    (1009, 'Stranger in a Strange Land', null, null),
    (1010, 'Nightfall', null, null),
    (1011, 'Nightwings', null, null),
    (1012, 'Across a Billion Years', null, null),
    (1013, 'Hyperion', 1989, 482),
    (1014, 'The Fall of Hyperion', 1990, 517),
    (1015, 'Endymion', 1996, 441),
    (1016, 'The Rise of Endymion', 1997, 579)
go

insert into dbo.books_authors values
    (1, 1000),
    (1, 1001),
    (1, 1002),
    (1, 1003),
    (1, 1004),
    (1, 1005),
    (1, 1006),
    (1, 1007),
    (1, 1010),
    (2, 1008),
    (2, 1009),
    (2, 1011),
    (3, 1010),
    (3, 1012),
    (4, 1013),
    (4, 1014),
    (4, 1015),
    (4, 1016)
go

create table dbo.series
(
    id int not null primary key default (next value for dbo.globalId),
    [name] nvarchar(1000) not null
)
go

alter table dbo.books 
    add series_id int null;
go

alter table dbo.books 
    add foreign key (series_id) references dbo.series(id)
go

insert into dbo.series values
    (10000, 'Foundation'),
    (10001, 'Hyperion Cantos')
go

update dbo.books 
set series_id = 10000
where id in (1000, 1001, 1002, 1003, 1004, 1005, 1006)
go

update dbo.books 
set series_id = 10001
where id in (1013, 1014, 1015, 1016)
go

and here's the config file:

{
  "$schema": "../../../schemas/dab.draft-01.schema.json",
  "data-source": {
    "database-type": "mssql",
    "connection-string": "***"
  },
  "runtime": {
    "rest": {
      "path": "/api"
    },
    "graphql": {
      "path": "/graphql"
    },
    "host": {
      "mode": "production",
      "cors": {
        "origins": [],
        "allow-credentials": false
      },
      "authentication": {
        "provider": "StaticWebApps"
      }
    }
  },
  "entities": {
    "book": {
      "source": "dbo.books",
      "rest": {
        "path": "books"
      },
      "permissions": [
        {
          "role": "anonymous",
          "actions": [
            "*"
          ]
        }
      ],
      "relationships": {
        "series": {
          "cardinality": "one",
          "target.entity": "series",
          "source.fields": [ "series_id" ],
          "target.fields": [ "id" ]
        }
      }
    },
    "series": {
      "source": "dbo.series",
      "permissions": [
        {
          "role": "anonymous",
          "actions": [
            {
              "action": "*"
            }
          ]
        }
      ],
      "relationships": {
        "books": {
          "cardinality": "many",
          "target.entity": "book"
        }
      }
    }
  }
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggraphql

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions