diff --git a/DEVELOPER.md b/DEVELOPER.md new file mode 100644 index 00000000..80df6442 --- /dev/null +++ b/DEVELOPER.md @@ -0,0 +1,233 @@ +# Developer Guide + +This document provides comprehensive guidance for developers working on the Linq2GraphQL.Client project, particularly when modifying T4 templates and the code generation system. + +## Table of Contents + +- [Prerequisites](#prerequisites) +- [Project Structure](#project-structure) +- [T4 Template Development](#t4-template-development) +- [Code Generation Workflow](#code-generation-workflow) +- [Troubleshooting](#troubleshooting) +- [Best Practices](#best-practices) + +## Prerequisites + +- **Visual Studio 2022** (recommended) or Visual Studio 2019/2022 +- **.NET 8.0 SDK** or later +- **T4 Template Support** - Ensure the "Text Template Transformation" workload is installed in Visual Studio + +## Project Structure + +``` +src/ +├── Linq2GraphQL.Generator/ # Main code generation project +│ ├── Templates/ # T4 template files +│ │ ├── Client/ # Client generation templates +│ │ ├── Class/ # Class generation templates +│ │ ├── Interface/ # Interface generation templates +│ │ ├── Methods/ # Method generation templates +│ │ └── Enum/ # Enum generation templates +│ ├── GraphQLSchema/ # Schema parsing and processing +│ └── ClientGenerator.cs # Main generation orchestration +└── Linq2GraphQL.Client/ # Core client library +``` + +## T4 Template Development + +### Understanding T4 Templates + +This project uses **T4 (Text Template Transformation Toolkit)** for code generation. T4 templates are `.tt` files that generate C# source code based on GraphQL schema information. + +#### Template File Types + +- **`.tt`** - Source T4 template files (human-editable) +- **`.tt.cs`** - Partial class definitions for template variables and helper methods +- **`.cs`** - Preprocessed T4 templates (auto-generated, contains the actual `TransformText()` method) + +### Template Development Workflow + +#### 1. Modifying T4 Templates + +When modifying `.tt` files: + +1. **Edit the `.tt` file** with your changes +2. **Manually regenerate the `.cs` file** using Visual Studio's custom tool +3. **Build the project** to ensure compilation +4. **Test the generation** by running the client generator + +#### 2. Manual Template Regeneration + +**⚠️ IMPORTANT: After modifying any `.tt` file, you MUST manually regenerate the corresponding `.cs` file.** + +**In Visual Studio 2022:** + +1. Right-click on the `.tt` file in Solution Explorer +2. Select **"Run Custom Tool"** +3. This will regenerate the `.cs` file with your changes +4. Verify the `.cs` file contains your updated template logic + +**Alternative method:** +1. Right-click on the `.tt` file +2. Select **"Properties"** +3. Set **"Custom Tool"** to `TextTemplatingFilePreprocessor` +4. Set **"Custom Tool Namespace"** to your desired namespace +5. Save the file to trigger regeneration + +#### 3. Template File Dependencies + +Each T4 template requires: + +- **`.tt` file** - Contains the template logic and output format +- **`.tt.cs` file** - Provides the partial class with constructor parameters and helper methods +- **`.cs` file** - Auto-generated preprocessed template (regenerated from `.tt`) + +### Template Syntax + +#### Basic T4 Directives + +```t4 +<#@ template language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +``` + +#### Template Expressions + +```t4 +<#= variableName #> +<# if (condition) { #> + // C# code here +<# } #> +<# foreach (var item in collection) { #> + // Process each item +<# } #> +``` + +#### Helper Methods + +Define helper methods in the `.tt.cs` file: + +```csharp +public partial class TemplateName +{ + private readonly string variableName; + + public TemplateName(string variableName) + { + this.variableName = variableName; + } + + private string HelperMethod() + { + return "Helper logic here"; + } +} +``` + +## Code Generation Workflow + +### 1. Development Cycle + +``` +Edit .tt file → Run Custom Tool → Build Project → Test Generation → Repeat +``` + +### 2. Testing Changes + +After modifying templates: + +1. **Build the project** to ensure no compilation errors +2. **Run the client generator** to test template output +3. **Verify generated code** matches your expectations +4. **Test the generated client** in a sample application + +### 3. Command Line Generation + +```bash +# Build the generator project +dotnet build src/Linq2GraphQL.Generator + +# Generate a client +dotnet run --project src/Linq2GraphQL.Generator -- [options] +``` + +## Troubleshooting + +### Common Issues + +#### T4 Templates Not Regenerating + +**Problem:** Changes to `.tt` files not reflected in generated output. + +**Solution:** +1. Ensure you've run the **"Run Custom Tool"** on the `.tt` file +2. Check that the `.cs` file was updated with your changes +3. Clean and rebuild the project +4. Verify the T4 preprocessor is working in Visual Studio + +#### Missing TransformText Method + +**Problem:** Compilation error "does not contain a definition for 'TransformText'". + +**Solution:** +1. The `.cs` file is missing or outdated +2. Run **"Run Custom Tool"** on the corresponding `.tt` file +3. Ensure the `.tt.cs` file exists and has the correct partial class definition + +#### Template Variables Not Available + +**Problem:** Template variables like `namespaceName` or `name` are undefined. + +**Solution:** +1. Check the `.tt.cs` file has the correct constructor parameters +2. Verify the partial class has `readonly` fields for all template variables +3. Ensure the `ClientGenerator.cs` passes the correct parameters when instantiating templates + +### Debugging Tips + +1. **Check the `.cs` file content** - It should contain your template logic in the `TransformText()` method +2. **Verify template compilation** - Build errors often indicate template syntax issues +3. **Use Visual Studio's T4 debugging** - Set breakpoints in the generated `.cs` files +4. **Check build output** - Look for T4-related error messages + +## Best Practices + +### Template Design + +1. **Keep templates focused** - Each template should handle one specific aspect of code generation +2. **Use helper methods** - Move complex logic to the `.tt.cs` file +3. **Maintain readability** - Use clear variable names and consistent formatting +4. **Handle edge cases** - Always check for null values and empty collections + +### Code Organization + +1. **Separate concerns** - Keep template logic separate from business logic +2. **Use partial classes** - Leverage C# partial classes for template organization +3. **Consistent naming** - Follow the project's naming conventions +4. **Documentation** - Include XML comments in generated code + +### Testing + +1. **Test with various schemas** - Ensure templates work with different GraphQL schemas +2. **Validate generated code** - Check that generated code compiles and works correctly +3. **Regression testing** - Ensure changes don't break existing functionality +4. **Integration testing** - Test the complete generation pipeline + +### Version Control + +1. **Commit `.tt` and `.tt.cs` files** - These are source files +2. **Ignore generated `.cs` files** - Add `**/*.cs` to `.gitignore` for auto-generated files +3. **Document template changes** - Include clear commit messages for template modifications +4. **Review generated output** - Verify that template changes produce the expected results + +## Getting Help + +- **Check existing templates** - Review similar templates for examples +- **T4 documentation** - Microsoft's T4 documentation provides comprehensive guidance +- **Project issues** - Search existing GitHub issues for similar problems +- **Community support** - Reach out to the project maintainers or community + +--- + +**Note:** T4 template development requires careful attention to the regeneration workflow. Always remember to run the custom tool after modifying `.tt` files to ensure your changes are applied to the generated code. diff --git a/Directory.Packages.props b/Directory.Packages.props index 646757e3..ca66cbd4 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,43 +1,44 @@  - - true - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + true + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + \ No newline at end of file diff --git a/README.md b/README.md index d290d04e..8079bb45 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,20 @@ Turning on *SafeMode* will make the client before the first request to do an int # Acknowledgments Linq2GraphQL is inspired by [GraphQLinq](https://github.com/Giorgi/GraphQLinq) , thank you [Giorgi](https://github.com/Giorgi) +## Contributing + +Are you a developer looking to contribute to this project? Please see our [Developer Guide](DEVELOPER.md) for comprehensive information about: + +- T4 template development workflow +- Code generation system architecture +- Troubleshooting common issues +- Best practices for template development +- Manual template regeneration process + +## Development Workflow + +**⚠️ Important for Developers:** When modifying T4 templates (`.tt` files), you must manually regenerate the corresponding `.cs` files using Visual Studio's "Run Custom Tool" feature. See [DEVELOPER.md](DEVELOPER.md) for detailed instructions. + [![Stargazers repo roster for @linq2graphql/linq2graphql.client](https://reporoster.com/stars/dark/linq2graphql/linq2graphql.client)](https://github.com/linq2graphql/linq2graphql.client/stargazers) diff --git a/nuget.config b/nuget.config index cbdf0855..55dcc87d 100644 --- a/nuget.config +++ b/nuget.config @@ -2,6 +2,9 @@ - + + + + \ No newline at end of file diff --git a/nuget.config.backup b/nuget.config.backup new file mode 100644 index 00000000..cbdf0855 --- /dev/null +++ b/nuget.config.backup @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/Linq2GraphQL.Generator/ClientGenerator.cs b/src/Linq2GraphQL.Generator/ClientGenerator.cs index 804e282b..9fe195ec 100644 --- a/src/Linq2GraphQL.Generator/ClientGenerator.cs +++ b/src/Linq2GraphQL.Generator/ClientGenerator.cs @@ -104,16 +104,21 @@ public List Generate(string schemaJson) Console.WriteLine("Generate Interfaces"); - var classInterfacesList = schema.GetClassTypes().Where(e => e.HasInterfaces) - .SelectMany(i => i.Interfaces.ToDictionary(e => i.Name, e => e.Name)).ToList(); - foreach (var interfaceType in schema.GetInterfaces()) + var classInterfacesList = schema.GetClassTypes()?.Where(e => e.HasInterfaces) + ?.SelectMany(i => i.Interfaces?.ToDictionary(e => i.Name, e => e.Name))?.ToList() ?? new List>(); + + var interfaces = schema.GetInterfaces(); + if (interfaces != null) { - var implementedBy = classInterfacesList.Where(e => e.Value == interfaceType.Name).Select(e => e.Key) - .ToList(); - - var interfaceTemplte = - new InterfaceTemplate(interfaceType, namespaceName, implementedBy).TransformText(); - AddFile("Interfaces", interfaceType.FileName, interfaceTemplte); + foreach (var interfaceType in interfaces) + { + var implementedBy = classInterfacesList.Where(e => e.Value == interfaceType.Name).Select(e => e.Key) + .ToList(); + + var interfaceTemplte = + new InterfaceTemplate(interfaceType, namespaceName, implementedBy).TransformText(); + AddFile("Interfaces", interfaceType.FileName, interfaceTemplte); + } } Console.WriteLine("Generate Types..."); @@ -171,6 +176,12 @@ public List Generate(string schemaJson) } + Console.WriteLine("Generate Client Interface..."); + var clientInterfaceText = new IClientTemplate(namespaceName, clientName, queryType, mutationType, subscriptionType, includeDeprecated) + .TransformText(); + var interfaceFileName = "I" + clientName + ".cs"; + AddFile("Interfaces", interfaceFileName, clientInterfaceText); + Console.WriteLine("Generate Client..."); var templateText = new ClientTemplate(namespaceName, clientName, queryType, mutationType, subscriptionType, includeDeprecated) .TransformText(); @@ -195,6 +206,12 @@ private void GenerateContextMethods(string namespaceName, string directory, Grap return; } + // Generate interface first in Interfaces directory + var interfaceFileName = "I" + methodType.Name.ToPascalCase() + "Methods" + ".cs"; + var interfaceTemplateText = new IMethodsTemplate(methodType, namespaceName, schemaType).TransformText(); + AddFile("Interfaces", interfaceFileName, interfaceTemplateText); + + // Generate concrete class that implements the interface in Client directory var fileName = methodType.Name.ToPascalCase() + "Methods" + ".cs"; var templateText = new MethodsTemplate(methodType, namespaceName, schemaType).TransformText(); AddFile(directory, fileName, templateText); diff --git a/src/Linq2GraphQL.Generator/GraphQLSchema/Schema.cs b/src/Linq2GraphQL.Generator/GraphQLSchema/Schema.cs index f497d92f..94a8fdf6 100644 --- a/src/Linq2GraphQL.Generator/GraphQLSchema/Schema.cs +++ b/src/Linq2GraphQL.Generator/GraphQLSchema/Schema.cs @@ -21,15 +21,17 @@ public class Schema [JsonPropertyName("subscriptionType")] public GraphqlSchemaType SchemaSubscriptionType { get; set; } - [JsonIgnore] public GraphqlType QueryType => Types.FirstOrDefault(e => e.Name == SchemaQueryType?.Name); + [JsonIgnore] public GraphqlType QueryType => Types?.FirstOrDefault(e => e.Name == SchemaQueryType?.Name); - [JsonIgnore] public GraphqlType MutationType => Types.FirstOrDefault(e => e.Name == SchemaMutationType?.Name); + [JsonIgnore] public GraphqlType MutationType => Types?.FirstOrDefault(e => e.Name == SchemaMutationType?.Name); [JsonIgnore] - public GraphqlType SubscriptionType => Types.FirstOrDefault(e => e.Name == SchemaSubscriptionType?.Name); + public GraphqlType SubscriptionType => Types?.FirstOrDefault(e => e.Name == SchemaSubscriptionType?.Name); public List GetAllTypesExceptSystemTypes() { + if (Types == null) return new List(); + return Types.Where(e => e.Name != SchemaQueryType?.Name && !e.Name.StartsWith("__") && !BuiltInTypes.Contains(e.Name) && @@ -40,6 +42,8 @@ public List GetAllTypesExceptSystemTypes() public void PopulateFieldTypes() { + if (Types == null) return; + foreach (var typeGroup in Types.Where(e => e.AllFields != null && e.AllFields.Any()) .SelectMany(e => e.AllFields).GroupBy(e => e.Type.GetBaseBaseType().Name)) { @@ -76,6 +80,6 @@ public List GetInterfaces() return GetAllTypesExceptSystemTypes().Where(e => e.Kind == TypeKind.Interface).ToList(); } - public GraphqlType GetGraphqlType(string name) => Types.FirstOrDefault(e => e.Name == name); + public GraphqlType GetGraphqlType(string name) => Types?.FirstOrDefault(e => e.Name == name); } \ No newline at end of file diff --git a/src/Linq2GraphQL.Generator/Linq2GraphQL.Generator.csproj b/src/Linq2GraphQL.Generator/Linq2GraphQL.Generator.csproj index 5819e4e9..10fbf8b9 100644 --- a/src/Linq2GraphQL.Generator/Linq2GraphQL.Generator.csproj +++ b/src/Linq2GraphQL.Generator/Linq2GraphQL.Generator.csproj @@ -38,6 +38,10 @@ TextTemplatingFilePreprocessor ClientTemplate.cs + + TextTemplatingFilePreprocessor + IClientTemplate.cs + TextTemplatingFilePreprocessor EnumTemplate.cs @@ -46,9 +50,9 @@ InterfaceTemplate.cs TextTemplatingFilePreprocessor - + TextTemplatingFilePreprocessor - MethodsTemplate.cs + IMethodsTemplate.cs InputFactoryClassTemplate.cs @@ -79,10 +83,20 @@ True ClassTemplate.tt + + True + True + ClientExtensionsTemplate.tt + + True + True + ClientTemplate.tt + + True True - ClientTemplate.tt + IClientTemplate.tt True @@ -94,21 +108,16 @@ True InterfaceTemplate.tt - + True True - MethodsTemplate.tt + IMethodsTemplate.tt True True InputFactoryClassTemplate.tt - - True - True - ClientExtensionsTemplate.tt - True True diff --git a/src/Linq2GraphQL.Generator/Templates/Class/ClassTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Class/ClassTemplate.cs index 14ba4f1b..abed5e90 100644 --- a/src/Linq2GraphQL.Generator/Templates/Class/ClassTemplate.cs +++ b/src/Linq2GraphQL.Generator/Templates/Class/ClassTemplate.cs @@ -15,7 +15,7 @@ namespace Linq2GraphQL.Generator.Templates.Class /// Class to produce the template output /// - #line 1 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class ClassTemplate : ClassTemplateBase { @@ -29,147 +29,147 @@ public virtual string TransformText() "ation;\r\nusing Linq2GraphQL.Client;\r\nusing Linq2GraphQL.Client.Common;\r\n\r\nnamespa" + "ce "); - #line 9 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 9 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); #line default #line hidden this.Write(";\r\n\r\n"); - #line 11 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 11 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" if (NullableEnabled()) { #line default #line hidden this.Write("#pragma warning disable CS8618\r\n"); - #line 13 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 13 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } #line default #line hidden this.Write("\r\n"); - #line 15 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 15 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" if (classType.AllFields.Any(e => e.IsMethod)) { #line default #line hidden this.Write("public static class "); - #line 16 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 16 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden this.Write("Extensions\r\n{\r\n"); - #line 18 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 18 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" foreach (var field in classType.AllFields.Where(e => e.IsMethod)) { #line default #line hidden this.Write(" [GraphQLMember(\""); - #line 19 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 19 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write("\")]\r\n"); - #line 20 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 20 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" if (field.IsDeprecated) { #line default #line hidden this.Write(" [Obsolete(\""); - #line 21 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 21 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.SafeDeprecationReason)); #line default #line hidden this.Write("\")]\r\n"); - #line 22 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 22 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } #line default #line hidden this.Write(" public static "); - #line 23 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 23 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetFieldCSharpName(field))); #line default #line hidden this.Write(" "); - #line 23 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 23 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write("(this "); - #line 23 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 23 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden this.Write(" "); - #line 23 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 23 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.CSharpVariableName)); #line default #line hidden this.Write(", "); - #line 23 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 23 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.GetArgString(true))); #line default #line hidden this.Write(")\r\n {\r\n return "); - #line 25 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 25 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.CSharpVariableName)); #line default #line hidden this.Write(".GetMethodValue<"); - #line 25 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 25 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetFieldCSharpName(field))); #line default #line hidden this.Write(">(\""); - #line 25 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 25 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write("\", "); - #line 25 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 25 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.GetArgNames())); #line default #line hidden this.Write(");\r\n }\r\n\r\n"); - #line 28 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 28 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } #line default #line hidden this.Write("}\r\n\r\n"); - #line 31 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 31 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } @@ -177,21 +177,21 @@ public virtual string TransformText() #line default #line hidden - #line 34 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 34 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" if (classType.HasDescription) { #line default #line hidden this.Write("/// \r\n/// "); - #line 36 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 36 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.SummaryDescription)); #line default #line hidden this.Write("\r\n/// \r\n"); - #line 38 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 38 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } @@ -200,41 +200,41 @@ public virtual string TransformText() #line hidden this.Write("public partial class "); - #line 41 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 41 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden this.Write(" "); - #line 41 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 41 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.GetInterfacesString("GraphQLTypeBase"))); #line default #line hidden this.Write("\r\n{\r\n"); - #line 43 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 43 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" foreach (var field in classType.AllFields) { #line default #line hidden - #line 44 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 44 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" if (field.IsMethod) { #line default #line hidden this.Write(" private LazyProperty<"); - #line 45 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 45 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetFieldCSharpName(field))); #line default #line hidden this.Write("> _"); - #line 45 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 45 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default @@ -242,150 +242,150 @@ public virtual string TransformText() this.Write(" = new();\r\n /// \r\n /// Do not use in Query, only to retrive result" + "\r\n /// \r\n"); - #line 49 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 49 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" if (field.IsDeprecated) { #line default #line hidden this.Write(" [Obsolete(\""); - #line 50 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 50 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.SafeDeprecationReason)); #line default #line hidden this.Write("\")]\r\n"); - #line 51 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 51 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } #line default #line hidden this.Write(" public "); - #line 52 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 52 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetFieldCSharpName(field))); #line default #line hidden this.Write(" "); - #line 52 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 52 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write(" => _"); - #line 52 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 52 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write(".Value(() => GetFirstMethodValue<"); - #line 52 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 52 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetFieldCSharpName(field))); #line default #line hidden this.Write(">(\""); - #line 52 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 52 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write("\"));\r\n\r\n"); - #line 54 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 54 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } else { #line default #line hidden - #line 55 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 55 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" if (field.HasDescription) { #line default #line hidden this.Write(" /// \r\n /// "); - #line 57 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 57 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.SummaryDescription)); #line default #line hidden this.Write("\r\n /// \r\n"); - #line 59 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 59 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } #line default #line hidden - #line 60 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 60 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" if (field.IsDeprecated) { #line default #line hidden this.Write(" [Obsolete(\""); - #line 61 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 61 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.SafeDeprecationReason)); #line default #line hidden this.Write("\")]\r\n"); - #line 62 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 62 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } #line default #line hidden this.Write(" [GraphQLMember(\""); - #line 63 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 63 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write("\")]\r\n [JsonPropertyName(\""); - #line 64 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 64 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write("\")]\r\n public "); - #line 65 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 65 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetFieldCSharpName(field))); #line default #line hidden this.Write(" "); - #line 65 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 65 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write(" { get; set; }\r\n\r\n"); - #line 67 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 67 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } #line default #line hidden - #line 68 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 68 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } #line default #line hidden - #line 69 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 69 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" if (classType.HasInterfaces) { #line default @@ -393,7 +393,7 @@ public virtual string TransformText() this.Write(" [GraphQLMember(\"__typename\")]\r\n [JsonPropertyName(\"__typename\")]\r\n publ" + "ic string __TypeName { get; set; }\r\n"); - #line 73 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" + #line 73 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt" } #line default diff --git a/src/Linq2GraphQL.Generator/Templates/Class/InputClassTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Class/InputClassTemplate.cs index 63af09ab..75b687ba 100644 --- a/src/Linq2GraphQL.Generator/Templates/Class/InputClassTemplate.cs +++ b/src/Linq2GraphQL.Generator/Templates/Class/InputClassTemplate.cs @@ -15,7 +15,7 @@ namespace Linq2GraphQL.Generator.Templates.Class /// Class to produce the template output /// - #line 1 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class InputClassTemplate : InputClassTemplateBase { @@ -28,28 +28,28 @@ public virtual string TransformText() this.Write("using System;\r\nusing System.Collections.Generic;\r\nusing System.Text.Json.Serializ" + "ation;\r\nusing Linq2GraphQL.Client;\r\n\r\nnamespace "); - #line 8 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 8 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); #line default #line hidden this.Write(";\r\n\r\n[JsonConverter(typeof(GraphInputConverter<"); - #line 10 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 10 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden this.Write(">))]\r\npublic partial class "); - #line 11 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 11 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden this.Write(" : GraphInputBase\r\n{\r\n"); - #line 13 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 13 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" foreach (var field in classType.AllFields) { @@ -59,77 +59,77 @@ public virtual string TransformText() #line default #line hidden - #line 18 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 18 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" if (field.IsDeprecated) { #line default #line hidden this.Write(" [Obsolete(\""); - #line 19 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 19 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.DeprecationReason)); #line default #line hidden this.Write("\")]\r\n"); - #line 20 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 20 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" } #line default #line hidden this.Write("\t[GraphQLMember(\""); - #line 21 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 21 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write("\")]\r\n\t[JsonPropertyName(\""); - #line 22 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 22 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write("\")]\r\n\tpublic "); - #line 23 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 23 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetPropertyDefinition(field))); #line default #line hidden this.Write(" "); - #line 23 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 23 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write(" \r\n\t{\r\n\t\tget => GetValue<"); - #line 25 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 25 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(coreType.CSharpTypeDefinition)); #line default #line hidden this.Write(">(\""); - #line 25 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 25 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write("\");\r\n \tset => SetValue(\""); - #line 26 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 26 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write("\", value);\r\n\t}\r\n\r\n"); - #line 29 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" + #line 29 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputClassTemplate.tt" } diff --git a/src/Linq2GraphQL.Generator/Templates/Class/InputFactoryClassTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Class/InputFactoryClassTemplate.cs index 3d6ec0fd..775c3a25 100644 --- a/src/Linq2GraphQL.Generator/Templates/Class/InputFactoryClassTemplate.cs +++ b/src/Linq2GraphQL.Generator/Templates/Class/InputFactoryClassTemplate.cs @@ -16,7 +16,7 @@ namespace Linq2GraphQL.Generator.Templates.Class /// Class to produce the template output /// - #line 1 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class InputFactoryClassTemplate : InputFactoryClassTemplateBase { @@ -29,14 +29,14 @@ public virtual string TransformText() this.Write("using System;\r\nusing System.Collections.Generic;\r\nusing System.Text.Json.Serializ" + "ation;\r\nusing Linq2GraphQL.Client;\r\n\r\nnamespace "); - #line 9 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 9 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); #line default #line hidden this.Write(";\r\n\r\npublic static class IF \r\n{ \r\n"); - #line 13 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 13 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" foreach (var field in inputs) { @@ -46,28 +46,28 @@ public virtual string TransformText() #line hidden this.Write("\tpublic static "); - #line 17 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 17 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write(" "); - #line 17 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 17 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName.RemoveFromEnd("Input"))); #line default #line hidden this.Write("() \r\n\t{\r\n\t\treturn new "); - #line 19 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 19 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write("();\r\n\t}\r\n"); - #line 21 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 21 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" } @@ -76,7 +76,7 @@ public virtual string TransformText() #line hidden this.Write("}\r\n\r\n\r\n"); - #line 27 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 27 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" foreach (var input in inputs.Where(x => x.AllFields.Any())) { @@ -86,14 +86,14 @@ public virtual string TransformText() #line hidden this.Write("\r\npublic static class "); - #line 32 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 32 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(input.CSharpName)); #line default #line hidden this.Write("Extensions\r\n{ \r\n\t"); - #line 34 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 34 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" foreach (var field in input.AllFields) { @@ -103,7 +103,7 @@ public virtual string TransformText() #line default #line hidden - #line 39 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 39 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" if (coreType.CSharpType.IsValueTypeOrString() || coreType.IsEnum) { @@ -113,42 +113,42 @@ public virtual string TransformText() #line hidden this.Write("\r\n public static "); - #line 44 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 44 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(input.CSharpName)); #line default #line hidden this.Write(" "); - #line 44 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 44 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write("(this "); - #line 44 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 44 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(input.CSharpName)); #line default #line hidden this.Write(" input, "); - #line 44 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 44 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(coreType.CSharpTypeDefinition)); #line default #line hidden this.Write(" val)\r\n {\r\n input."); - #line 46 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 46 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write(" = val;\r\n return input;\r\n }\r\n\r\n"); - #line 50 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 50 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" } else @@ -159,49 +159,49 @@ public virtual string TransformText() #line hidden this.Write(" public static "); - #line 55 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 55 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(input.CSharpName)); #line default #line hidden this.Write(" "); - #line 55 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 55 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write("(this "); - #line 55 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 55 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(input.CSharpName)); #line default #line hidden this.Write(" input, Action<"); - #line 55 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 55 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(coreType.CSharpTypeDefinition)); #line default #line hidden this.Write("> mod)\r\n {\r\n var filter = new "); - #line 57 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 57 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(coreType.CSharpTypeDefinitionNeverNull)); #line default #line hidden this.Write("();\r\n mod ??= _ => { };\r\n mod(filter); \r\n input."); - #line 60 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 60 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write(" = filter;\r\n return input;\r\n }\r\n\r\n"); - #line 64 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 64 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" } } @@ -211,7 +211,7 @@ public virtual string TransformText() #line hidden this.Write("}\r\n"); - #line 69 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" + #line 69 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Class\InputFactoryClassTemplate.tt" } diff --git a/src/Linq2GraphQL.Generator/Templates/Client/ClientExtensionsTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Client/ClientExtensionsTemplate.cs index 279c0563..ca82de6c 100644 --- a/src/Linq2GraphQL.Generator/Templates/Client/ClientExtensionsTemplate.cs +++ b/src/Linq2GraphQL.Generator/Templates/Client/ClientExtensionsTemplate.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version: 16.0.0.0 +// Runtime Version: 17.0.0.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -15,8 +15,8 @@ namespace Linq2GraphQL.Generator.Templates.Client /// Class to produce the template output /// - #line 1 "C:\Code\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class ClientExtensionsTemplate : ClientExtensionsTemplateBase { #line hidden @@ -25,65 +25,82 @@ public partial class ClientExtensionsTemplate : ClientExtensionsTemplateBase /// public virtual string TransformText() { - this.Write("using Linq2GraphQL.Client;\r\nusing Microsoft.Extensions.DependencyInjection;\r\nusing Microsoft.Extensions.Options;\r\n\r\nnamespace "); + this.Write("using Linq2GraphQL.Client;\r\nusing Microsoft.Extensions.DependencyInjection;\r\nusin" + + "g Microsoft.Extensions.Options;\r\n\r\nnamespace "); - #line 7 "C:\Code\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" + #line 7 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); #line default #line hidden this.Write(";\r\n\r\npublic static class "); - #line 9 "C:\Code\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" + #line 9 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(clientName)); #line default #line hidden this.Write("Extensions \r\n{\r\n private const string ClientName = \""); - #line 11 "C:\Code\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" + #line 11 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(clientName)); #line default #line hidden this.Write("\";\r\n \r\n public static IGraphClientBuilder<"); - #line 13 "C:\Code\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" + #line 13 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(clientName)); #line default #line hidden this.Write("> Add"); - #line 13 "C:\Code\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" + #line 13 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(clientName)); #line default #line hidden - this.Write("(this IServiceCollection services)\r\n {\r\n var graphClientOptions = new GraphClientOptions();\r\n return GraphClientBuilder(services, graphClientOptions);\r\n }\r\n \r\n public static IGraphClientBuilder<"); + this.Write("(this IServiceCollection services)\r\n {\r\n var graphClientOptions = new G" + + "raphClientOptions();\r\n return GraphClientBuilder(services, graphClientOpt" + + "ions);\r\n }\r\n \r\n public static IGraphClientBuilder<"); - #line 19 "C:\Code\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" + #line 19 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(clientName)); #line default #line hidden this.Write("> Add"); - #line 19 "C:\Code\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" + #line 19 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(clientName)); #line default #line hidden - this.Write("(this IServiceCollection services, Action opts)\r\n {\r\n var graphClientOptions = new GraphClientOptions();\r\n opts(graphClientOptions);\r\n \r\n return GraphClientBuilder(services, graphClientOptions);\r\n }\r\n\r\n private static IGraphClientBuilder<"); + this.Write(@"(this IServiceCollection services, Action opts) + { + var graphClientOptions = new GraphClientOptions(); + opts(graphClientOptions); + + return GraphClientBuilder(services, graphClientOptions); + } + + private static IGraphClientBuilder<"); - #line 27 "C:\Code\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" + #line 27 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(clientName)); #line default #line hidden - this.Write("> GraphClientBuilder(IServiceCollection services,\r\n GraphClientOptions graphClientOptions)\r\n {\r\n var opts = Options.Create(graphClientOptions);\r\n services.AddKeyedSingleton(ClientName, opts); \r\n services.AddMemoryCache(); \r\n return new ClientBuilder<"); + this.Write(@"> GraphClientBuilder(IServiceCollection services, + GraphClientOptions graphClientOptions) + { + var opts = Options.Create(graphClientOptions); + services.AddKeyedSingleton(ClientName, opts); + services.AddMemoryCache(); + return new ClientBuilder<"); - #line 33 "C:\Code\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" + #line 33 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientExtensionsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(clientName)); #line default @@ -99,7 +116,7 @@ public virtual string TransformText() /// /// Base class for this transformation /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public class ClientExtensionsTemplateBase { #region Fields @@ -114,7 +131,7 @@ public class ClientExtensionsTemplateBase /// /// The string builder that generation-time code is using to assemble generated output /// - protected System.Text.StringBuilder GenerationEnvironment + public System.Text.StringBuilder GenerationEnvironment { get { diff --git a/src/Linq2GraphQL.Generator/Templates/Client/ClientExtensionsTemplate.tt.cs b/src/Linq2GraphQL.Generator/Templates/Client/ClientExtensionsTemplate.tt.cs index 889f3d29..de55ea14 100644 --- a/src/Linq2GraphQL.Generator/Templates/Client/ClientExtensionsTemplate.tt.cs +++ b/src/Linq2GraphQL.Generator/Templates/Client/ClientExtensionsTemplate.tt.cs @@ -1,17 +1,15 @@ -namespace Linq2GraphQL.Generator.Templates.Client; +namespace Linq2GraphQL.Generator.Templates.Client; public partial class ClientExtensionsTemplate { - private readonly bool includeSubscriptions; - private readonly string clientName; private readonly string namespaceName; + private readonly string clientName; + private readonly bool includeSubscriptions; - public ClientExtensionsTemplate(string namespaceName, string name, bool includeSubscriptions) + public ClientExtensionsTemplate(string namespaceName, string clientName, bool includeSubscriptions) { this.namespaceName = namespaceName; - this.clientName = name; + this.clientName = clientName; this.includeSubscriptions = includeSubscriptions; } - - //private string clientName => clientName + "Client"; -} \ No newline at end of file +} diff --git a/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.cs index d177b0f2..afd68c4a 100644 --- a/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.cs +++ b/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.cs @@ -15,7 +15,7 @@ namespace Linq2GraphQL.Generator.Templates.Client /// Class to produce the template output /// - #line 1 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class ClientTemplate : ClientTemplateBase { @@ -25,167 +25,296 @@ public partial class ClientTemplate : ClientTemplateBase /// public virtual string TransformText() { - this.Write("using Linq2GraphQL.Client;\r\nusing Microsoft.Extensions.Caching.Memory;\r\nusing Mic" + - "rosoft.Extensions.DependencyInjection;\r\nusing Microsoft.Extensions.Options;\r\n\r\nn" + - "amespace "); + this.Write("using Linq2GraphQL.Client;\r\nusing Microsoft.Extensions.DependencyInjection;\r\nusin" + + "g Microsoft.Extensions.Options;\r\n\r\nnamespace "); - #line 8 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 7 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); #line default #line hidden - this.Write(";\r\n\r\npublic class "); + this.Write(";\r\n\r\n/// \r\n/// GraphQL client for "); - #line 10 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 10 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(name)); #line default #line hidden - this.Write("\r\n{ \r\n public "); + this.Write(" operations\r\n/// \r\n/// \r\n/// Provides strongly-typed access to" + + " GraphQL queries, mutations, and subscriptions.\r\n/// Supports dependency injecti" + + "on for better testability and flexibility.\r\n/// \r\npublic class "); - #line 12 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 16 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(name)); #line default #line hidden - this.Write("(HttpClient httpClient, [FromKeyedServices(\""); + this.Write(" : I"); - #line 12 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 16 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(name)); #line default #line hidden - this.Write("\")]IOptions options, IServiceProvider provider)\r\n {\r\n " + - " var client = new GraphClient(httpClient, options, provider, "); + this.Write(@" +{ + /// + /// Constructor with dependency injection support + /// + /// HTTP client for GraphQL requests + /// GraphQL client configuration options + /// Service provider for dependency resolution +"); + + #line 24 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + if (includeQuery) { + + #line default + #line hidden + this.Write(" /// Optional query methods implementation (uses de" + + "fault if null)\r\n"); + + #line 26 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + } + + #line default + #line hidden + + #line 27 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + if (includeMutation) { + + #line default + #line hidden + this.Write(" /// Optional mutation methods implementation (u" + + "ses default if null)\r\n"); + + #line 29 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + } + + #line default + #line hidden + + #line 30 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + if (includeSubscriptions) { + + #line default + #line hidden + this.Write(" /// Optional subscription methods implement" + + "ation (uses default if null)\r\n"); + + #line 32 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + } + + #line default + #line hidden + this.Write(" public "); + + #line 33 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(name)); + + #line default + #line hidden + this.Write("(\r\n HttpClient httpClient, \r\n [FromKeyedServices(\""); + + #line 35 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(name)); + + #line default + #line hidden + this.Write("\")] IOptions options, \r\n IServiceProvider provider"); + + #line 36 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + if (includeQuery) { + + #line default + #line hidden + this.Write(",\r\n I"); - #line 14 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 37 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(queryType))); + + #line default + #line hidden + this.Write(" queryMethods = null"); + + #line 37 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + } + + #line default + #line hidden + + #line 37 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + if (includeMutation) { + + #line default + #line hidden + this.Write(",\r\n I"); + + #line 38 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(mutationType))); + + #line default + #line hidden + this.Write(" mutationMethods = null"); + + #line 38 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + } + + #line default + #line hidden + + #line 38 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + if (includeSubscriptions) { + + #line default + #line hidden + this.Write(",\r\n I"); + + #line 39 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(subscriptionType))); + + #line default + #line hidden + this.Write(" subscriptionMethods = null"); + + #line 39 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + } + + #line default + #line hidden + this.Write(")\r\n {\r\n var client = new GraphClient(httpClient, options, provider, "); + + #line 41 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(includeDeprecated.ToString().ToLower())); #line default #line hidden this.Write(");\r\n"); - #line 15 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 42 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" if (includeQuery) { #line default #line hidden - this.Write(" Query = new "); + this.Write(" Query = queryMethods ?? new "); - #line 16 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 43 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(queryType))); #line default #line hidden this.Write("(client);\r\n"); - #line 17 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" - } + #line 44 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + } #line default #line hidden - #line 18 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 45 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" if (includeMutation) { #line default #line hidden - this.Write(" Mutation = new "); + this.Write(" Mutation = mutationMethods ?? new "); - #line 19 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 46 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(mutationType))); #line default #line hidden this.Write("(client);\r\n"); - #line 20 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" - } + #line 47 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + } #line default #line hidden - #line 21 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 48 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" if (includeSubscriptions) { #line default #line hidden - this.Write(" Subscription = new "); + this.Write(" Subscription = subscriptionMethods ?? new "); - #line 22 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 49 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(subscriptionType))); #line default #line hidden - this.Write("(client); \r\n"); + this.Write("(client);\r\n"); - #line 23 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" - } + #line 50 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + } #line default #line hidden this.Write(" }\r\n\r\n"); - #line 26 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 53 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" if (includeQuery) { #line default #line hidden - this.Write(" public "); + this.Write(" /// \r\n /// Gets the query methods for this GraphQL client\r\n //" + + "/ \r\n public I"); - #line 27 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 57 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(queryType))); #line default #line hidden this.Write(" Query { get; private set; }\r\n"); - #line 28 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 58 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" } #line default #line hidden - #line 29 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 59 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" if (includeMutation) { #line default #line hidden - this.Write(" public "); + this.Write(" /// \r\n /// Gets the mutation methods for this GraphQL client\r\n " + + " /// \r\n public I"); - #line 30 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 63 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(mutationType))); #line default #line hidden this.Write(" Mutation { get; private set; }\r\n"); - #line 31 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 64 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" } #line default #line hidden - #line 32 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 65 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" if (includeSubscriptions) { #line default #line hidden - this.Write(" public "); + this.Write(" /// \r\n /// Gets the subscription methods for this GraphQL client\r" + + "\n /// \r\n public I"); - #line 33 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 69 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(subscriptionType))); #line default #line hidden this.Write(" Subscription { get; private set; }\r\n"); - #line 34 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" + #line 70 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\ClientTemplate.tt" } #line default #line hidden - this.Write(" \r\n}"); + this.Write("}"); return this.GenerationEnvironment.ToString(); } } diff --git a/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.tt b/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.tt index f509badd..f80c86cd 100644 --- a/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.tt +++ b/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.tt @@ -1,36 +1,71 @@ <#@ template language="C#" #> <#@ assembly name="System.Core" #> using Linq2GraphQL.Client; -using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace <#= namespaceName #>; -public class <#= name #> +/// +/// GraphQL client for <#= name #> operations +/// +/// +/// Provides strongly-typed access to GraphQL queries, mutations, and subscriptions. +/// Supports dependency injection for better testability and flexibility. +/// +public class <#= name #> : I<#= name #> { - public <#= name #>(HttpClient httpClient, [FromKeyedServices("<#= name #>")]IOptions options, IServiceProvider provider) + /// + /// Constructor with dependency injection support + /// + /// HTTP client for GraphQL requests + /// GraphQL client configuration options + /// Service provider for dependency resolution +<# if (includeQuery) { #> + /// Optional query methods implementation (uses default if null) +<# } #> +<# if (includeMutation) { #> + /// Optional mutation methods implementation (uses default if null) +<# } #> +<# if (includeSubscriptions) { #> + /// Optional subscription methods implementation (uses default if null) +<# } #> + public <#= name #>( + HttpClient httpClient, + [FromKeyedServices("<#= name #>")] IOptions options, + IServiceProvider provider<# if (includeQuery) { #>, + I<#= GetMehodName(queryType) #> queryMethods = null<# } #><# if (includeMutation) { #>, + I<#= GetMehodName(mutationType) #> mutationMethods = null<# } #><# if (includeSubscriptions) { #>, + I<#= GetMehodName(subscriptionType) #> subscriptionMethods = null<# } #>) { var client = new GraphClient(httpClient, options, provider, <#= includeDeprecated.ToString().ToLower() #>); <# if (includeQuery) { #> - Query = new <#= GetMehodName(queryType) #>(client); -<# }#> + Query = queryMethods ?? new <#= GetMehodName(queryType) #>(client); +<# } #> <# if (includeMutation) { #> - Mutation = new <#= GetMehodName(mutationType) #>(client); -<# }#> + Mutation = mutationMethods ?? new <#= GetMehodName(mutationType) #>(client); +<# } #> <# if (includeSubscriptions) { #> - Subscription = new <#= GetMehodName(subscriptionType) #>(client); -<# }#> + Subscription = subscriptionMethods ?? new <#= GetMehodName(subscriptionType) #>(client); +<# } #> } <# if (includeQuery) { #> - public <#= GetMehodName(queryType) #> Query { get; private set; } + /// + /// Gets the query methods for this GraphQL client + /// + public I<#= GetMehodName(queryType) #> Query { get; private set; } <# } #> <# if (includeMutation) { #> - public <#= GetMehodName(mutationType) #> Mutation { get; private set; } + /// + /// Gets the mutation methods for this GraphQL client + /// + public I<#= GetMehodName(mutationType) #> Mutation { get; private set; } <# } #> <# if (includeSubscriptions) { #> - public <#= GetMehodName(subscriptionType) #> Subscription { get; private set; } + /// + /// Gets the subscription methods for this GraphQL client + /// + public I<#= GetMehodName(subscriptionType) #> Subscription { get; private set; } <# } #> - } \ No newline at end of file diff --git a/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.tt.cs b/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.tt.cs index 60a822c0..380aa435 100644 --- a/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.tt.cs +++ b/src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.tt.cs @@ -1,14 +1,30 @@ -namespace Linq2GraphQL.Generator.Templates.Client; +namespace Linq2GraphQL.Generator.Templates.Client; -public partial class ClientTemplate(string namespaceName, string name, GraphqlType queryType, GraphqlType mutationType, GraphqlType subscriptionType, bool includeDeprecated) +public partial class ClientTemplate { + private readonly string namespaceName; + private readonly string name; + private readonly GraphqlType queryType; + private readonly GraphqlType mutationType; + private readonly GraphqlType subscriptionType; + private readonly bool includeDeprecated; + + public ClientTemplate(string namespaceName, string name, GraphqlType queryType, GraphqlType mutationType, GraphqlType subscriptionType, bool includeDeprecated) + { + this.namespaceName = namespaceName; + this.name = name; + this.queryType = queryType; + this.mutationType = mutationType; + this.subscriptionType = subscriptionType; + this.includeDeprecated = includeDeprecated; + } + private bool includeQuery => queryType != null; - private bool includeMutation => mutationType != null; - private bool includeSubscriptions => subscriptionType != null; + private bool includeMutation => mutationType != null; + private bool includeSubscriptions => subscriptionType != null; private string GetMehodName(GraphqlType graphqlType) { return graphqlType.CSharpName + "Methods"; } - //private string clientName => clientName + "Client"; -} \ No newline at end of file +} diff --git a/src/Linq2GraphQL.Generator/Templates/Client/IClientTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Client/IClientTemplate.cs new file mode 100644 index 00000000..8d36a766 --- /dev/null +++ b/src/Linq2GraphQL.Generator/Templates/Client/IClientTemplate.cs @@ -0,0 +1,382 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version: 17.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +namespace Linq2GraphQL.Generator.Templates.Client +{ + using System; + + /// + /// Class to produce the template output + /// + + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] + public partial class IClientTemplate : IClientTemplateBase + { +#line hidden + /// + /// Create the template output + /// + public virtual string TransformText() + { + this.Write("using Linq2GraphQL.Client;\r\n\r\nnamespace "); + + #line 5 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); + + #line default + #line hidden + this.Write(";\r\n\r\npublic interface I"); + + #line 7 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(name)); + + #line default + #line hidden + this.Write("\r\n{\r\n"); + + #line 9 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + if (includeQuery) { + + #line default + #line hidden + this.Write(" I"); + + #line 10 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(queryType))); + + #line default + #line hidden + this.Write(" Query { get; }\r\n"); + + #line 11 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + } + + #line default + #line hidden + + #line 12 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + if (includeMutation) { + + #line default + #line hidden + this.Write(" I"); + + #line 13 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(mutationType))); + + #line default + #line hidden + this.Write(" Mutation { get; }\r\n"); + + #line 14 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + } + + #line default + #line hidden + + #line 15 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + if (includeSubscriptions) { + + #line default + #line hidden + this.Write(" I"); + + #line 16 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(GetMehodName(subscriptionType))); + + #line default + #line hidden + this.Write(" Subscription { get; }\r\n"); + + #line 17 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Client\IClientTemplate.tt" + } + + #line default + #line hidden + this.Write("}\r\n"); + return this.GenerationEnvironment.ToString(); + } + } + + #line default + #line hidden + #region Base class + /// + /// Base class for this transformation + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] + public class IClientTemplateBase + { + #region Fields + private global::System.Text.StringBuilder generationEnvironmentField; + private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; + private global::System.Collections.Generic.List indentLengthsField; + private string currentIndentField = ""; + private bool endsWithNewline; + private global::System.Collections.Generic.IDictionary sessionField; + #endregion + #region Properties + /// + /// The string builder that generation-time code is using to assemble generated output + /// + public System.Text.StringBuilder GenerationEnvironment + { + get + { + if ((this.generationEnvironmentField == null)) + { + this.generationEnvironmentField = new global::System.Text.StringBuilder(); + } + return this.generationEnvironmentField; + } + set + { + this.generationEnvironmentField = value; + } + } + /// + /// The error collection for the generation process + /// + public System.CodeDom.Compiler.CompilerErrorCollection Errors + { + get + { + if ((this.errorsField == null)) + { + this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); + } + return this.errorsField; + } + } + /// + /// A list of the lengths of each indent that was added with PushIndent + /// + private System.Collections.Generic.List indentLengths + { + get + { + if ((this.indentLengthsField == null)) + { + this.indentLengthsField = new global::System.Collections.Generic.List(); + } + return this.indentLengthsField; + } + } + /// + /// Gets the current indent we use when adding lines to the output + /// + public string CurrentIndent + { + get + { + return this.currentIndentField; + } + } + /// + /// Current transformation session + /// + public virtual global::System.Collections.Generic.IDictionary Session + { + get + { + return this.sessionField; + } + set + { + this.sessionField = value; + } + } + #endregion + #region Transform-time helpers + /// + /// Write text directly into the generated output + /// + public void Write(string textToAppend) + { + if (string.IsNullOrEmpty(textToAppend)) + { + return; + } + // If we're starting off, or if the previous text ended with a newline, + // we have to append the current indent first. + if (((this.GenerationEnvironment.Length == 0) + || this.endsWithNewline)) + { + this.GenerationEnvironment.Append(this.currentIndentField); + this.endsWithNewline = false; + } + // Check if the current text ends with a newline + if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) + { + this.endsWithNewline = true; + } + // This is an optimization. If the current indent is "", then we don't have to do any + // of the more complex stuff further down. + if ((this.currentIndentField.Length == 0)) + { + this.GenerationEnvironment.Append(textToAppend); + return; + } + // Everywhere there is a newline in the text, add an indent after it + textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); + // If the text ends with a newline, then we should strip off the indent added at the very end + // because the appropriate indent will be added when the next time Write() is called + if (this.endsWithNewline) + { + this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); + } + else + { + this.GenerationEnvironment.Append(textToAppend); + } + } + /// + /// Write text directly into the generated output + /// + public void WriteLine(string textToAppend) + { + this.Write(textToAppend); + this.GenerationEnvironment.AppendLine(); + this.endsWithNewline = true; + } + /// + /// Write formatted text directly into the generated output + /// + public void Write(string format, params object[] args) + { + this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Write formatted text directly into the generated output + /// + public void WriteLine(string format, params object[] args) + { + this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Raise an error + /// + public void Error(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + this.Errors.Add(error); + } + /// + /// Raise a warning + /// + public void Warning(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + error.IsWarning = true; + this.Errors.Add(error); + } + /// + /// Increase the indent + /// + public void PushIndent(string indent) + { + if ((indent == null)) + { + throw new global::System.ArgumentNullException("indent"); + } + this.currentIndentField = (this.currentIndentField + indent); + this.indentLengths.Add(indent.Length); + } + /// + /// Remove the last indent that was added with PushIndent + /// + public string PopIndent() + { + string returnValue = ""; + if ((this.indentLengths.Count > 0)) + { + int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; + this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); + if ((indentLength > 0)) + { + returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); + this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); + } + } + return returnValue; + } + /// + /// Remove any indentation + /// + public void ClearIndent() + { + this.indentLengths.Clear(); + this.currentIndentField = ""; + } + #endregion + #region ToString Helpers + /// + /// Utility class to produce culture-oriented representation of an object as a string. + /// + public class ToStringInstanceHelper + { + private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; + /// + /// Gets or sets format provider to be used by ToStringWithCulture method. + /// + public System.IFormatProvider FormatProvider + { + get + { + return this.formatProviderField ; + } + set + { + if ((value != null)) + { + this.formatProviderField = value; + } + } + } + /// + /// This is called from the compile/run appdomain to convert objects within an expression block to a string + /// + public string ToStringWithCulture(object objectToConvert) + { + if ((objectToConvert == null)) + { + throw new global::System.ArgumentNullException("objectToConvert"); + } + System.Type t = objectToConvert.GetType(); + System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { + typeof(System.IFormatProvider)}); + if ((method == null)) + { + return objectToConvert.ToString(); + } + else + { + return ((string)(method.Invoke(objectToConvert, new object[] { + this.formatProviderField }))); + } + } + } + private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); + /// + /// Helper to produce culture-oriented representation of an object as a string + /// + public ToStringInstanceHelper ToStringHelper + { + get + { + return this.toStringHelperField; + } + } + #endregion + } + #endregion +} diff --git a/src/Linq2GraphQL.Generator/Templates/Client/IClientTemplate.tt b/src/Linq2GraphQL.Generator/Templates/Client/IClientTemplate.tt new file mode 100644 index 00000000..f4ddb27a --- /dev/null +++ b/src/Linq2GraphQL.Generator/Templates/Client/IClientTemplate.tt @@ -0,0 +1,18 @@ +<#@ template language="C#" #> +<#@ assembly name="System.Core" #> +using Linq2GraphQL.Client; + +namespace <#= namespaceName #>; + +public interface I<#= name #> +{ +<# if (includeQuery) { #> + I<#= GetMehodName(queryType) #> Query { get; } +<# } #> +<# if (includeMutation) { #> + I<#= GetMehodName(mutationType) #> Mutation { get; } +<# } #> +<# if (includeSubscriptions) { #> + I<#= GetMehodName(subscriptionType) #> Subscription { get; } +<# } #> +} diff --git a/src/Linq2GraphQL.Generator/Templates/Client/IClientTemplate.tt.cs b/src/Linq2GraphQL.Generator/Templates/Client/IClientTemplate.tt.cs new file mode 100644 index 00000000..938c6604 --- /dev/null +++ b/src/Linq2GraphQL.Generator/Templates/Client/IClientTemplate.tt.cs @@ -0,0 +1,30 @@ +namespace Linq2GraphQL.Generator.Templates.Client; + +public partial class IClientTemplate +{ + private readonly string namespaceName; + private readonly string name; + private readonly GraphqlType queryType; + private readonly GraphqlType mutationType; + private readonly GraphqlType subscriptionType; + private readonly bool includeDeprecated; + + public IClientTemplate(string namespaceName, string name, GraphqlType queryType, GraphqlType mutationType, GraphqlType subscriptionType, bool includeDeprecated) + { + this.namespaceName = namespaceName; + this.name = name; + this.queryType = queryType; + this.mutationType = mutationType; + this.subscriptionType = subscriptionType; + this.includeDeprecated = includeDeprecated; + } + + private bool includeQuery => queryType != null; + private bool includeMutation => mutationType != null; + private bool includeSubscriptions => subscriptionType != null; + + private string GetMehodName(GraphqlType graphqlType) + { + return graphqlType.CSharpName + "Methods"; + } +} diff --git a/src/Linq2GraphQL.Generator/Templates/Enum/EnumTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Enum/EnumTemplate.cs index c4d7e699..a9da04e0 100644 --- a/src/Linq2GraphQL.Generator/Templates/Enum/EnumTemplate.cs +++ b/src/Linq2GraphQL.Generator/Templates/Enum/EnumTemplate.cs @@ -15,7 +15,7 @@ namespace Linq2GraphQL.Generator.Templates.Enum /// Class to produce the template output /// - #line 1 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class EnumTemplate : EnumTemplateBase { @@ -28,21 +28,21 @@ public virtual string TransformText() this.Write("using Linq2GraphQL.Client;\r\nusing System.Runtime.Serialization;\r\nusing System.Tex" + "t.Json.Serialization;\r\n\r\nnamespace "); - #line 7 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 7 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); #line default #line hidden this.Write(";\r\n\r\n[JsonConverter(typeof(JsonStringEnumMemberConverter))]\r\npublic enum "); - #line 10 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 10 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(enumType.Name)); #line default #line hidden this.Write("\r\n{\r\n"); - #line 12 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 12 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" foreach (var enumValue in enumType.EnumValues) { @@ -51,42 +51,42 @@ public virtual string TransformText() #line default #line hidden - #line 16 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 16 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" if (enumValue.IsDeprecated) { #line default #line hidden this.Write(" [Obsolete(\""); - #line 17 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 17 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(enumValue.SafeDeprecationReason)); #line default #line hidden this.Write("\")]\r\n"); - #line 18 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 18 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" } #line default #line hidden this.Write(" [EnumMember(Value = \""); - #line 19 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 19 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(enumValue.Name)); #line default #line hidden this.Write("\")]\r\n "); - #line 20 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 20 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(enumValue.GetCSharpName())); #line default #line hidden this.Write(",\r\n"); - #line 21 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 21 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" } @@ -94,7 +94,7 @@ public virtual string TransformText() #line default #line hidden - #line 24 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 24 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" if (enumGeneratorStrategy == EnumGeneratorStrategy.AddUnknownOption) { @@ -107,7 +107,7 @@ public virtual string TransformText() "on\'t set explicitly. \r\n /// \r\n [EnumMember(Value = \"\")]\r\n __U" + "nknown\r\n"); - #line 35 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" + #line 35 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Enum\EnumTemplate.tt" } diff --git a/src/Linq2GraphQL.Generator/Templates/Interface/InterfaceTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Interface/InterfaceTemplate.cs index 45395c5c..7ab9a1d2 100644 --- a/src/Linq2GraphQL.Generator/Templates/Interface/InterfaceTemplate.cs +++ b/src/Linq2GraphQL.Generator/Templates/Interface/InterfaceTemplate.cs @@ -15,7 +15,7 @@ namespace Linq2GraphQL.Generator.Templates.Interface /// Class to produce the template output /// - #line 1 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class InterfaceTemplate : InterfaceTemplateBase { @@ -29,243 +29,308 @@ public virtual string TransformText() "em.Text.Json.Serialization;\r\nusing Linq2GraphQL.Client;\r\nusing Linq2GraphQL.Clie" + "nt.Converters;\r\n\r\nnamespace "); - #line 10 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 10 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); #line default #line hidden - this.Write(";\r\n\r\npublic static class "); + this.Write(";\r\n\r\n/// \r\n/// Extension methods for "); - #line 12 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 13 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden - this.Write("Extentions\r\n{\r\n\r\n"); + this.Write(" interface type casting\r\n/// \r\npublic static class "); - #line 15 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 15 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); + + #line default + #line hidden + this.Write("Extensions\r\n{\r\n"); + + #line 17 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" foreach (var field in implementedBy) { #line default #line hidden - this.Write("\r\n [GraphInterface]\r\n public static "); + this.Write(" /// \r\n /// Casts "); + + #line 19 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); + + #line default + #line hidden + this.Write(" to "); - #line 18 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 19 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(field)); + + #line default + #line hidden + this.Write(" if the runtime type matches\r\n /// \r\n /// The" + + " interface value to cast\r\n /// "); + + #line 22 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(field)); + + #line default + #line hidden + this.Write(" instance or null if type doesn\'t match\r\n [GraphInterface]\r\n publ" + + "ic static "); + + #line 24 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field)); #line default #line hidden this.Write(" "); - #line 18 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 24 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field)); #line default #line hidden this.Write("(this "); - #line 18 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 24 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden this.Write(" value)\r\n {\r\n if (value.__TypeName == \""); - #line 20 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 26 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field)); #line default #line hidden this.Write("\")\r\n {\r\n return ("); - #line 22 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 28 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field)); #line default #line hidden - this.Write(")value;\r\n }\r\n return null;\r\n }\r\n"); + this.Write(")value;\r\n }\r\n return null;\r\n }\r\n\r\n"); - #line 26 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 33 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" } #line default #line hidden - this.Write("}\r\n\r\n\r\ninternal class "); + this.Write("}\r\n\r\n/// \r\n/// JSON converter for "); - #line 30 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 37 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); + + #line default + #line hidden + this.Write(" interface deserialization\r\n/// \r\ninternal class "); + + #line 39 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetInterfaceConverterName())); #line default #line hidden this.Write(" : InterfaceJsonConverter<"); - #line 30 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 39 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden - this.Write(">\r\n{\r\n public override "); + this.Write(@"> +{ + /// + /// Deserializes JSON to the appropriate concrete type based on __typename + /// + /// The GraphQL type name from __typename field + /// The JSON object to deserialize + /// Deserialized instance of the appropriate concrete type + public override "); - #line 32 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 47 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden - this.Write(" Deserialize(string typeName, JsonObject json) => typeName switch\r\n {\r\n "); + this.Write(" Deserialize(string typeName, JsonObject json) => typeName switch\r\n {\r\n"); - #line 34 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 49 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" foreach (var field in implementedBy) { #line default #line hidden - this.Write(" \""); + this.Write(" \""); - #line 35 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 50 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field)); #line default #line hidden this.Write("\" => json.Deserialize<"); - #line 35 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 50 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field)); #line default #line hidden this.Write(">(),\r\n"); - #line 36 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 51 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" } #line default #line hidden - this.Write(" _ => json.Deserialize< "); + this.Write(" _ => json.Deserialize<"); - #line 37 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 52 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetInterfaceConcreteName())); #line default #line hidden - this.Write(">()\r\n };\r\n}\r\n\r\n\r\n\r\n\r\n[JsonConverter(typeof("); + this.Write(">()\r\n };\r\n}\r\n\r\n/// \r\n/// GraphQL interface "); + + #line 57 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); - #line 44 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line default + #line hidden + this.Write(" with all common fields\r\n/// \r\n[JsonConverter(typeof("); + + #line 59 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetInterfaceConverterName())); #line default #line hidden this.Write("))]\r\npublic interface "); - #line 45 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 60 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden this.Write(" "); - #line 45 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 60 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.GetInterfacesString())); #line default #line hidden this.Write("\r\n{\r\n"); - #line 47 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" - - foreach (var field in classType.AllFields) - { - var coreType = field.CoreType; - + #line 62 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + foreach (var field in classType.AllFields) { + var coreType = field.CoreType; #line default #line hidden - this.Write("\t[GraphQLMember(\""); + this.Write(" /// \r\n /// "); - #line 52 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 65 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden - this.Write("\")]\r\n\tpublic "); + this.Write(" field from GraphQL schema\r\n /// \r\n [GraphQLMember(\""); - #line 53 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 67 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); + + #line default + #line hidden + this.Write("\")]\r\n "); + + #line 68 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(coreType.CSharpTypeDefinition)); #line default #line hidden this.Write(" "); - #line 53 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 68 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden - this.Write(" { get; set; } \r\n"); + this.Write(" { get; set; }\r\n\r\n"); - #line 54 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" - - } - + #line 70 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + } #line default #line hidden - this.Write(" [GraphQLMember(\"__typename\")]\r\n public string __TypeName { get; set; }\r\n\r\n" + - "}\r\n\r\ninternal class "); + this.Write(" /// \r\n /// GraphQL __typename field for runtime type resolution\r\n" + + " /// \r\n [GraphQLMember(\"__typename\")]\r\n string __TypeName { g" + + "et; set; }\r\n}\r\n\r\n/// \r\n/// Concrete implementation of "); - #line 62 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 79 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); + + #line default + #line hidden + this.Write(" interface for fallback deserialization\r\n/// \r\ninternal class "); + + #line 81 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetInterfaceConcreteName())); #line default #line hidden this.Write(" : "); - #line 62 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 81 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(classType.Name)); #line default #line hidden this.Write("\r\n{\r\n"); - #line 64 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" - - foreach (var field in classType.AllFields) - { - var coreType = field.CoreType; - + #line 83 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + foreach (var field in classType.AllFields) { + var coreType = field.CoreType; #line default #line hidden - this.Write("\t[GraphQLMember(\""); + this.Write(" /// \r\n /// "); - #line 69 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 86 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden - this.Write("\")]\r\n\tpublic "); + this.Write(" field from GraphQL schema\r\n /// \r\n [GraphQLMember(\""); - #line 70 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 88 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); + + #line default + #line hidden + this.Write("\")]\r\n "); + + #line 89 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(coreType.CSharpTypeDefinition)); #line default #line hidden this.Write(" "); - #line 70 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + #line 89 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden - this.Write(" { get; set; } \r\n"); + this.Write(" { get; set; }\r\n\r\n"); - #line 71 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" - - } - + #line 91 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Interface\InterfaceTemplate.tt" + } #line default #line hidden - this.Write("\r\n [GraphQLMember(\"__typename\")]\r\n public string __TypeName { get; set; }\r\n" + - "\r\n}"); + this.Write(" /// \r\n /// GraphQL __typename field for runtime type resolution\r\n" + + " /// \r\n [GraphQLMember(\"__typename\")]\r\n string __TypeName { g" + + "et; set; }\r\n}"); return this.GenerationEnvironment.ToString(); } } diff --git a/src/Linq2GraphQL.Generator/Templates/Interface/InterfaceTemplate.tt b/src/Linq2GraphQL.Generator/Templates/Interface/InterfaceTemplate.tt index d81e2d17..6535ab9b 100644 --- a/src/Linq2GraphQL.Generator/Templates/Interface/InterfaceTemplate.tt +++ b/src/Linq2GraphQL.Generator/Templates/Interface/InterfaceTemplate.tt @@ -9,11 +9,17 @@ using Linq2GraphQL.Client.Converters; namespace <#= namespaceName #>; -public static class <#= classType.Name #>Extentions +/// +/// Extension methods for <#= classType.Name #> interface type casting +/// +public static class <#= classType.Name #>Extensions { - <# foreach (var field in implementedBy) { #> - + /// + /// Casts <#= classType.Name #> to <#= field #> if the runtime type matches + /// + /// The interface value to cast + /// <#= field #> instance or null if type doesn't match [GraphInterface] public static <#= field #> <#= field #>(this <#= classType.Name #> value) { @@ -23,56 +29,69 @@ public static class <#= classType.Name #>Extentions } return null; } + <# } #> } - +/// +/// JSON converter for <#= classType.Name #> interface deserialization +/// internal class <#= GetInterfaceConverterName() #> : InterfaceJsonConverter<<#= classType.Name #>> { + /// + /// Deserializes JSON to the appropriate concrete type based on __typename + /// + /// The GraphQL type name from __typename field + /// The JSON object to deserialize + /// Deserialized instance of the appropriate concrete type public override <#= classType.Name #> Deserialize(string typeName, JsonObject json) => typeName switch { - <# foreach (var field in implementedBy) { #> - "<#= field #>" => json.Deserialize<<#= field #>>(), +<# foreach (var field in implementedBy) { #> + "<#= field #>" => json.Deserialize<<#= field #>>(), <# } #> - _ => json.Deserialize< <#= GetInterfaceConcreteName() #>>() + _ => json.Deserialize<<#= GetInterfaceConcreteName() #>>() }; } - - - +/// +/// GraphQL interface <#= classType.Name #> with all common fields +/// [JsonConverter(typeof(<#= GetInterfaceConverterName() #>))] public interface <#= classType.Name #> <#= classType.GetInterfacesString() #> { -<# - foreach (var field in classType.AllFields) - { - var coreType = field.CoreType; -#> - [GraphQLMember("<#= field.Name #>")] - public <#= coreType.CSharpTypeDefinition #> <#= field.CSharpName #> { get; set; } -<# - } -#> - [GraphQLMember("__typename")] - public string __TypeName { get; set; } +<# foreach (var field in classType.AllFields) { + var coreType = field.CoreType; #> + /// + /// <#= field.Name #> field from GraphQL schema + /// + [GraphQLMember("<#= field.Name #>")] + <#= coreType.CSharpTypeDefinition #> <#= field.CSharpName #> { get; set; } +<# } #> + /// + /// GraphQL __typename field for runtime type resolution + /// + [GraphQLMember("__typename")] + string __TypeName { get; set; } } +/// +/// Concrete implementation of <#= classType.Name #> interface for fallback deserialization +/// internal class <#= GetInterfaceConcreteName() #> : <#= classType.Name #> { -<# - foreach (var field in classType.AllFields) - { - var coreType = field.CoreType; -#> - [GraphQLMember("<#= field.Name #>")] - public <#= coreType.CSharpTypeDefinition #> <#= field.CSharpName #> { get; set; } -<# - } -#> +<# foreach (var field in classType.AllFields) { + var coreType = field.CoreType; #> + /// + /// <#= field.Name #> field from GraphQL schema + /// + [GraphQLMember("<#= field.Name #>")] + <#= coreType.CSharpTypeDefinition #> <#= field.CSharpName #> { get; set; } +<# } #> + /// + /// GraphQL __typename field for runtime type resolution + /// [GraphQLMember("__typename")] - public string __TypeName { get; set; } - + string __TypeName { get; set; } } \ No newline at end of file diff --git a/src/Linq2GraphQL.Generator/Templates/Methods/IMethodsTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Methods/IMethodsTemplate.cs new file mode 100644 index 00000000..6fcf978d --- /dev/null +++ b/src/Linq2GraphQL.Generator/Templates/Methods/IMethodsTemplate.cs @@ -0,0 +1,428 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version: 17.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +namespace Linq2GraphQL.Generator.Templates.Methods +{ + using System; + + /// + /// Class to produce the template output + /// + + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] + public partial class IMethodsTemplate : IMethodsTemplateBase + { +#line hidden + /// + /// Create the template output + /// + public virtual string TransformText() + { + this.Write("using System;\r\nusing System.Collections.Generic;\r\nusing Linq2GraphQL.Client;\r\n"); + + #line 6 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + if (isSubscription) { + + #line default + #line hidden + this.Write("using Linq2GraphQL.Client.Subscriptions;\r\n"); + + #line 8 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + } + + #line default + #line hidden + this.Write("\r\nnamespace "); + + #line 10 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); + + #line default + #line hidden + this.Write(";\r\n\r\n/// \r\n/// Interface for "); + + #line 13 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ClassName)); + + #line default + #line hidden + this.Write(" GraphQL operations\r\n/// \r\npublic interface I"); + + #line 15 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ClassName)); + + #line default + #line hidden + this.Write("\r\n{\r\n"); + + #line 17 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + foreach (var field in methodsType.AllFields) { + var coreType = field.CoreType; + + #line default + #line hidden + this.Write(" /// \r\n /// Executes "); + + #line 20 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); + + #line default + #line hidden + this.Write(" GraphQL operation\r\n /// \r\n"); + + #line 22 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + if (field.IsDeprecated) { + + #line default + #line hidden + this.Write(" /// \r\n /// This operation is deprecated: "); + + #line 24 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(field.DeprecationReason)); + + #line default + #line hidden + this.Write("\r\n /// \r\n [Obsolete(\""); + + #line 26 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(field.DeprecationReason)); + + #line default + #line hidden + this.Write("\")]\r\n"); + + #line 27 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + } + + #line default + #line hidden + this.Write(" /// The operation parameters\r\n /// GraphQL query result of type" + + " "); + + #line 29 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(GetReturnTypeString(field))); + + #line default + #line hidden + this.Write("\r\n "); + + #line 30 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(GetReturnTypeString(field))); + + #line default + #line hidden + this.Write(" "); + + #line 30 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); + + #line default + #line hidden + this.Write("("); + + #line 30 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(field.GetArgString(false))); + + #line default + #line hidden + this.Write(");\r\n\r\n"); + + #line 32 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\IMethodsTemplate.tt" + } + + #line default + #line hidden + this.Write("}\r\n"); + return this.GenerationEnvironment.ToString(); + } + } + + #line default + #line hidden + #region Base class + /// + /// Base class for this transformation + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] + public class IMethodsTemplateBase + { + #region Fields + private global::System.Text.StringBuilder generationEnvironmentField; + private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; + private global::System.Collections.Generic.List indentLengthsField; + private string currentIndentField = ""; + private bool endsWithNewline; + private global::System.Collections.Generic.IDictionary sessionField; + #endregion + #region Properties + /// + /// The string builder that generation-time code is using to assemble generated output + /// + public System.Text.StringBuilder GenerationEnvironment + { + get + { + if ((this.generationEnvironmentField == null)) + { + this.generationEnvironmentField = new global::System.Text.StringBuilder(); + } + return this.generationEnvironmentField; + } + set + { + this.generationEnvironmentField = value; + } + } + /// + /// The error collection for the generation process + /// + public System.CodeDom.Compiler.CompilerErrorCollection Errors + { + get + { + if ((this.errorsField == null)) + { + this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); + } + return this.errorsField; + } + } + /// + /// A list of the lengths of each indent that was added with PushIndent + /// + private System.Collections.Generic.List indentLengths + { + get + { + if ((this.indentLengthsField == null)) + { + this.indentLengthsField = new global::System.Collections.Generic.List(); + } + return this.indentLengthsField; + } + } + /// + /// Gets the current indent we use when adding lines to the output + /// + public string CurrentIndent + { + get + { + return this.currentIndentField; + } + } + /// + /// Current transformation session + /// + public virtual global::System.Collections.Generic.IDictionary Session + { + get + { + return this.sessionField; + } + set + { + this.sessionField = value; + } + } + #endregion + #region Transform-time helpers + /// + /// Write text directly into the generated output + /// + public void Write(string textToAppend) + { + if (string.IsNullOrEmpty(textToAppend)) + { + return; + } + // If we're starting off, or if the previous text ended with a newline, + // we have to append the current indent first. + if (((this.GenerationEnvironment.Length == 0) + || this.endsWithNewline)) + { + this.GenerationEnvironment.Append(this.currentIndentField); + this.endsWithNewline = false; + } + // Check if the current text ends with a newline + if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) + { + this.endsWithNewline = true; + } + // This is an optimization. If the current indent is "", then we don't have to do any + // of the more complex stuff further down. + if ((this.currentIndentField.Length == 0)) + { + this.GenerationEnvironment.Append(textToAppend); + return; + } + // Everywhere there is a newline in the text, add an indent after it + textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); + // If the text ends with a newline, then we should strip off the indent added at the very end + // because the appropriate indent will be added when the next time Write() is called + if (this.endsWithNewline) + { + this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); + } + else + { + this.GenerationEnvironment.Append(textToAppend); + } + } + /// + /// Write text directly into the generated output + /// + public void WriteLine(string textToAppend) + { + this.Write(textToAppend); + this.GenerationEnvironment.AppendLine(); + this.endsWithNewline = true; + } + /// + /// Write formatted text directly into the generated output + /// + public void Write(string format, params object[] args) + { + this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Write formatted text directly into the generated output + /// + public void WriteLine(string format, params object[] args) + { + this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Raise an error + /// + public void Error(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + this.Errors.Add(error); + } + /// + /// Raise a warning + /// + public void Warning(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + error.IsWarning = true; + this.Errors.Add(error); + } + /// + /// Increase the indent + /// + public void PushIndent(string indent) + { + if ((indent == null)) + { + throw new global::System.ArgumentNullException("indent"); + } + this.currentIndentField = (this.currentIndentField + indent); + this.indentLengths.Add(indent.Length); + } + /// + /// Remove the last indent that was added with PushIndent + /// + public string PopIndent() + { + string returnValue = ""; + if ((this.indentLengths.Count > 0)) + { + int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; + this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); + if ((indentLength > 0)) + { + returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); + this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); + } + } + return returnValue; + } + /// + /// Remove any indentation + /// + public void ClearIndent() + { + this.indentLengths.Clear(); + this.currentIndentField = ""; + } + #endregion + #region ToString Helpers + /// + /// Utility class to produce culture-oriented representation of an object as a string. + /// + public class ToStringInstanceHelper + { + private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; + /// + /// Gets or sets format provider to be used by ToStringWithCulture method. + /// + public System.IFormatProvider FormatProvider + { + get + { + return this.formatProviderField ; + } + set + { + if ((value != null)) + { + this.formatProviderField = value; + } + } + } + /// + /// This is called from the compile/run appdomain to convert objects within an expression block to a string + /// + public string ToStringWithCulture(object objectToConvert) + { + if ((objectToConvert == null)) + { + throw new global::System.ArgumentNullException("objectToConvert"); + } + System.Type t = objectToConvert.GetType(); + System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { + typeof(System.IFormatProvider)}); + if ((method == null)) + { + return objectToConvert.ToString(); + } + else + { + return ((string)(method.Invoke(objectToConvert, new object[] { + this.formatProviderField }))); + } + } + } + private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); + /// + /// Helper to produce culture-oriented representation of an object as a string + /// + public ToStringInstanceHelper ToStringHelper + { + get + { + return this.toStringHelperField; + } + } + #endregion + } + #endregion +} diff --git a/src/Linq2GraphQL.Generator/Templates/Methods/IMethodsTemplate.tt b/src/Linq2GraphQL.Generator/Templates/Methods/IMethodsTemplate.tt new file mode 100644 index 00000000..8b9489b9 --- /dev/null +++ b/src/Linq2GraphQL.Generator/Templates/Methods/IMethodsTemplate.tt @@ -0,0 +1,33 @@ +<#@ template language="C#" #> +<#@ assembly name="System.Core" #> +using System; +using System.Collections.Generic; +using Linq2GraphQL.Client; +<# if (isSubscription) { #> +using Linq2GraphQL.Client.Subscriptions; +<# } #> + +namespace <#= namespaceName #>; + +/// +/// Interface for <#= ClassName #> GraphQL operations +/// +public interface I<#= ClassName #> +{ +<# foreach (var field in methodsType.AllFields) { + var coreType = field.CoreType; #> + /// + /// Executes <#= field.Name #> GraphQL operation + /// +<# if (field.IsDeprecated) { #> + /// + /// This operation is deprecated: <#= field.DeprecationReason #> + /// + [Obsolete("<#= field.DeprecationReason #>")] +<# } #> + /// The operation parameters + /// GraphQL query result of type <#= GetReturnTypeString(field) #> + <#= GetReturnTypeString(field) #> <#= field.CSharpName #>(<#= field.GetArgString(false) #>); + +<# } #> +} diff --git a/src/Linq2GraphQL.Generator/Templates/Methods/IMethodsTemplate.tt.cs b/src/Linq2GraphQL.Generator/Templates/Methods/IMethodsTemplate.tt.cs new file mode 100644 index 00000000..75d6922d --- /dev/null +++ b/src/Linq2GraphQL.Generator/Templates/Methods/IMethodsTemplate.tt.cs @@ -0,0 +1,32 @@ +namespace Linq2GraphQL.Generator.Templates.Methods; + +public partial class IMethodsTemplate +{ + private readonly GraphqlType methodsType; + private readonly string namespaceName; + private readonly string operationType; + + public IMethodsTemplate(GraphqlType methodsType, string namespaceName, string operationType) + { + this.methodsType = methodsType; + this.namespaceName = namespaceName; + this.operationType = operationType; + } + + private string ClassName => methodsType.Name + "Methods"; + private bool isSubscription => operationType == "OperationType.Subscription"; + + private string GetReturnTypeString(Field field) + { + var cSharpTypeNameFull = field.CoreType.CSharpTypeDefinition; + if (isSubscription) + { + return $"GraphSubscription<{cSharpTypeNameFull}>"; + } + if (field.SupportCursorPaging()) + { + return $"GraphCursorQuery<{cSharpTypeNameFull}>"; + } + return $"GraphQuery<{cSharpTypeNameFull}>"; + } +} diff --git a/src/Linq2GraphQL.Generator/Templates/Methods/MethodsTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Methods/MethodsTemplate.cs index cb5bc769..0f0da9d7 100644 --- a/src/Linq2GraphQL.Generator/Templates/Methods/MethodsTemplate.cs +++ b/src/Linq2GraphQL.Generator/Templates/Methods/MethodsTemplate.cs @@ -15,7 +15,7 @@ namespace Linq2GraphQL.Generator.Templates.Methods /// Class to produce the template output /// - #line 1 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class MethodsTemplate : MethodsTemplateBase { @@ -27,7 +27,7 @@ public virtual string TransformText() { this.Write("using System.Collections.Generic;\r\nusing System;\r\nusing Linq2GraphQL.Client;\r\n"); - #line 6 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 6 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" if (isSubscription) { @@ -37,7 +37,7 @@ public virtual string TransformText() #line hidden this.Write("using Linq2GraphQL.Client.Subscriptions;\r\n"); - #line 11 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 11 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" } @@ -46,28 +46,35 @@ public virtual string TransformText() #line hidden this.Write("\r\nnamespace "); - #line 15 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 15 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); #line default #line hidden this.Write(";\r\n\r\npublic class "); - #line 17 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 17 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ClassName)); + + #line default + #line hidden + this.Write(" : I"); + + #line 17 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(ClassName)); #line default #line hidden this.Write("\r\n{\r\n private readonly GraphClient client;\r\n\r\n public "); - #line 21 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 21 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(ClassName)); #line default #line hidden this.Write("(GraphClient client)\r\n {\r\n this.client = client;\r\n }\r\n\r\n "); - #line 26 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 26 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" foreach (var field in methodsType.AllFields) { @@ -77,49 +84,49 @@ public virtual string TransformText() #line default #line hidden - #line 31 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 31 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" if (field.IsDeprecated) { #line default #line hidden this.Write("[Obsolete(\""); - #line 32 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 32 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.DeprecationReason)); #line default #line hidden this.Write("\")]\r\n "); - #line 33 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 33 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" } #line default #line hidden this.Write("public "); - #line 34 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 34 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetReturnTypeString(field))); #line default #line hidden this.Write(" "); - #line 34 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 34 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.CSharpName)); #line default #line hidden this.Write("("); - #line 34 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 34 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.GetArgString(false))); #line default #line hidden this.Write(")\r\n {\r\n\t var arguments = new List\r\n {\r\n "); - #line 38 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 38 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" foreach (var arg in field.Args) { @@ -129,28 +136,28 @@ public virtual string TransformText() #line hidden this.Write("\t new(\""); - #line 42 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 42 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(arg.Name)); #line default #line hidden this.Write("\",\""); - #line 42 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 42 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(arg.CoreType.GraphQLTypeDefinition)); #line default #line hidden this.Write("\", "); - #line 42 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 42 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(arg.Name.ToCamelCase())); #line default #line hidden this.Write("),\r\n "); - #line 43 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 43 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" } @@ -159,28 +166,28 @@ public virtual string TransformText() #line hidden this.Write(" };\r\n\r\n return "); - #line 48 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 48 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(GetReturnBuilderString(field))); #line default #line hidden this.Write("(client, \""); - #line 48 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 48 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field.Name)); #line default #line hidden this.Write("\", "); - #line 48 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 48 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(operationType)); #line default #line hidden this.Write(", arguments); \r\n }\r\n\r\n "); - #line 51 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" + #line 51 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Methods\MethodsTemplate.tt" } diff --git a/src/Linq2GraphQL.Generator/Templates/Methods/MethodsTemplate.tt b/src/Linq2GraphQL.Generator/Templates/Methods/MethodsTemplate.tt index c9f2fb0c..ba2f1335 100644 --- a/src/Linq2GraphQL.Generator/Templates/Methods/MethodsTemplate.tt +++ b/src/Linq2GraphQL.Generator/Templates/Methods/MethodsTemplate.tt @@ -1,54 +1,54 @@ <#@ template language="C#" #> <#@ assembly name="System.Core" #> -using System.Collections.Generic; using System; +using System.Collections.Generic; using Linq2GraphQL.Client; -<# - if (isSubscription) - { -#> +<# if (isSubscription) { #> using Linq2GraphQL.Client.Subscriptions; -<# - } -#> +<# } #> namespace <#= namespaceName #>; -public class <#= ClassName #> +/// +/// Implementation of <#= ClassName #> GraphQL operations +/// +public class <#= ClassName #> : I<#= ClassName #> { private readonly GraphClient client; + /// + /// Initializes a new instance of the <#= ClassName #> class + /// + /// The GraphQL client instance public <#= ClassName #>(GraphClient client) { - this.client = client; + this.client = client ?? throw new ArgumentNullException(nameof(client)); } - <# - foreach (var field in methodsType.AllFields) - { - var coreType = field.CoreType; -#> +<# foreach (var field in methodsType.AllFields) { + var coreType = field.CoreType; #> + /// + /// Executes <#= field.Name #> GraphQL operation + /// <# if (field.IsDeprecated) { #> -[Obsolete("<#= field.DeprecationReason #>")] - <# } #> -public <#= GetReturnTypeString(field) #> <#= field.CSharpName #>(<#= field.GetArgString(false) #>) + /// + /// This operation is deprecated: <#= field.DeprecationReason #> + /// + [Obsolete("<#= field.DeprecationReason #>")] +<# } #> + /// The operation parameters + /// GraphQL query result of type <#= GetReturnTypeString(field) #> + public <#= GetReturnTypeString(field) #> <#= field.CSharpName #>(<#= field.GetArgString(false) #>) { - var arguments = new List - { - <# - foreach (var arg in field.Args) + var arguments = new List { -#> - new("<#= arg.Name #>","<#= arg.CoreType.GraphQLTypeDefinition #>", <#= arg.Name.ToCamelCase() #>), - <# - } -#> - }; +<# foreach (var arg in field.Args) { #> + new("<#= arg.Name #>", "<#= arg.CoreType.GraphQLTypeDefinition #>", <#= arg.Name.ToCamelCase() #>), +<# } #> + }; - return <#= GetReturnBuilderString(field) #>(client, "<#= field.Name #>", <#= operationType #>, arguments); + return <#= GetReturnBuilderString(field) #>(client, "<#= field.Name #>", <#= operationType #>, arguments); } - <# - } -#> +<# } #> } diff --git a/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.cs index deba8aeb..2c78fa4f 100644 --- a/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.cs +++ b/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.cs @@ -18,7 +18,7 @@ namespace Linq2GraphQL.Generator.Templates.Scalars /// Class to produce the template output /// - #line 1 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" + #line 1 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class ScalarTemplate : ScalarTemplateBase { @@ -31,28 +31,28 @@ public virtual string TransformText() this.Write("\r\nusing Linq2GraphQL.Client;\r\nusing System.Text.Json.Serialization;\r\n\r\nnamespace " + ""); - #line 10 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" + #line 10 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(namespaceName)); #line default #line hidden this.Write(";\r\n\r\n /// \r\n /// "); - #line 13 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" + #line 13 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(scalarType.SummaryDescription)); #line default #line hidden this.Write("\r\n /// \r\n [JsonConverter(typeof(CustomScalarConverter<"); - #line 15 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" + #line 15 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(className)); #line default #line hidden this.Write(">))]\r\n public partial class "); - #line 16 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" + #line 16 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(className)); #line default diff --git a/test/Linq2GraphQL.TestClient/Generated/Client/MutationMethods.cs b/test/Linq2GraphQL.TestClient/Generated/Client/MutationMethods.cs index cac0dd73..3fb3aceb 100644 --- a/test/Linq2GraphQL.TestClient/Generated/Client/MutationMethods.cs +++ b/test/Linq2GraphQL.TestClient/Generated/Client/MutationMethods.cs @@ -11,7 +11,7 @@ namespace Linq2GraphQL.TestClient; -public class MutationMethods +public class MutationMethods : IMutationMethods { private readonly GraphClient client; diff --git a/test/Linq2GraphQL.TestClient/Generated/Client/QueryMethods.cs b/test/Linq2GraphQL.TestClient/Generated/Client/QueryMethods.cs index 0d10de9e..173786bf 100644 --- a/test/Linq2GraphQL.TestClient/Generated/Client/QueryMethods.cs +++ b/test/Linq2GraphQL.TestClient/Generated/Client/QueryMethods.cs @@ -11,7 +11,7 @@ namespace Linq2GraphQL.TestClient; -public class QueryMethods +public class QueryMethods : IQueryMethods { private readonly GraphClient client; diff --git a/test/Linq2GraphQL.TestClient/Generated/Client/SampleClient.cs b/test/Linq2GraphQL.TestClient/Generated/Client/SampleClient.cs index ff453cb4..9f814853 100644 --- a/test/Linq2GraphQL.TestClient/Generated/Client/SampleClient.cs +++ b/test/Linq2GraphQL.TestClient/Generated/Client/SampleClient.cs @@ -12,7 +12,7 @@ namespace Linq2GraphQL.TestClient; -public class SampleClient +public class SampleClient : ISampleClient { public SampleClient(HttpClient httpClient, [FromKeyedServices("SampleClient")]IOptions options, IServiceProvider provider) { @@ -22,8 +22,8 @@ public SampleClient(HttpClient httpClient, [FromKeyedServices("SampleClient")]IO Subscription = new SubscriptionMethods(client); } - public QueryMethods Query { get; private set; } - public MutationMethods Mutation { get; private set; } - public SubscriptionMethods Subscription { get; private set; } + public IQueryMethods Query { get; private set; } + public IMutationMethods Mutation { get; private set; } + public ISubscriptionMethods Subscription { get; private set; } } \ No newline at end of file diff --git a/test/Linq2GraphQL.TestClient/Generated/Client/SubscriptionMethods.cs b/test/Linq2GraphQL.TestClient/Generated/Client/SubscriptionMethods.cs index aef2bfe7..6d3f0010 100644 --- a/test/Linq2GraphQL.TestClient/Generated/Client/SubscriptionMethods.cs +++ b/test/Linq2GraphQL.TestClient/Generated/Client/SubscriptionMethods.cs @@ -12,7 +12,7 @@ namespace Linq2GraphQL.TestClient; -public class SubscriptionMethods +public class SubscriptionMethods : ISubscriptionMethods { private readonly GraphClient client; diff --git a/test/Linq2GraphQL.TestClient/Generated/Interfaces/IMutationMethods.cs b/test/Linq2GraphQL.TestClient/Generated/Interfaces/IMutationMethods.cs new file mode 100644 index 00000000..d7399031 --- /dev/null +++ b/test/Linq2GraphQL.TestClient/Generated/Interfaces/IMutationMethods.cs @@ -0,0 +1,18 @@ +//--------------------------------------------------------------------- +// This code was automatically generated by Linq2GraphQL +// Please don't edit this file +// Github:https://github.com/linq2graphql/linq2graphql.client +// Url: https://linq2graphql.com +//--------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using Linq2GraphQL.Client; + +namespace Linq2GraphQL.TestClient; + +public interface IMutationMethods +{ + GraphQuery SetName(string name); + GraphQuery AddCustomer(CustomerInput customer); +} diff --git a/test/Linq2GraphQL.TestClient/Generated/Interfaces/IQueryMethods.cs b/test/Linq2GraphQL.TestClient/Generated/Interfaces/IQueryMethods.cs new file mode 100644 index 00000000..0c8359af --- /dev/null +++ b/test/Linq2GraphQL.TestClient/Generated/Interfaces/IQueryMethods.cs @@ -0,0 +1,23 @@ +//--------------------------------------------------------------------- +// This code was automatically generated by Linq2GraphQL +// Please don't edit this file +// Github:https://github.com/linq2graphql/linq2graphql.client +// Url: https://linq2graphql.com +//--------------------------------------------------------------------- + +using System.Collections.Generic; +using Linq2GraphQL.Client; + +namespace Linq2GraphQL.TestClient; + +public interface IQueryMethods +{ + GraphQuery Hello(string name = null); + GraphQuery CustomerReturnNull(); + GraphQuery> Customers(); + GraphQuery OrdersNoBackwardPagination(int? first = null, string after = null, OrderFilterInput where = null, List order = null); + GraphCursorQuery OrdersNoTotalCount(int? first = null, string after = null, int? last = null, string before = null, OrderFilterInput where = null, List order = null); + GraphCursorQuery Orders(int? first = null, string after = null, int? last = null, string before = null, OrderFilterInput where = null, List order = null); + GraphCursorQuery Animals(int? first = null, string after = null, int? last = null, string before = null, IAnimalFilterInput where = null, List order = null); + GraphQuery OrdersOffsetPaging(int? skip = null, int? take = null, OrderFilterInput where = null, List order = null); +} diff --git a/test/Linq2GraphQL.TestClient/Generated/Interfaces/ISampleClient.cs b/test/Linq2GraphQL.TestClient/Generated/Interfaces/ISampleClient.cs new file mode 100644 index 00000000..155ce520 --- /dev/null +++ b/test/Linq2GraphQL.TestClient/Generated/Interfaces/ISampleClient.cs @@ -0,0 +1,17 @@ +//--------------------------------------------------------------------- +// This code was automatically generated by Linq2GraphQL +// Please don't edit this file +// Github:https://github.com/linq2graphql/linq2graphql.client +// Url: https://linq2graphql.com +//--------------------------------------------------------------------- + +using Linq2GraphQL.Client; + +namespace Linq2GraphQL.TestClient; + +public interface ISampleClient +{ + IQueryMethods Query { get; } + IMutationMethods Mutation { get; } + ISubscriptionMethods Subscription { get; } +} diff --git a/test/Linq2GraphQL.TestClient/Generated/Interfaces/ISubscriptionMethods.cs b/test/Linq2GraphQL.TestClient/Generated/Interfaces/ISubscriptionMethods.cs new file mode 100644 index 00000000..d2e45a3e --- /dev/null +++ b/test/Linq2GraphQL.TestClient/Generated/Interfaces/ISubscriptionMethods.cs @@ -0,0 +1,16 @@ +//--------------------------------------------------------------------- +// This code was automatically generated by Linq2GraphQL +// Please don't edit this file +// Github:https://github.com/linq2graphql/linq2graphql.client +// Url: https://linq2graphql.com +//--------------------------------------------------------------------- + +using Linq2GraphQL.Client.Subscriptions; + +namespace Linq2GraphQL.TestClient; + +public interface ISubscriptionMethods +{ + GraphSubscription CustomerAdded(); + GraphSubscription CustomerNameAdded(string name = null); +} diff --git a/test/Linq2GraphQL.TestClientNullable/Generated/Client/MutationMethods.cs b/test/Linq2GraphQL.TestClientNullable/Generated/Client/MutationMethods.cs index 39137d8c..0942a94a 100644 --- a/test/Linq2GraphQL.TestClientNullable/Generated/Client/MutationMethods.cs +++ b/test/Linq2GraphQL.TestClientNullable/Generated/Client/MutationMethods.cs @@ -11,7 +11,7 @@ namespace Linq2GraphQL.TestClientNullable; -public class MutationMethods +public class MutationMethods : IMutationMethods { private readonly GraphClient client; diff --git a/test/Linq2GraphQL.TestClientNullable/Generated/Client/QueryMethods.cs b/test/Linq2GraphQL.TestClientNullable/Generated/Client/QueryMethods.cs index 273d6fa3..3e264a0b 100644 --- a/test/Linq2GraphQL.TestClientNullable/Generated/Client/QueryMethods.cs +++ b/test/Linq2GraphQL.TestClientNullable/Generated/Client/QueryMethods.cs @@ -11,7 +11,7 @@ namespace Linq2GraphQL.TestClientNullable; -public class QueryMethods +public class QueryMethods : IQueryMethods { private readonly GraphClient client; diff --git a/test/Linq2GraphQL.TestClientNullable/Generated/Client/SampleNullableClient.cs b/test/Linq2GraphQL.TestClientNullable/Generated/Client/SampleNullableClient.cs index 377537b0..3c24b38f 100644 --- a/test/Linq2GraphQL.TestClientNullable/Generated/Client/SampleNullableClient.cs +++ b/test/Linq2GraphQL.TestClientNullable/Generated/Client/SampleNullableClient.cs @@ -12,7 +12,7 @@ namespace Linq2GraphQL.TestClientNullable; -public class SampleNullableClient +public class SampleNullableClient : ISampleNullableClient { public SampleNullableClient(HttpClient httpClient, [FromKeyedServices("SampleNullableClient")]IOptions options, IServiceProvider provider) { @@ -21,7 +21,7 @@ public SampleNullableClient(HttpClient httpClient, [FromKeyedServices("SampleNul Mutation = new MutationMethods(client); } - public QueryMethods Query { get; private set; } - public MutationMethods Mutation { get; private set; } + public IQueryMethods Query { get; private set; } + public IMutationMethods Mutation { get; private set; } } \ No newline at end of file diff --git a/test/Linq2GraphQL.TestClientNullable/Generated/Interfaces/IMutationMethods.cs b/test/Linq2GraphQL.TestClientNullable/Generated/Interfaces/IMutationMethods.cs new file mode 100644 index 00000000..bb4eefab --- /dev/null +++ b/test/Linq2GraphQL.TestClientNullable/Generated/Interfaces/IMutationMethods.cs @@ -0,0 +1,15 @@ +//--------------------------------------------------------------------- +// This code was automatically generated by Linq2GraphQL +// Please don't edit this file +// Github:https://github.com/linq2graphql/linq2graphql.client +// Url: https://linq2graphql.com +//--------------------------------------------------------------------- + +using Linq2GraphQL.Client; + +namespace Linq2GraphQL.TestClientNullable; + +public interface IMutationMethods +{ + GraphQuery UpdatePerson(PersonInput person); +} diff --git a/test/Linq2GraphQL.TestClientNullable/Generated/Interfaces/IQueryMethods.cs b/test/Linq2GraphQL.TestClientNullable/Generated/Interfaces/IQueryMethods.cs new file mode 100644 index 00000000..67836038 --- /dev/null +++ b/test/Linq2GraphQL.TestClientNullable/Generated/Interfaces/IQueryMethods.cs @@ -0,0 +1,24 @@ +//--------------------------------------------------------------------- +// This code was automatically generated by Linq2GraphQL +// Please don't edit this file +// Github:https://github.com/linq2graphql/linq2graphql.client +// Url: https://linq2graphql.com +//--------------------------------------------------------------------- + +using System.Collections.Generic; +using Linq2GraphQL.Client; + +namespace Linq2GraphQL.TestClientNullable; + +public interface IQueryMethods +{ + GraphQuery Item(); + [Obsolete("This is an really old method! please d not use it!!")] + GraphQuery ItemDraft(); + GraphQuery> CustomerList(); + GraphQuery CustomerNullable(); + GraphQuery?> CustomerListAllNullable(); + GraphQuery?> CustomerListNullable(); + GraphQuery>> CustomerListInList(); + GraphQuery Person(); +} diff --git a/test/Linq2GraphQL.TestClientNullable/Generated/Interfaces/ISampleNullableClient.cs b/test/Linq2GraphQL.TestClientNullable/Generated/Interfaces/ISampleNullableClient.cs new file mode 100644 index 00000000..3ecd5e33 --- /dev/null +++ b/test/Linq2GraphQL.TestClientNullable/Generated/Interfaces/ISampleNullableClient.cs @@ -0,0 +1,16 @@ +//--------------------------------------------------------------------- +// This code was automatically generated by Linq2GraphQL +// Please don't edit this file +// Github:https://github.com/linq2graphql/linq2graphql.client +// Url: https://linq2graphql.com +//--------------------------------------------------------------------- + +using Linq2GraphQL.Client; + +namespace Linq2GraphQL.TestClientNullable; + +public interface ISampleNullableClient +{ + IQueryMethods Query { get; } + IMutationMethods Mutation { get; } +} diff --git a/test/Linq2GraphQL.Tests/ClientMockingTests.cs b/test/Linq2GraphQL.Tests/ClientMockingTests.cs new file mode 100644 index 00000000..8f905f0e --- /dev/null +++ b/test/Linq2GraphQL.Tests/ClientMockingTests.cs @@ -0,0 +1,141 @@ +using Linq2GraphQL.Client; +using Linq2GraphQL.Client.Subscriptions; +using Linq2GraphQL.TestClient; +using Microsoft.Extensions.Options; +using Moq; +using Shouldly; + +namespace Linq2GraphQL.Tests; + +public class ClientMockingTests +{ + [Fact] + public void Mock_ISampleClient_ShouldAllowMocking() + { + // Arrange + var mockClient = new Mock(); + var mockQuery = new Mock(); + var mockMutation = new Mock(); + var mockSubscription = new Mock(); + + mockClient.Setup(c => c.Query).Returns(mockQuery.Object); + mockClient.Setup(c => c.Mutation).Returns(mockMutation.Object); + mockClient.Setup(c => c.Subscription).Returns(mockSubscription.Object); + + // Act + var query = mockClient.Object.Query; + var mutation = mockClient.Object.Mutation; + var subscription = mockClient.Object.Subscription; + + // Assert + query.ShouldBe(mockQuery.Object); + mutation.ShouldBe(mockMutation.Object); + subscription.ShouldBe(mockSubscription.Object); + } + + [Fact] + public void Mock_IQueryMethods_ShouldAllowMockingQueryExecution() + { + // Arrange + var mockQueryMethods = new Mock(); + mockQueryMethods.Setup(q => q.Hello("Test")) + .Returns(new GraphQuery(null, "hello", OperationType.Query, new List())); + + // Act + var result = mockQueryMethods.Object.Hello("Test"); + + // Assert + result.ShouldNotBeNull(); + mockQueryMethods.Verify(q => q.Hello("Test"), Times.Once); + } + + [Fact] + public void Mock_IMutationMethods_ShouldAllowMockingMutationExecution() + { + // Arrange + var mockMutationMethods = new Mock(); + var customerInput = new CustomerInput + { + CustomerId = Guid.NewGuid(), + CustomerName = "Test Customer", + Status = CustomerStatus.Active, + Orders = new List() + }; + + mockMutationMethods.Setup(m => m.AddCustomer(customerInput)) + .Returns(new GraphQuery(null, "addCustomer", OperationType.Mutation, new List())); + + // Act + var result = mockMutationMethods.Object.AddCustomer(customerInput); + + // Assert + result.ShouldNotBeNull(); + mockMutationMethods.Verify(m => m.AddCustomer(customerInput), Times.Once); + } + + [Fact] + public void Mock_ISubscriptionMethods_ShouldAllowMockingSubscription() + { + // Arrange + var mockSubscriptionMethods = new Mock(); + + mockSubscriptionMethods.Setup(s => s.CustomerAdded()) + .Returns(new GraphSubscription(null, "customerAdded", OperationType.Subscription, new List())); + + // Act + var result = mockSubscriptionMethods.Object.CustomerAdded(); + + // Assert + result.ShouldNotBeNull(); + mockSubscriptionMethods.Verify(s => s.CustomerAdded(), Times.Once); + } + + [Fact] + public void DependencyInjection_WithMockedInterfaces_ShouldWork() + { + // Arrange + var mockQueryMethods = new Mock(); + var mockMutationMethods = new Mock(); + var mockSubscriptionMethods = new Mock(); + + // Act & Assert - This test verifies that interfaces can be mocked + // demonstrating the flexibility of interfaces for testing + mockQueryMethods.ShouldNotBeNull(); + mockMutationMethods.ShouldNotBeNull(); + mockSubscriptionMethods.ShouldNotBeNull(); + + // Verify that mocked interfaces can be used + mockQueryMethods.Setup(q => q.Hello("Test")) + .Returns(new GraphQuery(null, "hello", OperationType.Query, new List())); + + var result = mockQueryMethods.Object.Hello("Test"); + result.ShouldNotBeNull(); + } + + [Fact] + public void Interface_Contract_ShouldMatchConcreteImplementation() + { + // Arrange + var concreteClient = typeof(SampleClient); + var interfaceClient = typeof(ISampleClient); + + // Act + var concreteProperties = concreteClient.GetProperties() + .Where(p => p.Name == "Query" || p.Name == "Mutation" || p.Name == "Subscription") + .OrderBy(p => p.Name) + .ToList(); + + var interfaceProperties = interfaceClient.GetProperties() + .OrderBy(p => p.Name) + .ToList(); + + // Assert + concreteProperties.Count.ShouldBe(interfaceProperties.Count); + + for (int i = 0; i < concreteProperties.Count; i++) + { + concreteProperties[i].Name.ShouldBe(interfaceProperties[i].Name); + concreteProperties[i].PropertyType.ShouldBe(interfaceProperties[i].PropertyType); + } + } +} diff --git a/test/Linq2GraphQL.Tests/GeneratedClientInterfaceTests.cs b/test/Linq2GraphQL.Tests/GeneratedClientInterfaceTests.cs new file mode 100644 index 00000000..a169446e --- /dev/null +++ b/test/Linq2GraphQL.Tests/GeneratedClientInterfaceTests.cs @@ -0,0 +1,101 @@ +using System.Reflection; +using Linq2GraphQL.TestClient; +using Shouldly; + +namespace Linq2GraphQL.Tests; + +public class GeneratedClientInterfaceTests +{ + [Fact] + public void SampleClient_ShouldImplement_ISampleClient() + { + // Arrange & Act + var client = typeof(SampleClient); + var interfaceType = typeof(ISampleClient); + + // Assert + interfaceType.IsAssignableFrom(client).ShouldBeTrue(); + } + + [Fact] + public void QueryMethods_ShouldImplement_IQueryMethods() + { + // Arrange & Act + var queryMethods = typeof(QueryMethods); + var interfaceType = typeof(IQueryMethods); + + // Assert + interfaceType.IsAssignableFrom(queryMethods).ShouldBeTrue(); + } + + [Fact] + public void MutationMethods_ShouldImplement_IMutationMethods() + { + // Arrange & Act + var mutationMethods = typeof(MutationMethods); + var interfaceType = typeof(IMutationMethods); + + // Assert + interfaceType.IsAssignableFrom(mutationMethods).ShouldBeTrue(); + } + + [Fact] + public void SubscriptionMethods_ShouldImplement_ISubscriptionMethods() + { + // Arrange & Act + var subscriptionMethods = typeof(SubscriptionMethods); + var interfaceType = typeof(ISubscriptionMethods); + + // Assert + interfaceType.IsAssignableFrom(subscriptionMethods).ShouldBeTrue(); + } + + [Fact] + public void SampleClient_Properties_ShouldBeInterfaceTypes() + { + // Arrange + var clientType = typeof(SampleClient); + + // Act + var queryProperty = clientType.GetProperty("Query"); + var mutationProperty = clientType.GetProperty("Mutation"); + var subscriptionProperty = clientType.GetProperty("Subscription"); + + // Assert + queryProperty.ShouldNotBeNull(); + queryProperty.PropertyType.ShouldBe(typeof(IQueryMethods)); + + mutationProperty.ShouldNotBeNull(); + mutationProperty.PropertyType.ShouldBe(typeof(IMutationMethods)); + + subscriptionProperty.ShouldNotBeNull(); + subscriptionProperty.PropertyType.ShouldBe(typeof(ISubscriptionMethods)); + } + + [Fact] + public void Interface_ShouldExposeAllPublicMethods() + { + // Arrange + var queryMethodsType = typeof(QueryMethods); + var iQueryMethodsType = typeof(IQueryMethods); + + // Act + var concreteMethods = GetPublicInstanceMethods(queryMethodsType); + var interfaceMethods = iQueryMethodsType.GetMethods() + .Select(m => m.Name) + .OrderBy(n => n) + .ToList(); + + // Assert + concreteMethods.ShouldBe(interfaceMethods); + } + + private static List GetPublicInstanceMethods(Type type) + { + return type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) + .Where(m => !m.IsSpecialName) // Exclude properties + .Select(m => m.Name) + .OrderBy(n => n) + .ToList(); + } +} diff --git a/test/Linq2GraphQL.Tests/InterfaceContractTests.cs b/test/Linq2GraphQL.Tests/InterfaceContractTests.cs new file mode 100644 index 00000000..939bb258 --- /dev/null +++ b/test/Linq2GraphQL.Tests/InterfaceContractTests.cs @@ -0,0 +1,167 @@ +using System.Reflection; +using Linq2GraphQL.TestClient; +using Shouldly; + +namespace Linq2GraphQL.Tests; + +public class InterfaceContractTests +{ + [Fact] + public void IQueryMethods_ShouldExposeAllPublicMethodsFromQueryMethods() + { + // Arrange + var concreteType = typeof(QueryMethods); + var interfaceType = typeof(IQueryMethods); + + // Act + var concreteMethods = GetPublicInstanceMethods(concreteType); + var interfaceMethods = GetInterfaceMethods(interfaceType); + + // Assert + interfaceMethods.ShouldBeSubsetOf(concreteMethods); + concreteMethods.ShouldBeSubsetOf(interfaceMethods); + } + + [Fact] + public void IMutationMethods_ShouldExposeAllPublicMethodsFromMutationMethods() + { + // Arrange + var concreteType = typeof(MutationMethods); + var interfaceType = typeof(IMutationMethods); + + // Act + var concreteMethods = GetPublicInstanceMethods(concreteType); + var interfaceMethods = GetInterfaceMethods(interfaceType); + + // Assert + interfaceMethods.ShouldBeSubsetOf(concreteMethods); + concreteMethods.ShouldBeSubsetOf(interfaceMethods); + } + + [Fact] + public void ISubscriptionMethods_ShouldExposeAllPublicMethodsFromSubscriptionMethods() + { + // Arrange + var concreteType = typeof(SubscriptionMethods); + var interfaceType = typeof(ISubscriptionMethods); + + // Act + var concreteMethods = GetPublicInstanceMethods(concreteType); + var interfaceMethods = GetInterfaceMethods(interfaceType); + + // Assert + interfaceMethods.ShouldBeSubsetOf(concreteMethods); + concreteMethods.ShouldBeSubsetOf(interfaceMethods); + } + + [Fact] + public void ISampleClient_ShouldExposeAllPublicPropertiesFromSampleClient() + { + // Arrange + var concreteType = typeof(SampleClient); + var interfaceType = typeof(ISampleClient); + + // Act + var concreteProperties = GetPublicProperties(concreteType); + var interfaceProperties = GetInterfaceProperties(interfaceType); + + // Assert + interfaceProperties.ShouldBeSubsetOf(concreteProperties); + concreteProperties.ShouldBeSubsetOf(interfaceProperties); + } + + [Fact] + public void Interface_MethodSignatures_ShouldMatchConcreteImplementation() + { + // Arrange + var concreteType = typeof(QueryMethods); + var interfaceType = typeof(IQueryMethods); + + // Act & Assert + foreach (var interfaceMethod in interfaceType.GetMethods()) + { + var concreteMethod = concreteType.GetMethod(interfaceMethod.Name, + BindingFlags.Public | BindingFlags.Instance); + + concreteMethod.ShouldNotBeNull($"Method {interfaceMethod.Name} should exist in concrete class"); + + // Verify parameter types match + var interfaceParams = interfaceMethod.GetParameters(); + var concreteParams = concreteMethod.GetParameters(); + + interfaceParams.Length.ShouldBe(concreteParams.Length); + + for (int i = 0; i < interfaceParams.Length; i++) + { + interfaceParams[i].ParameterType.ShouldBe(concreteParams[i].ParameterType); + interfaceParams[i].Name.ShouldBe(concreteParams[i].Name); + } + + // Verify return type matches + interfaceMethod.ReturnType.ShouldBe(concreteMethod.ReturnType); + } + } + + [Fact] + public void Interface_PropertySignatures_ShouldMatchConcreteImplementation() + { + // Arrange + var concreteType = typeof(SampleClient); + var interfaceType = typeof(ISampleClient); + + // Act & Assert + foreach (var interfaceProperty in interfaceType.GetProperties()) + { + var concreteProperty = concreteType.GetProperty(interfaceProperty.Name); + + concreteProperty.ShouldNotBeNull($"Property {interfaceProperty.Name} should exist in concrete class"); + + // Verify property type matches + interfaceProperty.PropertyType.ShouldBe(concreteProperty.PropertyType); + + // Verify getter/setter accessibility + if (interfaceProperty.CanRead) + { + concreteProperty.CanRead.ShouldBeTrue($"Property {interfaceProperty.Name} should be readable"); + } + + if (interfaceProperty.CanWrite) + { + concreteProperty.CanWrite.ShouldBeTrue($"Property {interfaceProperty.Name} should be writable"); + } + } + } + + private static List GetPublicInstanceMethods(Type type) + { + return type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) + .Where(m => !m.IsSpecialName) // Exclude properties + .Select(m => m.Name) + .OrderBy(n => n) + .ToList(); + } + + private static List GetInterfaceMethods(Type type) + { + return type.GetMethods() + .Select(m => m.Name) + .OrderBy(n => n) + .ToList(); + } + + private static List GetPublicProperties(Type type) + { + return type.GetProperties(BindingFlags.Public | BindingFlags.Instance) + .Select(p => p.Name) + .OrderBy(n => n) + .ToList(); + } + + private static List GetInterfaceProperties(Type type) + { + return type.GetProperties() + .Select(p => p.Name) + .OrderBy(n => n) + .ToList(); + } +} diff --git a/test/Linq2GraphQL.Tests/Linq2GraphQL.Tests.csproj b/test/Linq2GraphQL.Tests/Linq2GraphQL.Tests.csproj index 788d1b91..d7e13526 100644 --- a/test/Linq2GraphQL.Tests/Linq2GraphQL.Tests.csproj +++ b/test/Linq2GraphQL.Tests/Linq2GraphQL.Tests.csproj @@ -10,10 +10,11 @@ - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -25,10 +26,10 @@ - - - - + + + + diff --git a/test/Linq2GraphQL.Tests/SampleClientFixture.cs b/test/Linq2GraphQL.Tests/SampleClientFixture.cs index 1e46413e..fa71fe25 100644 --- a/test/Linq2GraphQL.Tests/SampleClientFixture.cs +++ b/test/Linq2GraphQL.Tests/SampleClientFixture.cs @@ -8,6 +8,7 @@ namespace Linq2GraphQL.Tests; public class SampleClientFixture : IDisposable { internal readonly SampleClient sampleClient; + internal readonly ISampleClient sampleClientInterface; public SampleClientFixture() { @@ -21,6 +22,10 @@ public SampleClientFixture() { SubscriptionProtocol = SubscriptionProtocol.ServerSentEvents, UseSafeMode = true }), application.Services); + + // Cast to interface for testing interface functionality + sampleClientInterface = sampleClient; + //Please note currently only ServerSentEvents work in test project } diff --git a/test/Linq2GraphQL.Tests/SampleClientNullableFixture.cs b/test/Linq2GraphQL.Tests/SampleClientNullableFixture.cs index 5633bfc4..8e851938 100644 --- a/test/Linq2GraphQL.Tests/SampleClientNullableFixture.cs +++ b/test/Linq2GraphQL.Tests/SampleClientNullableFixture.cs @@ -8,6 +8,7 @@ namespace Linq2GraphQL.Tests; public class SampleNullableClientFixture : IDisposable { internal readonly SampleNullableClient sampleClient; + internal readonly ISampleNullableClient sampleClientInterface; public SampleNullableClientFixture() { @@ -21,6 +22,10 @@ public SampleNullableClientFixture() { SubscriptionProtocol = SubscriptionProtocol.ServerSentEvents, UseSafeMode = false }), application.Services); + + // Cast to interface for testing interface functionality + sampleClientInterface = sampleClient; + //Please note currently only ServerSentEvents work in test project }