-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization.Metadata; | ||
using Extism; | ||
|
||
namespace CodegenBot; | ||
|
||
public interface ICodegenBotImports | ||
{ | ||
string GraphQL<T>(GraphQLRequest<T> request, JsonTypeInfo<GraphQLRequest<T>> jsonTypeInfo); | ||
void Log(LogEvent logEvent); | ||
} | ||
|
||
public class CodegenBotImports : ICodegenBotImports | ||
{ | ||
public string GraphQL<T>(GraphQLRequest<T> request, JsonTypeInfo<GraphQLRequest<T>> jsonTypeInfo) | ||
{ | ||
var json = request.ToJsonString(jsonTypeInfo); | ||
using var block = Pdk.Allocate(json); | ||
var ptr = Imports.ExternGraphQL(block.Offset); | ||
var response = MemoryBlock.Find(ptr).ReadString(); | ||
response = JsonUtility.EnsureTypeDiscriminatorPropertiesComeFirst(response); | ||
return response; | ||
} | ||
|
||
public void Log(LogEvent logEvent) | ||
{ | ||
var json = JsonSerializer.Serialize(logEvent, LogEventJsonContext.Default.LogEvent); | ||
using var block = Pdk.Allocate(json); | ||
Imports.ExternLog(block.Offset); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters