Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cc72ac4
Add GraphQL Query support for field aliases on (no relationship) enti…
seantleonard Jan 25, 2023
92090e5
Create (Insert) GraphQL Mutation support for Column Aliases (Mapped c…
seantleonard Jan 26, 2023
e3a99e9
Add GraphQL Alias (mappings) support for Update and Delete mutations.
seantleonard Jan 26, 2023
94a96c9
update spacing.
seantleonard Jan 26, 2023
d18443a
Merge branch 'main' into dev/seleonar/graphQL_Mappings
seantleonard Jan 26, 2023
68df518
Disable GraphQL for entities with non-compatible mapped names. Table …
seantleonard Jan 26, 2023
79de857
Explicitly disable GraphQL endpoint on entities used for REST testing…
seantleonard Jan 26, 2023
c54591c
fix cmd spelling.
seantleonard Jan 26, 2023
4bd7f2e
Fix spacing.
seantleonard Jan 26, 2023
578fef4
Added helper method to reduce code duplication
seantleonard Jan 27, 2023
754985f
Added GraphQL mappings tests for mutations MSSQL
seantleonard Jan 27, 2023
0a20c1a
Updated config generators for tests.
seantleonard Jan 27, 2023
40a3efb
updated commands for mssql
seantleonard Jan 27, 2023
65ce370
Add Query and Mutation mappings tests and add Query Filter Backing co…
seantleonard Jan 27, 2023
96d6498
Merge branch 'main' into dev/seleonar/graphQL_Mappings
seantleonard Jan 30, 2023
3d23e2b
update map cmd
seantleonard Jan 30, 2023
54ac9f0
update add entity
seantleonard Jan 30, 2023
215f4e8
Add schema converter tests.
seantleonard Jan 30, 2023
51ea502
Updated test with comments.
seantleonard Jan 30, 2023
b9d9552
Patch Cosmos incompatibility with mapped columns.
seantleonard Jan 30, 2023
10cab9c
fix spacing.
seantleonard Jan 30, 2023
1442fd3
Added PG and MySQL tests.
seantleonard Jan 30, 2023
ddb709a
Updated mutation tests for PG and MySQL
seantleonard Jan 30, 2023
f40777e
Update PG/MySQL commands and .sql files
seantleonard Jan 30, 2023
b34a5f1
drop table if exists.
seantleonard Jan 30, 2023
272ae6d
fix mysql issues. and PG
seantleonard Jan 30, 2023
184eefd
fixes
seantleonard Jan 30, 2023
be082b8
Fix casing MySql Table.
seantleonard Jan 30, 2023
db61efa
Merge branch 'main' into dev/seleonar/graphQL_Mappings
seantleonard Jan 30, 2023
8f86b87
fix casing.
seantleonard Jan 30, 2023
e6dcd7d
Merge branch 'main' into dev/seleonar/graphQL_Mappings
seantleonard Jan 30, 2023
988ffb6
Update method comment
seantleonard Jan 30, 2023
2d57951
Merge branch 'dev/seleonar/graphQL_Mappings' of https://github.com/Az…
seantleonard Jan 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ConfigGenerators/MsSqlCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ add books_publishers_view_composite_insertable --config "dab-config.MsSql.json"
add Empty --config "dab-config.MsSql.json" --source "empty_table" --permissions "authenticated:create,read,update,delete" --rest true
add Notebook --config "dab-config.MsSql.json" --source "notebooks" --permissions "anonymous:read" --rest true --graphql true --fields.include "*" --policy-database "@item ne 1"
add Journal --config "dab-config.MsSql.json" --source "journals" --rest true --graphql true --permissions "policy_tester_noupdate:create,delete"
add ArtOfWar --config "dab-config.MsSql.json" --source "aow" --rest true --permissions "anonymous:*"
add ArtOfWar --config "dab-config.MsSql.json" --source "aow" --rest true --graphql false --permissions "anonymous:*"
Comment thread
seantleonard marked this conversation as resolved.
add series --config "dab-config.MsSql.json" --source "series" --permissions "anonymous:*"
add Sales --config "dab-config.MsSql.json" --source "sales" --permissions "anonymous:*" --rest true --graphql true
add GetBooks --config "dab-config.MsSql.json" --source "get_books" --source.type "stored-procedure" --permissions "anonymous:read" --rest true --graphql true
Expand All @@ -34,6 +34,8 @@ add DeleteLastInsertedBook --config "dab-config.MsSql.json" --source "delete_las
add UpdateBookTitle --config "dab-config.MsSql.json" --source "update_book_title" --source.type "stored-procedure" --source.params "id:1,title:Testing Tonight" --permissions "anonymous:update" --rest true --graphql true
add GetAuthorsHistoryByFirstName --config "dab-config.MsSql.json" --source "get_authors_history_by_first_name" --source.type "stored-procedure" --source.params "firstName:Aaron" --permissions "anonymous:read" --rest true --graphql SearchAuthorByFirstName
add InsertAndDisplayAllBooksUnderGivenPublisher --config "dab-config.MsSql.json" --source "insert_and_display_all_books_for_given_publisher" --source.type "stored-procedure" --source.params "title:MyTitle,publisher_name:MyPublisher" --permissions "anonymous:create" --rest true --graphql true
add GQLmappings --config "dab-config.MsSql.json" --source "GQLmappings" --permissions "anonymous:*" --rest true --graphql true
update GQLmappings --config "dab-config.MsSql.json" --map "__column1:column1,__column2:column2" --permissions "authenticated:*"
update Publisher --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many
update Publisher --config "dab-config.MsSql.json" --permissions "policy_tester_01:create,delete"
update Publisher --config "dab-config.MsSql.json" --permissions "policy_tester_01:update" --fields.include "*"
Expand Down Expand Up @@ -93,7 +95,7 @@ update stocks_price --config "dab-config.MsSql.json" --permissions "authenticate
update Comic --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship myseries --target.entity series --cardinality one
update series --config "dab-config.MsSql.json" --relationship comics --target.entity Comic --cardinality many
update Broker --config "dab-config.MsSql.json" --permissions "authenticated:create,update,read,delete" --graphql false
update Tree --config "dab-config.MsSql.json" --rest true --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
update Tree --config "dab-config.MsSql.json" --rest true --graphql false --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
update Shrub --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName"
update Fungus --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --map "spores:hazards" --rest true
update Fungus --config "dab-config.MsSql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'"
Expand Down
6 changes: 4 additions & 2 deletions ConfigGenerators/MySqlCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ add books_publishers_view_composite_insertable --config "dab-config.MySql.json"
add Empty --config "dab-config.MySql.json" --source "empty_table" --permissions "authenticated:create,read,update,delete" --rest true
add Notebook --config "dab-config.MySql.json" --source "notebooks" --permissions "anonymous:read" --rest true --graphql true --fields.include "*" --policy-database "@item ne 1"
add Journal --config "dab-config.MySql.json" --source "journals" --rest true --graphql true --permissions "policy_tester_noupdate:create,delete"
add ArtOfWar --config "dab-config.MySql.json" --source "aow" --rest true --permissions "anonymous:*"
add ArtOfWar --config "dab-config.MySql.json" --source "aow" --rest true --graphql false --permissions "anonymous:*"
add series --config "dab-config.MySql.json" --source "series" --permissions "anonymous:*"
add Sales --config "dab-config.MySql.json" --source "sales" --permissions "anonymous:*" --rest true --graphql true
add GQLmappings --config "dab-config.MySql.json" --source "GQLmappings" --permissions "anonymous:*" --rest true --graphql true
update GQLmappings --config "dab-config.MySql.json" --map "__column1:column1,__column2:column2" --permissions "authenticated:*"
update Publisher --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many
update Publisher --config "dab-config.MySql.json" --permissions "policy_tester_01:create,delete"
update Publisher --config "dab-config.MySql.json" --permissions "policy_tester_01:update" --fields.include "*"
Expand Down Expand Up @@ -84,7 +86,7 @@ update stocks_price --config "dab-config.MySql.json" --permissions "authenticate
update Comic --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship myseries --target.entity series --cardinality one
update series --config "dab-config.MySql.json" --relationship comics --target.entity Comic --cardinality many
update Broker --config "dab-config.MySql.json" --permissions "authenticated:create,update,read,delete" --graphql false
update Tree --config "dab-config.MySql.json" --rest true --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
update Tree --config "dab-config.MySql.json" --rest true --graphql false --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
update Shrub --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName"
update Fungus --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --map "spores:hazards" --rest true
update Fungus --config "dab-config.MySql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'"
Expand Down
6 changes: 4 additions & 2 deletions ConfigGenerators/PostgreSqlCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ add books_publishers_view_composite_insertable --config "dab-config.PostgreSql.j
add Empty --config "dab-config.PostgreSql.json" --source "empty_table" --permissions "authenticated:create,read,update,delete" --rest true
add Notebook --config "dab-config.PostgreSql.json" --source "notebooks" --permissions "anonymous:read" --rest true --graphql true --fields.include "*" --policy-database "@item ne 1"
add Journal --config "dab-config.PostgreSql.json" --source "journals" --rest true --graphql true --permissions "policy_tester_noupdate:create,delete"
add ArtOfWar --config "dab-config.PostgreSql.json" --source "aow" --rest true --permissions "anonymous:*"
add ArtOfWar --config "dab-config.PostgreSql.json" --source "aow" --rest true --graphql false --permissions "anonymous:*"
add series --config "dab-config.PostgreSql.json" --source "series" --permissions "anonymous:*"
add Sales --config "dab-config.PostgreSql.json" --source "sales" --permissions "anonymous:*" --rest true --graphql true
add GQLmappings --config "dab-config.PostgreSql.json" --source "gqlmappings" --permissions "anonymous:*" --rest true --graphql true
update GQLmappings --config "dab-config.PostgreSql.json" --map "__column1:column1,__column2:column2" --permissions "authenticated:*"
update Publisher --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many
update Publisher --config "dab-config.PostgreSql.json" --permissions "policy_tester_01:create,delete"
update Publisher --config "dab-config.PostgreSql.json" --permissions "policy_tester_01:update" --fields.include "*"
Expand Down Expand Up @@ -84,7 +86,7 @@ update stocks_price --config "dab-config.PostgreSql.json" --permissions "authent
update Comic --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship myseries --target.entity series --cardinality one
update series --config "dab-config.PostgreSql.json" --relationship comics --target.entity Comic --cardinality many
update Broker --config "dab-config.PostgreSql.json" --permissions "authenticated:create,update,read,delete" --graphql false
update Tree --config "dab-config.PostgreSql.json" --rest true --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
update Tree --config "dab-config.PostgreSql.json" --rest true --graphql false --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region"
update Shrub --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --map "species:fancyName"
update Fungus --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --map "spores:hazards" --rest true
update Fungus --config "dab-config.PostgreSql.json" --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'"
Expand Down
24 changes: 23 additions & 1 deletion ConfigGenerators/dab-config.mssql.reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@
"source": {
"type": "view",
"object": "books_view_with_mapping",
"key-fields": ["id"]
"key-fields": [ "id" ]
},
"rest": true,
"permissions": [
Expand Down Expand Up @@ -1092,6 +1092,28 @@
}
],
"graphql": true
},
"GQLmappings": {
"source": {
"type": "table",
"object": "GQLmappings",
"key-fields": []
},
"graphql": true,
"mappings": {
"__column1": "column1",
"__column2": "column2"
},
"permissions": [
{
"role": "anonymous",
"actions": [ "*" ]
},
{
"role": "authenticated",
"actions": [ "*" ]
}
]
}
}
}
18 changes: 18 additions & 0 deletions ConfigGenerators/dab-config.sql.reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,24 @@
}
],
"graphql": true
},
"GQLmappings": {
"source": "GQLmappings",
"graphql": true,
"mappings": {
"__column1": "column1",
"__column2": "column2"
},
"permissions": [
{
"role": "anonymous",
"actions": [ "*" ]
},
{
"role": "authenticated",
"actions": [ "*" ]
}
]
}
}
}
8 changes: 7 additions & 1 deletion src/Service.GraphQLBuilder/Sql/SchemaConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,16 @@ public static ObjectTypeDefinitionNode FromDatabaseObject(
directives.Add(authZDirective!);
}

string exposedColumnName = columnName;
if (configEntity.Mappings is not null && configEntity.Mappings.TryGetValue(key: columnName, out string? columnAlias))
{
exposedColumnName = columnAlias;
}

NamedTypeNode fieldType = new(GetGraphQLTypeForColumnType(column.SystemType));
FieldDefinitionNode field = new(
location: null,
new(columnName),
new(exposedColumnName),
description: null,
new List<InputValueDefinitionNode>(),
column.IsNullable ? fieldType : new NonNullTypeNode(fieldType),
Expand Down
49 changes: 49 additions & 0 deletions src/Service.Tests/GraphQLBuilder/Sql/SchemaConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,55 @@ public void ColumnNameBecomesFieldName(string columnName, string expected)
Assert.AreEqual(expected, od.Fields[0].Name.Value);
}

/// <summary>
/// Tests that an Entity object's mapping configuration is utilized in the schema generator
/// by checking that mapped column values are used for field names instead of backing column names.
/// </summary>
/// <param name="setMappings">Whether to add mapping entries to the mappings collection.</param>
/// <param name="backingColumnName">Name of database column.</param>
/// <param name="mappedName">Configured alternative (mapped) name of column to be used in REST/GraphQL endpoints.</param>
/// <param name="expectMappedName">Whether GraphQL object field name should equal the mapped column name provided.</param>
[DataTestMethod]
[DataRow(true, "__typename", "typename", true, DisplayName = "Mapped column name fixes GraphQL introspection naming violation. ")]
[DataRow(false, "typename", "mappedtypename", false, DisplayName = "Mapped column name ")]
public void FieldNameMatchesMappedValue(bool setMappings, string backingColumnName, string mappedName, bool expectMappedName)
{
Dictionary<string, string> mappings = new();

if (setMappings)
{
mappings.Add(backingColumnName, mappedName);
}

SourceDefinition table = new();
table.Columns.Add(backingColumnName, new ColumnDefinition
{
SystemType = typeof(string)
});

DatabaseObject dbObject = new DatabaseTable() { TableDefinition = table };

Entity configEntity = GenerateEmptyEntity() with { Mappings = mappings };

ObjectTypeDefinitionNode od = SchemaConverter.FromDatabaseObject(
"table",
dbObject,
configEntity,
entities: new(),
rolesAllowedForEntity: GetRolesAllowedForEntity(),
rolesAllowedForFields: GetFieldToRolesMap(columnName: table.Columns.First().Key));

string errorMessage = "Object field representing database column has an unexpected name value.";
if (expectMappedName)
{
Assert.AreEqual(mappedName, od.Fields[0].Name.Value, message: errorMessage);
}
else
{
Assert.AreEqual(backingColumnName, od.Fields[0].Name.Value, message: errorMessage);
}
}

[TestMethod]
public void PrimaryKeyColumnHasAppropriateDirective()
{
Expand Down
12 changes: 12 additions & 0 deletions src/Service.Tests/MsSqlBooks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ DROP TABLE IF EXISTS sales;
DROP TABLE IF EXISTS authors_history;
DROP TABLE IF EXISTS revenues;
DROP TABLE IF EXISTS graphql_incompatible;
DROP TABLE IF EXISTS GQLmappings;
DROP SCHEMA IF EXISTS [foo];
COMMIT;

Expand Down Expand Up @@ -212,6 +213,12 @@ CREATE TABLE graphql_incompatible (
conformingName varchar(12)
);

CREATE TABLE GQLmappings (
__column1 int PRIMARY KEY,
__column2 varchar(max),
column3 varchar(max)
)

ALTER TABLE books
ADD CONSTRAINT book_publisher_fk
FOREIGN KEY (publisher_id)
Expand Down Expand Up @@ -271,6 +278,11 @@ SET IDENTITY_INSERT authors ON
INSERT INTO authors(id, name, birthdate) VALUES (123, 'Jelte', '2001-01-01'), (124, 'Aniruddh', '2002-02-02'), (125, 'Aniruddh', '2001-01-01'), (126, 'Aaron', '2001-01-01');
SET IDENTITY_INSERT authors OFF

INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (1, 'Incompatible GraphQL Name', 'Compatible GraphQL Name');
INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (3, 'Old Value', 'Record to be Updated');
INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (4, 'Lost Record', 'Record to be Deleted');
INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (5, 'Filtered Record', 'Record to be Filtered on Find');

SET IDENTITY_INSERT books ON
INSERT INTO books(id, title, publisher_id)
VALUES (1, 'Awesome book', 1234),
Expand Down
12 changes: 11 additions & 1 deletion src/Service.Tests/MySqlBooks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DROP TABLE IF EXISTS aow;
DROP TABLE IF EXISTS series;
DROP TABLE IF EXISTS sales;
DROP TABLE IF EXISTS graphql_incompatible;

DROP TABLE IF EXISTS GQLmappings;

CREATE TABLE publishers(
id int AUTO_INCREMENT PRIMARY KEY,
Expand Down Expand Up @@ -177,6 +177,12 @@ CREATE TABLE graphql_incompatible (
conformingName text
);

CREATE TABLE GQLmappings (
__column1 int PRIMARY KEY,
__column2 text,
column3 text
);

ALTER TABLE books
ADD CONSTRAINT book_publisher_fk
FOREIGN KEY (publisher_id)
Expand Down Expand Up @@ -225,6 +231,10 @@ FOREIGN KEY (series_id)
REFERENCES series(id)
ON DELETE CASCADE;

INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (1, 'Incompatible GraphQL Name', 'Compatible GraphQL Name');
INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (3, 'Old Value', 'Record to be Updated');
INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (4, 'Lost Record', 'Record to be Deleted');
INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (5, 'Filtered Record', 'Record to be Filtered on Find');
INSERT INTO publishers(id, name) VALUES (1234, 'Big Company'), (2345, 'Small Town Publisher'), (2323, 'TBD Publishing One'), (2324, 'TBD Publishing Two Ltd'), (1940, 'Policy Publisher 01'), (1941, 'Policy Publisher 02'), (1156, 'The First Publisher');
INSERT INTO authors(id, name, birthdate) VALUES (123, 'Jelte', '2001-01-01'), (124, 'Aniruddh', '2002-02-02'), (125, 'Aniruddh', '2001-01-01'), (126, 'Aaron', '2001-01-01');
INSERT INTO books(id, title, publisher_id)
Expand Down
11 changes: 11 additions & 0 deletions src/Service.Tests/PostgreSqlBooks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ DROP TABLE IF EXISTS journals;
DROP TABLE IF EXISTS series;
DROP TABLE IF EXISTS sales;
DROP TABLE IF EXISTS graphql_incompatible;
DROP TABLE IF EXISTS GQLmappings;
DROP FUNCTION IF EXISTS insertCompositeView;

DROP SCHEMA IF EXISTS foo;
Expand Down Expand Up @@ -181,6 +182,12 @@ CREATE TABLE graphql_incompatible (
conformingName text
);

CREATE TABLE GQLmappings (
__column1 int PRIMARY KEY,
__column2 text,
column3 text
);

ALTER TABLE books
ADD CONSTRAINT book_publisher_fk
FOREIGN KEY (publisher_id)
Expand Down Expand Up @@ -229,6 +236,10 @@ FOREIGN KEY (series_id)
REFERENCES series(id)
ON DELETE CASCADE;

INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (1, 'Incompatible GraphQL Name', 'Compatible GraphQL Name');
INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (3, 'Old Value', 'Record to be Updated');
INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (4, 'Lost Record', 'Record to be Deleted');
INSERT INTO GQLmappings(__column1, __column2, column3) VALUES (5, 'Filtered Record', 'Record to be Filtered on Find');
INSERT INTO publishers(id, name) VALUES (1234, 'Big Company'), (2345, 'Small Town Publisher'), (2323, 'TBD Publishing One'), (2324, 'TBD Publishing Two Ltd'), (1940, 'Policy Publisher 01'), (1941, 'Policy Publisher 02'), (1156, 'The First Publisher');
INSERT INTO authors(id, name, birthdate) VALUES (123, 'Jelte', '2001-01-01'), (124, 'Aniruddh', '2002-02-02'), (125, 'Aniruddh', '2001-01-01'), (126, 'Aaron', '2001-01-01');
INSERT INTO books(id, title, publisher_id)
Expand Down
Loading