├── .editorconfig
├── .filenesting.json
├── .github
├── FUNDING.yml
└── workflows
│ └── dotnet-core.yml
├── .gitignore
├── LICENSE.txt
├── README.md
├── TypeCache.sln
├── TypeCash.png
├── src
├── TypeCache.GraphQL
│ ├── Attributes
│ │ ├── GraphQLDeprecationReasonAttribute.cs
│ │ ├── GraphQLDescriptionAttribute.cs
│ │ ├── GraphQLIgnoreAttribute.cs
│ │ ├── GraphQLInputNameAttribute.cs
│ │ ├── GraphQLMutationAttribute.cs
│ │ ├── GraphQLNameAttribute.cs
│ │ ├── GraphQLQueryAttribute.cs
│ │ ├── GraphQLSubscriptionAttribute.cs
│ │ └── GraphQLTypeAttribute.cs
│ ├── Converters
│ │ ├── GraphQLExecutionErrorJsonConverter.cs
│ │ └── GraphQLExecutionResultJsonConverter.cs
│ ├── Data
│ │ ├── Connection.cs
│ │ ├── Edge.cs
│ │ └── PageInfo.cs
│ ├── Extensions
│ │ ├── ApplicationBuilderExtensions.cs
│ │ ├── AttributeExtensions.cs
│ │ ├── EnumExtensions.cs
│ │ ├── GraphQLExtensions.cs
│ │ ├── QueryArgumentsExtensions.cs
│ │ ├── ResolveFieldContextExtensions.cs
│ │ ├── SchemaExtensions.cs
│ │ ├── ServiceCollectionExtensions.cs
│ │ └── TypeScriptExtensions.cs
│ ├── GlobalUsings.cs
│ ├── Listeners
│ │ └── DefaultDocumentExecutionListener.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── README.md
│ ├── Resolvers
│ │ ├── BatchCollectionFieldResolver.cs
│ │ ├── BatchItemFieldResolver.cs
│ │ ├── CustomFieldResolver.cs
│ │ ├── CustomSourceStreamResolver.cs
│ │ ├── DatabaseSchemaFieldResolver.cs
│ │ ├── FieldResolver.cs
│ │ ├── ItemFieldResolver.cs
│ │ ├── MethodFieldResolver.cs
│ │ ├── MethodSourceStreamResolver.cs
│ │ ├── ObservableFromAsyncEnumerable.cs
│ │ ├── PropertyFieldResolver.cs
│ │ ├── SourceStreamResolver.cs
│ │ ├── SqlApiCallFieldResolver.cs
│ │ ├── SqlApiDeleteFieldResolver.cs
│ │ ├── SqlApiInsertFieldResolver.cs
│ │ ├── SqlApiSelectFieldResolver.cs
│ │ ├── SqlApiUpdateFieldResolver.cs
│ │ └── StringCase.cs
│ ├── SqlApi
│ │ ├── DataResponse.cs
│ │ ├── OutputResponse.cs
│ │ ├── Parameter.cs
│ │ └── SelectResponse.cs
│ ├── TypeCache.GraphQL.csproj
│ ├── Types
│ │ ├── ConfigureSchema.cs
│ │ ├── EnumGraphType.cs
│ │ ├── HashIdGraphType.cs
│ │ ├── InputGraphType.cs
│ │ ├── InterfaceGraphType.cs
│ │ └── OutputGraphType.cs
│ └── Web
│ │ ├── GraphQLMiddleware.cs
│ │ ├── GraphQLRequest.cs
│ │ └── GraphQLSerializer.cs
├── TypeCache.Web
│ ├── Attributes
│ │ ├── RequireClaimAttribute.cs
│ │ └── RequireHeaderAttribute.cs
│ ├── Extensions
│ │ ├── ApplicationBuilderExtensions.cs
│ │ ├── AuthorizationHandlerContextExtensions.cs
│ │ ├── AuthorizationOptionsExtensions.cs
│ │ ├── ClaimsPrincipalExtensions.cs
│ │ ├── EndpointRouteBuilderExtensions.API.cs
│ │ ├── EndpointRouteBuilderExtensions.SQL.cs
│ │ ├── EndpointRouteBuilderExtensions.cs
│ │ ├── HttpContextExtensions.cs
│ │ ├── HttpRequestExtensions.cs
│ │ └── ServiceCollectionExtensions.cs
│ ├── Filters
│ │ ├── SqlApiProcedureEndpointFilter.cs
│ │ ├── SqlApiSchemaEndpointFilter.cs
│ │ └── SqlApiTableEndpointFilter.cs
│ ├── GlobalUsings.cs
│ ├── Handlers
│ │ ├── ClaimAuthorizationHandler.cs
│ │ ├── HeaderAuthorizationHandler.cs
│ │ ├── SelectParameter.cs
│ │ ├── SqlApiHandler.cs
│ │ └── SqlHandler.cs
│ ├── Mediation
│ │ ├── HttpClientRequest.cs
│ │ ├── HttpClientRule.cs
│ │ └── HttpClientValidationRule.cs
│ ├── Middleware
│ │ └── SqlApiErrorHandlerMiddleware.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── README.md
│ ├── Requirements
│ │ ├── ClaimAuthorizationRequirement.cs
│ │ └── HeaderAuthorizationRequirement.cs
│ └── TypeCache.Web.csproj
└── TypeCache
│ ├── Attributes
│ ├── MapAttribute.cs
│ ├── MapIgnoreAttribute.cs
│ ├── ScopedAttribute.cs
│ ├── ServiceLifetimeAttribute.cs
│ ├── SingletonAttribute.cs
│ ├── SqlApiAction.cs
│ ├── SqlApiAttribute.cs
│ └── TransientAttribute.cs
│ ├── Converters
│ ├── BigIntegerJsonConverter.cs
│ ├── DataRowJsonConverter.cs
│ ├── DataSetJsonConverter.cs
│ ├── DataTableJsonConverter.cs
│ ├── DataViewJsonConverter.cs
│ ├── DictionaryJsonConverter.cs
│ ├── FieldJsonConverter.cs
│ ├── PropertyJsonConverter.cs
│ ├── ReadOnlyDictionaryJsonConverter.cs
│ ├── StringValuesJsonConverter.cs
│ └── ValueJsonConverter.cs
│ ├── Data
│ ├── ColumnSchema.cs
│ ├── ComparisonOperator.cs
│ ├── DataSource.cs
│ ├── DataSourceType.cs
│ ├── DatabaseObjectType.cs
│ ├── Extensions
│ │ ├── DbCommandExtensions.cs
│ │ ├── DbConnectionExtensions.cs
│ │ ├── DbDataReaderExtensions.cs
│ │ ├── DbProviderFactoryExtensions.cs
│ │ ├── EnumExtensions.cs
│ │ ├── SqlCommandExtensions.cs
│ │ ├── SqlExtensions.cs
│ │ └── StringBuilderExtensions.cs
│ ├── IDataSource.cs
│ ├── LogicalOperator.cs
│ ├── Mediation
│ │ ├── SqlDataSetRule.cs
│ │ ├── SqlDataTableRule.cs
│ │ ├── SqlExecuteRule.cs
│ │ ├── SqlResultJsonRule.cs
│ │ ├── SqlResultSetJsonRule.cs
│ │ ├── SqlResultsRule.cs
│ │ └── SqlScalarRule.cs
│ ├── ObjectSchema.cs
│ ├── ParameterSchema.cs
│ ├── SchemaCollection.cs
│ ├── SchemaColumn.cs
│ ├── SelectQuery.cs
│ ├── Sort.cs
│ └── SqlCommand.cs
│ ├── Extensions
│ ├── ActionExtensions.cs
│ ├── ArrayExtensions.cs
│ ├── AssemblyExtensions.cs
│ ├── AsyncEnumeratorExtensions.cs
│ ├── BooleanExtensions.cs
│ ├── CharExtensions.cs
│ ├── ComparableExtensions.cs
│ ├── ComparerExtensions.cs
│ ├── CsvExtensions.cs
│ ├── DateTimeExtensions.cs
│ ├── DictionaryExtensions.cs
│ ├── EnumExtensions.CollectionType.cs
│ ├── EnumExtensions.ScalarType.cs
│ ├── EnumExtensions.cs
│ ├── EnumerableExtensions.cs
│ ├── EnumeratorExtensions.cs
│ ├── EqualityComparerExtensions.cs
│ ├── EquatableExtensions.cs
│ ├── ExpressionExtensions.ArrayExpressionBuilder.cs
│ ├── ExpressionExtensions.BinaryOperator.cs
│ ├── ExpressionExtensions.LabelTarget.cs
│ ├── ExpressionExtensions.UnaryOperator.cs
│ ├── ExpressionExtensions.cs
│ ├── FuncExtensions.cs
│ ├── GlobalExtensions.cs
│ ├── IndexExtensions.cs
│ ├── JsonExtensions.cs
│ ├── ListExtensions.cs
│ ├── LoggerExtensions.cs
│ ├── MapExtensions.cs
│ ├── NumericExtensions.Double.cs
│ ├── NumericExtensions.FloatingPoint.cs
│ ├── NumericExtensions.FloatingPointIeee754.cs
│ ├── NumericExtensions.Int32.cs
│ ├── NumericExtensions.Number.cs
│ ├── NumericExtensions.NumberBase.cs
│ ├── NumericExtensions.cs
│ ├── ObjectExtensions.cs
│ ├── ParallelExtensions.cs
│ ├── RangeExtensions.cs
│ ├── ReadOnlySpanExtensions.cs
│ ├── ReflectionExtensions.CollectionType.cs
│ ├── ReflectionExtensions.ConstructorInfo.cs
│ ├── ReflectionExtensions.Delegate.cs
│ ├── ReflectionExtensions.FieldInfo.cs
│ ├── ReflectionExtensions.Handles.cs
│ ├── ReflectionExtensions.MemberInfo.cs
│ ├── ReflectionExtensions.MethodBase.cs
│ ├── ReflectionExtensions.MethodInfo.cs
│ ├── ReflectionExtensions.ObjectType.cs
│ ├── ReflectionExtensions.ParameterInfo.cs
│ ├── ReflectionExtensions.PropertyInfo.cs
│ ├── ReflectionExtensions.ScalarType.cs
│ ├── ReflectionExtensions.Type.cs
│ ├── ReflectionExtensions.cs
│ ├── RuneExtensions.cs
│ ├── ServiceCollectionExtensions.cs
│ ├── SetExtensions.cs
│ ├── SpanExtensions.cs
│ ├── StringBuilderExtensions.cs
│ ├── StringExtensions.cs
│ └── TaskExtensions.cs
│ ├── GlobalUsings.cs
│ ├── Mediation
│ ├── CustomAfterRule.cs
│ ├── CustomRule.cs
│ ├── CustomValidationRule.cs
│ ├── IAfterRule.cs
│ ├── IMediator.cs
│ ├── IRequest.cs
│ ├── IRule.cs
│ ├── IValidationRule.cs
│ ├── Mediator.cs
│ └── RuleFactory.cs
│ ├── README.md
│ ├── TypeCache.csproj
│ └── Utilities
│ ├── Array.cs
│ ├── CustomObservable.cs
│ ├── CustomStringWriter.cs
│ ├── Enum.cs
│ ├── EnumComparer.cs
│ ├── Enumerable.cs
│ ├── EventHandler.cs
│ ├── HashMaker.cs
│ ├── IHashMaker.cs
│ ├── LambdaFactory.cs
│ ├── LazyDictionary.cs
│ ├── ObservableAdapter.cs
│ ├── ObserverAdapter.cs
│ ├── Sequence.cs
│ ├── Singleton.cs
│ ├── TypeStore.cs
│ ├── ValueBox.cs
│ └── ValueConverter.cs
└── tests
├── TypeCache.GraphQL.TestApp
├── Models
│ └── Detail.cs
├── Program.cs
├── Properties
│ └── launchSettings.json
├── Tables
│ ├── Person.cs
│ ├── Product.cs
│ └── WorkOrder.cs
├── TypeCache.GraphQL.TestApp.csproj
└── appsettings.json
└── TypeCache.Tests
├── AssemblyInfo.cs
├── Converters
└── JsonConverterTests.cs
├── Data
└── Extensions
│ ├── DbDataReaderExtensions.cs
│ └── SqlExtensions.cs
├── Extensions
├── ActionExtensions.cs
├── ArrayExtensions.cs
├── BooleanExtensions.cs
├── CharExtensions.cs
├── ComparableExtensions.cs
├── ComparerExtensions.cs
├── DateTimeExtensions.cs
├── DictionaryExtensions.cs
├── EnumExtensions.cs
├── EnumerableExtensions.cs
├── EnumeratorExtensions.cs
├── EqualityComparerExtensions.cs
├── EquatableExtensions.cs
├── FuncExtensions.cs
├── GlobalExtensions.cs
├── IndexExtensions.cs
├── JsonExtensions.cs
├── ListExtensions.cs
├── MapExtensions.cs
├── MathExtensions.cs
├── NumericExtensions.cs
├── ObjectExtensions.cs
├── RangeExtensions.cs
├── ReadOnlySpanExtensions.cs
├── ReflectionExtensions.cs
├── RuneExtensions.cs
├── StringExtensions.cs
└── ValueExtensions.cs
├── TypeCache.Tests.csproj
└── Utilities
├── EnumTests.cs
├── EventOfTests.cs
└── HashMakerTests.cs
/.filenesting.json:
--------------------------------------------------------------------------------
1 | {
2 | "help":"https://go.microsoft.com/fwlink/?linkid=866610"
3 | }
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: sam987883
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: ['https://www.paypal.com/paypalme/sam987883']
13 |
--------------------------------------------------------------------------------
/.github/workflows/dotnet-core.yml:
--------------------------------------------------------------------------------
1 | name: .NET9
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: Setup .NET9
17 | uses: actions/setup-dotnet@v1
18 | with:
19 | dotnet-version: 9.0.x
20 | - name: Install dependencies
21 | run: dotnet restore
22 | - name: Build
23 | run: dotnet build --configuration Release --no-restore
24 | - name: Test
25 | run: dotnet test --no-restore --verbosity normal
26 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Samuel Abraham
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TypeCache
2 | TypeCache is a fast alternative to System.Reflection.
3 |
--------------------------------------------------------------------------------
/TypeCash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sam987883/TypeCache/db8844e4a13fdd50420a20791cd60f27314f863e/TypeCash.png
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Attributes/GraphQLDeprecationReasonAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using TypeCache.Extensions;
4 |
5 | namespace TypeCache.GraphQL.Attributes;
6 |
7 | ///
8 | /// GraphQL
9 | /// Sets the deprecation reason of the object type, object property, enum type, enum field, endpoint or endpoint parameter.
10 | ///
11 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue | AttributeTargets.Struct)]
12 | public sealed class GraphQLDeprecationReasonAttribute(string deprecationReason) : Attribute
13 | {
14 | public string DeprecationReason { get; } = deprecationReason;
15 | }
16 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Attributes/GraphQLDescriptionAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using TypeCache.Extensions;
4 |
5 | namespace TypeCache.GraphQL.Attributes;
6 |
7 | ///
8 | /// GraphQL
9 | /// Sets the description of the object type, object property, enum type, enum field, endpoint or endpoint parameter.
10 | ///
11 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue | AttributeTargets.Struct)]
12 | public sealed class GraphQLDescriptionAttribute(string description) : Attribute
13 | {
14 | public string Description { get; } = description;
15 | }
16 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Attributes/GraphQLIgnoreAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | namespace TypeCache.GraphQL.Attributes;
4 |
5 | ///
6 | /// GraphQL
7 | /// Ignore a parameter, enum field or property.
8 | ///
9 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)]
10 | public sealed class GraphQLIgnoreAttribute : Attribute
11 | {
12 | }
13 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Attributes/GraphQLInputNameAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using TypeCache.Extensions;
4 |
5 | namespace TypeCache.GraphQL.Attributes;
6 |
7 | ///
8 | /// GraphQL
9 | /// Sets the name of the input type.
10 | ///
11 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
12 | public sealed class GraphQLInputNameAttribute(string name) : Attribute
13 | {
14 | public string Name { get; } = name;
15 | }
16 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Attributes/GraphQLMutationAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | namespace TypeCache.GraphQL.Attributes;
4 |
5 | ///
6 | /// GraphQL
7 | /// Marks a method to be used as a root level Mutation endpoint.
8 | ///
9 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
10 | public sealed class GraphQLMutationAttribute : Attribute
11 | {
12 | }
13 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Attributes/GraphQLNameAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using TypeCache.Extensions;
4 |
5 | namespace TypeCache.GraphQL.Attributes;
6 |
7 | ///
8 | /// GraphQL
9 | /// Sets the name of the object type, object property, enum type, enum field, endpoint or endpoint parameter.
10 | ///
11 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue | AttributeTargets.Struct)]
12 | public sealed class GraphQLNameAttribute(string name) : Attribute
13 | {
14 | public string Name { get; } = name;
15 | }
16 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Attributes/GraphQLQueryAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | namespace TypeCache.GraphQL.Attributes;
4 |
5 | ///
6 | /// GraphQL
7 | /// Marks a method to be used as a root level Query endpoint.
8 | ///
9 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
10 | public sealed class GraphQLQueryAttribute : Attribute
11 | {
12 | }
13 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Attributes/GraphQLSubscriptionAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | namespace TypeCache.GraphQL.Attributes;
4 |
5 | ///
6 | /// GraphQL
7 | /// Marks a method to be used as a Subscriber endpoint.
8 | ///
9 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
10 | public sealed class GraphQLSubscriptionAttribute : Attribute
11 | {
12 | }
13 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Attributes/GraphQLTypeAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using GraphQL;
4 | using GraphQL.Types;
5 |
6 | namespace TypeCache.GraphQL.Attributes;
7 |
8 | public abstract class GraphQLTypeAttribute : Attribute
9 | {
10 | }
11 |
12 | ///
13 | /// GraphQL
14 | /// If the parameter a type of or , then it will not show up in the endpoint-
15 | /// Instead it will be injected with the instance of or .
16 | ///
17 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = false)]
18 | public sealed class GraphQLTypeAttribute : GraphQLTypeAttribute
19 | where T : IGraphType
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Converters/GraphQLExecutionErrorJsonConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using System.Text.Json;
4 | using System.Text.Json.Serialization;
5 | using GraphQL;
6 | using TypeCache.Extensions;
7 |
8 | namespace TypeCache.GraphQL.Converters;
9 |
10 | public sealed class GraphQLExecutionErrorJsonConverter : JsonConverter
11 | {
12 | ///
13 | public override ExecutionError Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
14 | => throw new NotImplementedException();
15 |
16 | public override void Write(Utf8JsonWriter writer, ExecutionError? value, JsonSerializerOptions options)
17 | {
18 | if (value is null)
19 | {
20 | writer.WriteNullValue();
21 | return;
22 | }
23 |
24 | writer.WriteStartObject();
25 | writer.WriteString("message", value.Message);
26 |
27 | if (value.Locations is not null)
28 | {
29 | writer.WritePropertyName("locations");
30 | JsonSerializer.Serialize(writer, value.Locations, options);
31 | }
32 |
33 | if (value.Path?.Any() is true)
34 | {
35 | writer.WritePropertyName("path");
36 | JsonSerializer.Serialize(writer, value.Path, options);
37 | }
38 |
39 | if (value.Extensions?.Any() is true)
40 | {
41 | writer.WritePropertyName("extensions");
42 | JsonSerializer.Serialize(writer, value.Extensions, options);
43 | }
44 |
45 | writer.WriteEndObject();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Data/Edge.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using GraphQL.Resolvers;
4 | using GraphQL.Types;
5 | using TypeCache.Extensions;
6 | using TypeCache.GraphQL.Attributes;
7 | using TypeCache.GraphQL.Extensions;
8 |
9 | namespace TypeCache.GraphQL.Data;
10 |
11 | [GraphQLDescription("An edge in a connection that associates a cursor ID with data.")]
12 | public readonly record struct Edge(
13 | [GraphQLDescription("An identification number for use in pagination.")] int Cursor
14 | , [GraphQLDescription("The data item associated with the cursor value.")] T Node)
15 | where T : notnull
16 | {
17 | public static ObjectGraphType CreateGraphType(string name, IGraphType dataGraphType)
18 | {
19 | var graphType = new ObjectGraphType
20 | {
21 | Name = Invariant($"{name}{nameof(Edge)}"),
22 | Description = typeof(Edge).GraphQLDescription()
23 | };
24 |
25 | graphType.AddField(new()
26 | {
27 | Name = nameof(Edge.Cursor),
28 | Type = ScalarType.Int32.ToGraphType(),
29 | Resolver = new FuncFieldResolver, int>(context => context.Source.Cursor)
30 | });
31 | graphType.AddField(new()
32 | {
33 | Name = nameof(Edge.Node),
34 | ResolvedType = new NonNullGraphType(dataGraphType),
35 | Resolver = new FuncFieldResolver, T>(context => context.Source.Node)
36 | });
37 |
38 | return graphType;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Data/PageInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using TypeCache.GraphQL.Attributes;
4 |
5 | namespace TypeCache.GraphQL.Data;
6 |
7 | [GraphQLDescription("Information about pagination in a connection.")]
8 | public readonly record struct PageInfo(
9 | [GraphQLDescription("The first cursor value of the current page.")] int StartCursor
10 | , [GraphQLDescription("The last cursor value of the current page.")] int EndCursor
11 | , [GraphQLDescription("Whether a page exists before the current page.")] bool HasPreviousPage
12 | , [GraphQLDescription("Whether a page exists after the current page.")] bool HasNextPage)
13 | {
14 | public PageInfo(uint offset, uint fetch, int totalCount)
15 | : this((int)offset + 1, (int)(offset + fetch), offset > 0, (offset + fetch) < totalCount)
16 | {
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Extensions/ApplicationBuilderExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using GraphQL;
4 | using GraphQL.DI;
5 | using GraphQL.Types;
6 | using Microsoft.AspNetCore.Builder;
7 | using Microsoft.AspNetCore.Http;
8 | using TypeCache.GraphQL.Types;
9 | using TypeCache.GraphQL.Web;
10 |
11 | namespace TypeCache.GraphQL.Extensions;
12 |
13 | public static class ApplicationBuilderExtensions
14 | {
15 | ///
16 | /// => @.UseMiddleware<>(, ());
17 | ///
18 | /// The route to use for this instance.
19 | public static IApplicationBuilder UseGraphQLSchema(this IApplicationBuilder @this, PathString route, IConfigureSchema configureSchema)
20 | => @this.UseMiddleware(route, configureSchema);
21 |
22 | ///
23 | /// => @.UseMiddleware<>(, ());
24 | ///
25 | /// The route to use for this instance.
26 | public static IApplicationBuilder UseGraphQLSchema(this IApplicationBuilder @this, PathString route, Action configureSchema)
27 | => @this.UseMiddleware(route, new ConfigureSchema(configureSchema));
28 | }
29 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Extensions/EnumExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using global::GraphQL.Types;
4 | using TypeCache.Extensions;
5 |
6 | namespace TypeCache.GraphQL.Extensions;
7 |
8 | public static class EnumExtensions
9 | {
10 | public static Type? ToGraphType(this ScalarType @this)
11 | => @this switch
12 | {
13 | ScalarType.Boolean => typeof(BooleanGraphType),
14 | ScalarType.SByte => typeof(SByteGraphType),
15 | ScalarType.Int16 => typeof(ShortGraphType),
16 | ScalarType.Int32 or ScalarType.Index => typeof(IntGraphType),
17 | ScalarType.Int64 or ScalarType.IntPtr => typeof(LongGraphType),
18 | ScalarType.BigInteger or ScalarType.Int128 or ScalarType.UInt128 => typeof(BigIntGraphType),
19 | ScalarType.Byte => typeof(ByteGraphType),
20 | ScalarType.UInt16 => typeof(UShortGraphType),
21 | ScalarType.UInt32 => typeof(UIntGraphType),
22 | ScalarType.UInt64 or ScalarType.UIntPtr => typeof(ULongGraphType),
23 | ScalarType.Half => typeof(HalfGraphType),
24 | ScalarType.Single or ScalarType.Double => typeof(FloatGraphType),
25 | ScalarType.Decimal => typeof(DecimalGraphType),
26 | ScalarType.DateOnly => typeof(DateOnlyGraphType),
27 | ScalarType.DateTime => typeof(DateTimeGraphType),
28 | ScalarType.DateTimeOffset => typeof(DateTimeOffsetGraphType),
29 | ScalarType.TimeOnly => typeof(TimeOnlyGraphType),
30 | ScalarType.TimeSpan => typeof(TimeSpanSecondsGraphType),
31 | ScalarType.Guid => typeof(GuidGraphType),
32 | ScalarType.String or ScalarType.Char => typeof(StringGraphType),
33 | ScalarType.Uri => typeof(UriGraphType),
34 | _ => null
35 | };
36 | }
37 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/GlobalUsings.cs:
--------------------------------------------------------------------------------
1 | global using System;
2 | global using System.Buffers.Text;
3 | global using System.Diagnostics;
4 | global using System.Diagnostics.CodeAnalysis;
5 | global using static System.FormattableString;
6 | global using static System.Runtime.CompilerServices.MethodImplOptions;
7 | global using CancellationToken = System.Threading.CancellationToken;
8 | global using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
9 | global using Task = System.Threading.Tasks.Task;
10 | global using ValueTask = System.Threading.Tasks.ValueTask;
11 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Listeners/DefaultDocumentExecutionListener.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using GraphQL.Execution;
4 |
5 | namespace TypeCache.GraphQL.Listeners;
6 |
7 | internal sealed class DefaultDocumentExecutionListener : DocumentExecutionListenerBase
8 | {
9 | }
10 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "TypeCache.GraphQL": {
4 | "commandName": "Project",
5 | "launchBrowser": true,
6 | "environmentVariables": {
7 | "ASPNETCORE_ENVIRONMENT": "Development"
8 | },
9 | "applicationUrl": "https://localhost:56443;http://localhost:56444"
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/README.md:
--------------------------------------------------------------------------------
1 | ># TypeCache - GraphQL
2 | ###### sam987883@gmail.com
3 |
4 | [**Source Code**](https://github.com/sam987883/TypeCache/tree/master/src/TypeCache.GraphQL)
5 |
6 | [Request Features (or report a bug) (if any)](https://github.com/sam987883/TypeCache/issues)
7 |
8 | ---
9 | ### `TypeCache.GraphQL.Types` - GraphQL Type Objects
10 |
11 | - `GraphQLEnumType`
12 | - `GraphQLHashIdType`
13 | - `GraphQLInputType`
14 | - `GraphQLInterfaceType`
15 | - `GraphQLObjectType`
16 | - `GraphQLScalarType`
17 | - `GraphQLUnionType`
18 | - `GraphQLUriType`
19 | ---
20 | ### `TypeCache.GraphQL.Attributes` - GraphQL Attributes
21 |
22 | - `GraphQLDeprecationReasonAttribute`
23 | - `GraphQLDescriptionAttribute`
24 | - `GraphQLIgnoreAttribute`
25 | - `GraphQLInputNameAttribute`
26 | - `GraphQLMutationAttribute`
27 | - `GraphQLNameAttribute`
28 | - `GraphQLQueryAttribute`
29 | - `GraphQLSubscriptionAttribute`
30 | - `GraphQLTypeAttribute`
31 | ---
32 | ### `GraphQL.Types.ISchema` - GraphQL ISchema Extensions
33 |
34 | - `AddVersion(...)`
35 | - `AddDatabaseSchemaQueries(...)`
36 | - `AddDatabaseSchemaQuery(...)`
37 | - `AddDatabaseEndpoints(...)`
38 | - `AddEndpoints<>(...)`
39 | - `AddQuery(...)`
40 | - `AddQueries<>(...)`
41 | - `AddMutation(...)`
42 | - `AddMutations<>(...)`
43 | - `AddSubscription(...)`
44 | - `AddSubscriptions<>(...)`
45 | - `AddSqlApiEndpoints<>(...)`
46 | - `AddSqlApiCallProcedureEndpoint<>(...)`
47 | - `AddSqlApiDeleteDataEndpoint<>(...)`
48 | - `AddSqlApiDeleteEndpoint<>(...)`
49 | - `AddSqlApiInsertDataEndpoint<>(...)`
50 | - `AddSqlApiInsertEndpoint<>(...)`
51 | - `AddSqlApiSelectEndpoint<>(...)`
52 | - `AddSqlApiUpdateDataEndpoint<>(...)`
53 | - `AddSqlApiUpdateEndpoint<>(...)`
54 | ---
55 | ### `TypeCache.GraphQL.Types.GraphQLObject` - GraphQL GraphQLObject Extensions
56 |
57 | - `AddField(MethodInfo)`
58 | - `AddQueryItem(MethodInfo, Func, Func)`
59 | - `AddQueryCollection(MethodInfo, Func, Func)`
60 |
--------------------------------------------------------------------------------
/src/TypeCache.GraphQL/Resolvers/BatchCollectionFieldResolver.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 Samuel Abraham
2 |
3 | using System.Reflection;
4 | using TypeCache.Extensions;
5 | using TypeCache.GraphQL.Extensions;
6 | using IResolveFieldContext = global::GraphQL.IResolveFieldContext;
7 |
8 | namespace TypeCache.GraphQL.Resolvers;
9 |
10 | public sealed class BatchCollectionFieldResolver : FieldResolver
11 | where SOURCE : notnull
12 | where ITEM : notnull
13 | {
14 | private readonly Lock _Lock = new();
15 | private readonly RuntimeMethodHandle _MethodHandle;
16 | private readonly Func _GetResults;
17 | private bool _HasResults = false;
18 | private Task- ? _Results = null;
19 |
20 | ///
21 | ///
22 | public BatchCollectionFieldResolver(MethodInfo methodInfo, Func getResults)
23 | {
24 | methodInfo.ThrowIfNull();
25 | getResults.ThrowIfNull();
26 | methodInfo.IsStatic.ThrowIfFalse();
27 | methodInfo.ReturnType.IsAny, Task>, ValueTask>, ITEM[], Task
- , ValueTask
- >().ThrowIfFalse();
28 |
29 | this._MethodHandle = methodInfo.MethodHandle;
30 | this._GetResults = getResults;
31 | }
32 |
33 | ///
34 | protected override async ValueTask