Skip to content

Commit

Permalink
fix up interfaces add usings
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemurray committed Nov 14, 2023
1 parent c22dc95 commit 58c6201
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/dotnet-gqlgen/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch ",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net6.0/dotnet-gqlgen.dll",
"args": [],
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
}
]
}
8 changes: 6 additions & 2 deletions src/dotnet-gqlgen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class Program
public string ScalarMapping { get; }
[Option(LongName = "output", ShortName = "o", Description = "Output directory")]
public string OutputDir { get; } = "output";
[Option(LongName = "usings", ShortName = "u", Description = "Extra using statements to add to generated code.")]
public string Usings { get; } = "";

public Dictionary<string, string> dotnetToGqlTypeMappings = new Dictionary<string, string> {
{"string", "String"},
Expand Down Expand Up @@ -113,7 +115,8 @@ private async void OnExecute()
Types = allTypes,
Enums = typeInfo.Enums,
Mutation = typeInfo.Mutation,
CmdArgs = $"-n {Namespace} -c {ClientClassName} -m {ScalarMapping}"
CmdArgs = $"-n {Namespace} -c {ClientClassName} -m {ScalarMapping}",
Usings = Usings
});
Directory.CreateDirectory(OutputDir);
File.WriteAllText($"{OutputDir}/GeneratedResultTypes.cs", resultTypes);
Expand All @@ -124,7 +127,8 @@ private async void OnExecute()
SchemaFile = Source,
Types = allTypes,
Mutation = typeInfo.Mutation,
CmdArgs = $"-n {Namespace} -c {ClientClassName} -m {ScalarMapping}"
CmdArgs = $"-n {Namespace} -c {ClientClassName} -m {ScalarMapping}",
Usings = Usings
});
Directory.CreateDirectory(OutputDir);
File.WriteAllText($"{OutputDir}/GeneratedQueryTypes.cs", queryTypes);
Expand Down
2 changes: 2 additions & 0 deletions src/dotnet-gqlgen/SchemaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public TypeInfo(IEnumerable<Field> fields, string name, string description, bool
Name = name;
Description = description;
IsInput = isInput;
IsInterface = isInterface;
}

public List<Field> Fields { get; }
Expand All @@ -114,6 +115,7 @@ public string DescriptionForComment(int indent = 8)
}

public bool IsInput { get; }
public bool IsInterface { get; }
}

public class Field
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet-gqlgen/SchemaVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public override object VisitInterfaceDef(GraphQLSchemaParser.InterfaceDefContext
if (schemaInfo.Types.ContainsKey(context.typeName.GetText()))
schemaInfo.Types[context.typeName.GetText()].Fields.AddRange(fields);
else
schemaInfo.Types.Add(context.typeName.GetText(), new TypeInfo(fields, context.typeName.GetText(), desc, true));
schemaInfo.Types.Add(context.typeName.GetText(), new TypeInfo(fields, context.typeName.GetText(), desc, false, true));
return result;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/dotnet-gqlgen/queryTypes.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using DotNetGqlClient;
@Model.Usings

/// <summary>
/// Generated classes used for making GraphQL API calls with a typed interface.
Expand All @@ -25,6 +26,7 @@ namespace @Model.Namespace
@gqlType.DescriptionForComment(4)
@:/// </summary>
}

@:public abstract class @gqlType.QueryName : @gqlType.Name
@:{
@foreach(var field in gqlType.Fields)
Expand Down
3 changes: 2 additions & 1 deletion src/dotnet-gqlgen/resultTypes.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using DotNetGqlClient;
@Model.Usings

/// <summary>
/// Generated classes used for making GraphQL API calls with a typed interface.
Expand Down Expand Up @@ -37,6 +37,7 @@ namespace @Model.Namespace
@gqlType.DescriptionForComment(4)
@:/// </summary>
}
@* We make interfaces as classes for now *@
@:public class @gqlType.Name
@:{
@foreach(var field in gqlType.Fields)
Expand Down

0 comments on commit 58c6201

Please sign in to comment.