Skip to content

Commit

Permalink
v8.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Abraham committed Mar 8, 2024
1 parent 3bbd166 commit 7d052d6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 35 deletions.
11 changes: 9 additions & 2 deletions src/TypeCache.GraphQL/Extensions/GraphQLExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using GraphQL;
using GraphQL.Resolvers;
using GraphQL.Types;
using TypeCache.Data;
using TypeCache.Data.Extensions;
using TypeCache.Extensions;
using TypeCache.GraphQL.Data;
using TypeCache.GraphQL.Resolvers;
Expand Down Expand Up @@ -44,8 +46,13 @@ public static FieldType AddField(this IComplexGraphType @this, PropertyInfo prop
return @this.AddField(fieldType);
}

public static void AddOrderBy(this EnumerationGraphType @this, OrderBy orderBy, string? deprecationReason = null)
=> @this.Add(orderBy.Display, orderBy.ToString(), orderBy.ToString(), deprecationReason);
public static void AddOrderBy(this EnumerationGraphType @this, string column, string? deprecationReason = null)
{
var asc = Sort.Ascending.ToSQL();
var desc = Sort.Descending.ToSQL();
@this.Add(Invariant($"{column}_{asc}"), Invariant($"{column} {asc}"), Invariant($"{column} {asc}"), deprecationReason);
@this.Add(Invariant($"{column}_{desc}"), Invariant($"{column} {desc}"), Invariant($"{column} {desc}"), deprecationReason);
}

/// <summary>
/// Use this to create a GraphQL Connection object to return in your endpoint to support paging.
Expand Down
22 changes: 9 additions & 13 deletions src/TypeCache.GraphQL/Extensions/SchemaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public static FieldType AddDatabaseSchemaQuery(this ISchema @this, IDataSource d
};
foreach (var column in table.Columns.OfType<DataColumn>())
{
graphOrderByEnum.AddOrderBy(new(column.ColumnName, Sort.Ascending));
graphOrderByEnum.AddOrderBy(new(column.ColumnName, Sort.Descending));
graphOrderByEnum.AddOrderBy(column.ColumnName);

var field = resolvedType.AddField(new()
{
Expand Down Expand Up @@ -212,8 +211,7 @@ public static void AddDatabaseEndpoints(this ISchema @this, IDataSource dataSour
field.Metadata.Add(ColumnName, column.Name);
field.Metadata.Add(ColumnType, column.DataTypeHandle);

graphOrderByEnum.AddOrderBy(new(column.Name, Sort.Ascending));
graphOrderByEnum.AddOrderBy(new(column.Name, Sort.Descending));
graphOrderByEnum.AddOrderBy(column.Name);
}

if ((objectSchema.Type is DatabaseObjectType.Table || objectSchema.Type is DatabaseObjectType.View) && actions.HasFlag(SqlApiAction.Select))
Expand All @@ -226,7 +224,7 @@ public static void AddDatabaseEndpoints(this ISchema @this, IDataSource dataSour

arguments.Add<bool>(nameof(SelectQuery.Distinct), defaultValue: false);
arguments.Add<string>(nameof(SelectQuery.Where), nullable: true, description: "If `where` is omitted, all records will be returned.");
arguments.Add(nameof(SelectQuery.OrderBy), new ListGraphType(new NonNullGraphType(graphOrderByEnum)), Array<OrderBy>.Empty);
arguments.Add(nameof(SelectQuery.OrderBy), new ListGraphType(new NonNullGraphType(graphOrderByEnum)));
arguments.Add<uint>(nameof(SelectQuery.Fetch), defaultValue: 0U);
arguments.Add<uint>(nameof(SelectQuery.Offset), defaultValue: 0U);
arguments.Add<uint>(nameof(SqlCommand.Timeout), defaultValue: 120U);
Expand Down Expand Up @@ -314,7 +312,7 @@ public static void AddDatabaseEndpoints(this ISchema @this, IDataSource dataSour

arguments.Add<bool>(nameof(SelectQuery.Distinct), defaultValue: false);
arguments.Add<string>(nameof(SelectQuery.Where), nullable: true, description: "If `where` is omitted, all records will be returned.");
arguments.Add(nameof(SelectQuery.OrderBy), new ListGraphType(new NonNullGraphType(graphOrderByEnum)), Array<OrderBy>.Empty);
arguments.Add(nameof(SelectQuery.OrderBy), new ListGraphType(new NonNullGraphType(graphOrderByEnum)));
arguments.Add<uint>(nameof(SelectQuery.Fetch), defaultValue: 0U);
arguments.Add<uint>(nameof(SelectQuery.Offset), defaultValue: 0U);
arguments.Add<uint>(nameof(SqlCommand.Timeout), defaultValue: 120U);
Expand Down Expand Up @@ -1007,8 +1005,7 @@ public static FieldType AddSqlApiInsertEndpoint<T>(this ISchema @this, IDataSour

var ascending = Sort.Ascending.ToSQL();
graphOrderByEnum.Add(Invariant($"{propertyName}_{ascending}"), Invariant($"{propertyName} {ascending}"), Invariant($"{propertyName} {ascending}"), propertyDeprecationReason);
graphOrderByEnum.AddOrderBy(new(propertyName, Sort.Ascending), propertyDeprecationReason);
graphOrderByEnum.AddOrderBy(new(propertyName, Sort.Descending), propertyDeprecationReason);
graphOrderByEnum.AddOrderBy(propertyName, propertyDeprecationReason);
}

var arguments = new QueryArguments();
Expand All @@ -1019,7 +1016,7 @@ public static FieldType AddSqlApiInsertEndpoint<T>(this ISchema @this, IDataSour
arguments.Add<bool>(nameof(SelectQuery.Distinct), defaultValue: false);
arguments.Add<string>(nameof(SelectQuery.From), description: "The table or view to pull the data from to insert.");
arguments.Add<string>(nameof(SelectQuery.Where), nullable: true, description: "If `where` is omitted, all records will be returned.");
arguments.Add(nameof(SelectQuery.OrderBy), new ListGraphType(new NonNullGraphType(graphOrderByEnum)), Array<OrderBy>.Empty);
arguments.Add(nameof(SelectQuery.OrderBy), new ListGraphType(new NonNullGraphType(graphOrderByEnum)));
arguments.Add<uint>(nameof(SelectQuery.Fetch), defaultValue: 0U);
arguments.Add<uint>(nameof(SelectQuery.Offset), defaultValue: 0U);
arguments.Add<uint>(nameof(SqlCommand.Timeout), defaultValue: 120U, description: "SQL Command timeout in seconds.");
Expand Down Expand Up @@ -1064,18 +1061,17 @@ public static FieldType AddSqlApiSelectEndpoint<T>(this ISchema @this, IDataSour
var propertyName = property.GraphQLName();
var propertyDeprecationReason = property.GraphQLDeprecationReason();

graphOrderByEnum.AddOrderBy(new(propertyName, Sort.Ascending), propertyDeprecationReason);
graphOrderByEnum.AddOrderBy(new(propertyName, Sort.Descending), propertyDeprecationReason);
graphOrderByEnum.AddOrderBy(propertyName, propertyDeprecationReason);
}

var arguments = new QueryArguments();
arguments.Add<Parameter[]>("parameters", nullable: true, description: "Used to reference user input values from the where clause.");
if (dataSource.Type is DataSourceType.SqlServer)
arguments.Add<GraphQLScalarType<string>>(nameof(SelectQuery.Top));
arguments.Add<uint>(nameof(SelectQuery.Top), nullable: true);

arguments.Add<bool>(nameof(SelectQuery.Distinct), defaultValue: false);
arguments.Add<string>(nameof(SelectQuery.Where), nullable: true, description: "If `where` is omitted, all records will be returned.");
arguments.Add(nameof(SelectQuery.OrderBy), new ListGraphType(new NonNullGraphType(graphOrderByEnum)), Array<OrderBy>.Empty);
arguments.Add(nameof(SelectQuery.OrderBy), new ListGraphType(new NonNullGraphType(graphOrderByEnum)));
arguments.Add<uint>(nameof(SelectQuery.Fetch), defaultValue: 0U);
arguments.Add<uint>(nameof(SelectQuery.Offset), defaultValue: 0U);
arguments.Add<uint>(nameof(SqlCommand.Timeout), defaultValue: 120U, description: "SQL Command timeout in seconds.");
Expand Down
4 changes: 2 additions & 2 deletions src/TypeCache.GraphQL/Resolvers/SqlApiInsertFieldResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public sealed class SqlApiInsertFieldResolver : FieldResolver
From = objectSchema.DataSource.CreateName(context.GetArgument<string>(nameof(SelectQuery.From))),
Fetch = context.GetArgument<uint>(nameof(SelectQuery.Fetch)),
Offset = context.GetArgument<uint>(nameof(SelectQuery.Offset)),
OrderBy = context.GetArgument<OrderBy[]>(nameof(SelectQuery.OrderBy)).Select(_ => _.ToString()).ToArray(),
OrderBy = context.GetArgument<string[]>(nameof(SelectQuery.OrderBy)),
Select = objectSchema.Columns
.Where(column => select.Any(_ => _.Right(Invariant($"{nameof(SelectQuery.Select)}.{column.Name}"))))
.Select(column => column.Name)
Expand Down Expand Up @@ -101,7 +101,7 @@ public sealed class SqlApiInsertFieldResolver<T> : FieldResolver
From = objectSchema.DataSource.CreateName(context.GetArgument<string>(nameof(SelectQuery.From))),
Fetch = context.GetArgument<uint>(nameof(SelectQuery.Fetch)),
Offset = context.GetArgument<uint>(nameof(SelectQuery.Offset)),
OrderBy = context.GetArgument<OrderBy[]>(nameof(SelectQuery.OrderBy)).Select(_ => _.ToString()).ToArray(),
OrderBy = context.GetArgument<string[]>(nameof(SelectQuery.OrderBy)),
Select = objectSchema.Columns
.Where(column => select.Any(_ => _.Right(Invariant($"{nameof(SelectQuery.Select)}.{column.Name}"))))
.Select(column => column.Name)
Expand Down
4 changes: 2 additions & 2 deletions src/TypeCache.GraphQL/Resolvers/SqlApiSelectFieldResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed class SqlApiSelectFieldResolver : FieldResolver
.Select(column => column.Name)
.ToArray(),
TableHints = objectSchema.DataSource.Type is SqlServer ? "NOLOCK" : null,
Top = context.GetArgument<string>(nameof(SelectQuery.Top)),
Top = context.GetArgument<uint>(nameof(SelectQuery.Top)).ToString(),
Where = context.GetArgument<string>(nameof(SelectQuery.Where))
};
var sql = objectSchema.CreateSelectSQL(select);
Expand Down Expand Up @@ -113,7 +113,7 @@ public sealed class SqlApiSelectFieldResolver<T> : FieldResolver
.Select(column => column.Name)
.ToArray(),
TableHints = objectSchema.DataSource.Type is SqlServer ? "NOLOCK" : null,
Top = context.GetArgument<string>(nameof(SelectQuery.Top)),
Top = context.GetArgument<uint>(nameof(SelectQuery.Top)).ToString(),
Where = context.GetArgument<string>(nameof(SelectQuery.Where))
};
var sql = objectSchema.CreateSelectSQL(select);
Expand Down
15 changes: 0 additions & 15 deletions src/TypeCache.GraphQL/SqlApi/OrderBy.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/TypeCache.GraphQL/TypeCache.GraphQL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<RootNamespace>TypeCache.GraphQL</RootNamespace>
<PackageId>TypeCache.GraphQL</PackageId>
<Version>8.1.3</Version>
<Version>8.1.4</Version>
<Authors>Samuel Abraham &lt;sam987883@gmail.com&gt;</Authors>
<Company>Samuel Abraham &lt;sam987883@gmail.com&gt;</Company>
<Title>TypeCache GraphQL</Title>
Expand Down

0 comments on commit 7d052d6

Please sign in to comment.