Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions build/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let src = path [ solutionRoot; "src" ]
let tests = path [ solutionRoot; "tests" ]
let tasks = path [ solutionRoot; "tasks" ]

let [<Literal>] TargetFramework = "net6.0"
let [<Literal>] TargetFramework = "net8.0"

let test() =
if Shell.Exec(Tools.dotnet, "run", tests) <> 0
Expand Down Expand Up @@ -159,7 +159,7 @@ let generateProjectFile (imports: string seq) (defaultTargets: string option) (t
yield! imports |> Seq.map (fun path -> MSBuildXElement.Import(path) :> obj)
yield XElement.ofStringName("PropertyGroup",
XElement.ofStringName("OutputType", "Exe"),
XElement.ofStringName("TargetFramework", "net6.0")) :> obj
XElement.ofStringName("TargetFramework", "net8.0")) :> obj
yield! targets |> Seq.map (fun target -> MSBuildXElement.Target(target) :> obj)
}))

Expand All @@ -185,7 +185,7 @@ let generateProjectFileForTask (targetFrameworks : string list) (package :MSBuil
yield XElement.ofStringName("PropertyGroup",
XElement.ofStringName("OutputType", "Exe"),
match targetFrameworks with
| [] -> XElement.ofStringName("TargetFramework", "net6.0")
| [] -> XElement.ofStringName("TargetFramework", "net8.0")
| [head] -> XElement.ofStringName("TargetFramework", head)
| frameworks -> XElement.ofStringName("TargetFrameworks", frameworks |> String.concat(";"))
) :> obj
Expand Down Expand Up @@ -216,7 +216,7 @@ let createProjectFileAndRun imports (projectFileName : string) =
let createProjectFileForTaskAndRun (directory: string) (project : string) (package :MSBuildPackageReference list) (schema : string) (target : string) (queries : string) =
let projectFileName = project + ".fsproj"
let project = generateProjectFileForTask
[ "net6.0" ]
[ "net8.0" ]
package
project
schema
Expand All @@ -232,7 +232,7 @@ let createProjectFileForTaskAndRun (directory: string) (project : string) (packa
let createMultiFrameworkProjectFileForTaskAndRun (directory: string) (project : string) (packages :MSBuildPackageReference list) (schema : string) (target : string) (queries : string) =
let projectFileName = project + ".fsproj"
let project = generateProjectFileForTask
[ "netcoreapp3.1"; "net6.0" ]
[ "net8.0" ]
packages
project
schema
Expand All @@ -247,7 +247,7 @@ let createMultiFrameworkProjectFileForTaskAndRun (directory: string) (project :
let createProjectFileAndRebuild (directory: string) (project : string) (packages :MSBuildPackageReference list) (schema: string) (target: string) (queries: string) =
let projectFileName = project + ".fsproj"
let project = generateProjectFileForTask
[ "net6.0" ]
[ "net8.0" ]
packages
project
schema
Expand All @@ -264,7 +264,7 @@ let tasksIntegration() =
let generateGQLClientTask =
{ Name = "GenerateGraphQLClient"
FullName = "Snowflaqe.Tasks.GenerateGraphQLClient"
AssemblyFile = path [ solutionRoot; "tasks"; "bin"; "Release"; "net6.0"; "Snowflaqe.Tasks.dll" ]
AssemblyFile = path [ solutionRoot; "tasks"; "bin"; "Release"; "net8.0"; "Snowflaqe.Tasks.dll" ]
Parameters =
seq {
KeyValuePair("Output", path [ solutionRoot; "src"; "output"] :> obj)
Expand Down Expand Up @@ -334,7 +334,7 @@ let multiFrameworkTasksIntegration() =
let generateGQLClientTask =
{ Name = "GenerateGraphQLClient"
FullName = "Snowflaqe.Tasks.GenerateGraphQLClient"
AssemblyFile = path [ solutionRoot; "tasks"; "bin"; "Release"; "net6.0"; "Snowflaqe.Tasks.dll" ]
AssemblyFile = path [ solutionRoot; "tasks"; "bin"; "Release"; "net8.0"; "Snowflaqe.Tasks.dll" ]
Parameters =
seq {
KeyValuePair("Output", path [ solutionRoot; "src"; "output"] :> obj)
Expand Down Expand Up @@ -545,7 +545,7 @@ let main (args: string[]) =
| [| "publish" |] -> publish()
| [| "publish-tasks" |] -> publishTasks()
| [| "integration" |] -> integration()
| [| "fsproj-integration" |] ->
| [| "fsproj-integration" |] ->
clear()
fsprojIntegration()
clear()
Expand Down
4 changes: 2 additions & 2 deletions build/Snowflaqe.Build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,7 +18,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.6" />
<PackageReference Update="FSharp.Core" Version="8.0.403" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"sdk": {
"version": "6.0.400",
"rollForward": "latestMinor"
}
}
}
38 changes: 25 additions & 13 deletions src/CodeGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,31 @@ let createInputRecord (input: GraphqlInputObject) =

let fields = input.fields |> List.filter (fun field -> not field.deprecated)

let recordRepresentation = SynTypeDefnSimpleReprRecordRcd.Create [
for field in fields ->
let recordFieldType = createFSharpType None field.fieldType
let recordField = SynFieldRcd.Create(field.fieldName |> ensureLegalFieldName, recordFieldType)
{ recordField with XmlDoc = PreXmlDoc.Create field.description }
]

let simpleType = SynTypeDefnSimpleReprRcd.Record recordRepresentation

SynModuleDecl.CreateSimpleType(info, simpleType)


if List.isEmpty fields then
// Generate a class type: type <InputType>() = inherit obj()
let members = [
SynMemberDefn.CreateImplicitCtor()
SynMemberDefn.Inherit(SynType.CreateLongIdent "obj()", None, Range.range0)
]

let typeDef =
{ Info = info
Repr = SynTypeDefnRepr.ObjectModel(kind = SynTypeDefnKind.Unspecified, members = members, range = range.Zero)
Members = []
ImplicitConstructor = None
Range = range.Zero
Trivia = { SynTypeDefnTrivia.Zero with LeadingKeyword = SynTypeDefnLeadingKeyword.Type range.Zero }
}
SynModuleDecl.Types( [typeDef.FromRcd], range0)
else
let recordRepresentation = SynTypeDefnSimpleReprRecordRcd.Create [
for field in fields ->
let recordFieldType = createFSharpType None field.fieldType
let recordField = SynFieldRcd.Create(field.fieldName |> ensureLegalFieldName, recordFieldType)
{ recordField with XmlDoc = PreXmlDoc.Create field.description }
]
let simpleType = SynTypeDefnSimpleReprRcd.Record recordRepresentation
SynModuleDecl.CreateSimpleType(info, simpleType)

let createGlobalTypes (schema: GraphqlSchema) (normalizeEnumCases: bool) =
let enums =
Expand All @@ -415,7 +428,6 @@ let createGlobalTypes (schema: GraphqlSchema) (normalizeEnumCases: bool) =

List.append enums inputs


let nextTick (name: string) (visited: ResizeArray<string>) =
if not (visited.Contains name) then
name
Expand Down
28 changes: 14 additions & 14 deletions src/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,22 @@ let readConfig (file: string) =
let validateAndPrint (queryFile: string) (document: GraphqlDocument) (schema: GraphqlSchema) =
match Query.validate document schema with
| ValidationResult.Success ->
colorprintfn "✔ Query $blue[%s] is valid" queryFile
colorprintfn "✔ Query $blue[%s] is valid" queryFile
true
| ValidationResult.SchemaDoesNotHaveQueryType ->
colorprintfn "⚠️ Error while validating query $red[%s]" queryFile
colorprintfn " Schema doesn't implement a Query type"
colorprintfn " Error while validating query $red[%s]" queryFile
colorprintfn " Schema doesn't implement a Query type"
false
| ValidationResult.SchemaDoesNotHaveMutationType ->
colorprintfn "⚠️ Error while validating query $red[%s]" queryFile
colorprintfn " Schema doesn't implement a Mutation type"
colorprintfn " Error while validating query $red[%s]" queryFile
colorprintfn " Schema doesn't implement a Mutation type"
false
| ValidationResult.NoQueryOrMutationProvided ->
colorprintfn "⚠️ Error while validating query $red[%s]" queryFile
colorprintfn " No query or mutation request were provided"
colorprintfn " Error while validating query $red[%s]" queryFile
colorprintfn " No query or mutation request were provided"
false
| ValidationResult.QueryErrors errors ->
colorprintfn "⚠️ Error while validating query $red[%s]" queryFile
colorprintfn " Error while validating query $red[%s]" queryFile
for error in errors do
match error with
| QueryError.UnknownField (fieldName, parent, typeName) ->
Expand Down Expand Up @@ -278,7 +278,7 @@ let runConfig (config: Config) =
| Error errorMessage ->
colorprintfn "$red[%s]" errorMessage; 1
| Ok schema ->
printfn "✔ Schema loaded successfully"
printfn "✔ Schema loaded successfully"
colorprintfn "⏳ Validating queries within $green[%s]" config.queries
let mutable errorCount = 0
let queryFiles = seq {
Expand All @@ -290,7 +290,7 @@ let runConfig (config: Config) =
let query = File.ReadAllText queryFile
match Query.parse query with
| Error parseError ->
colorprintf "⚠️ Could not parse query $red[%s]:%s%s%s" queryFile Environment.NewLine parseError Environment.NewLine
colorprintf " Could not parse query $red[%s]:%s%s%s" queryFile Environment.NewLine parseError Environment.NewLine
errorCount <- errorCount + 1
| Ok parsedQuery ->
if not (validateAndPrint queryFile parsedQuery schema)
Expand All @@ -316,7 +316,7 @@ let generate (config: Config) =
colorprintfn "⏳ Loading GraphQL schema from $green[%s]" config.schema
match Introspection.loadSchema config.schema with
| Error errorMessage ->
colorprintfn "$red[%s]" errorMessage
colorprintfn "{❌}$red[%s]" errorMessage
Error 1
| Ok schema ->
let mutable invalidQuery = false
Expand All @@ -330,7 +330,7 @@ let generate (config: Config) =
let query = File.ReadAllText queryFile
match Query.parse query with
| Error parseError ->
colorprintf "⚠️ Could not parse query $red[%s]:%s%s%s" queryFile Environment.NewLine parseError Environment.NewLine
colorprintf " Could not parse query $red[%s]:%s%s%s" queryFile Environment.NewLine parseError Environment.NewLine
invalidQuery <- true
| Ok query ->
invalidQuery <- not (validateAndPrint queryFile query schema)
Expand Down Expand Up @@ -744,7 +744,7 @@ let main argv =
|> Seq.tryFind (fun file -> file.ToLower().EndsWith("snowflaqe.json"))
|> function
| None ->
colorprintfn "⚠️ No configuration file found. Expecting JSON file $yellow[%s] in the current working directory" "snowflaqe.json"
colorprintfn " No configuration file found. Expecting JSON file $yellow[%s] in the current working directory" "snowflaqe.json"
1
| Some configFile ->
runConfigFile configFile
Expand Down Expand Up @@ -792,7 +792,7 @@ let main argv =
|> Seq.tryFind (fun file -> file.ToLower().EndsWith("snowflaqe.json"))
|> function
| None ->
colorprintfn "⚠️ No configuration file found. Expecting JSON file $yellow[%s] in the current working directory" "snowflaqe.json"
colorprintfn " No configuration file found. Expecting JSON file $yellow[%s] in the current working directory" "snowflaqe.json"
1
| Some configFile -> generateOrExit configFile

Expand Down
16 changes: 11 additions & 5 deletions src/Schema.fs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,13 @@ let (|Interface|_|) (typeJson: JToken) =
)

let possibleTypes =
if isNull typeJson.["possibleTypes"] then
let possibleTypes = typeJson.["possibleTypes"]
if isNull possibleTypes then
[ ]
elif isNull (possibleTypes :?> JArray) then
raise (Newtonsoft.Json.JsonException "'possibleTypes' is not array")
else
[ for possibleType in unbox<JArray> typeJson.["possibleTypes"] do
[ for possibleType in unbox<JArray> possibleTypes do
yield possibleType.["name"].ToString() ]
Some {
name = name
Expand All @@ -223,10 +226,13 @@ let (|Union|_|) (typeJson: JToken) =
let name = typeJson.["name"].ToString()
let description = stringOrNone typeJson "description" |> normalizeComment
let possibleTypes =
if isNull typeJson.["possibleTypes"] then
let possibleTypes = typeJson.["possibleTypes"]
if isNull possibleTypes then
[ ]
elif isNull (possibleTypes :?> JArray) then
raise (Newtonsoft.Json.JsonException "'possibleTypes' is not array")
else
[ for possibleType in unbox<JArray> typeJson.["possibleTypes"] do
[ for possibleType in unbox<JArray> possibleTypes do
yield possibleType.["name"].ToString() ]

Some {
Expand Down Expand Up @@ -331,4 +337,4 @@ let findMutation (schema: GraphqlSchema) =
| Some typeName ->
match findTypeByName typeName schema with
| Some (GraphqlType.Object queryType) -> Some queryType
| _ -> None
| _ -> None
6 changes: 3 additions & 3 deletions src/Snowflaqe.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<PackAsTool>true</PackAsTool>
<IsPackable>true</IsPackable>
<RollForward>Major</RollForward>
<TargetFramework Condition=" '$(IsNuget)' != '' ">net6.0</TargetFramework>
<TargetFrameworks Condition=" '$(IsNuget)' == '' ">netstandard2.0;netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFramework Condition=" '$(IsNuget)' != '' ">net8.0</TargetFramework>
<TargetFrameworks Condition=" '$(IsNuget)' == '' ">netstandard2.0;net8.0</TargetFrameworks>
<Version>1.48.0</Version>
<PackageReleaseNotes>Add warning-generating keyword 'params' to reserved keywords list</PackageReleaseNotes>
<AutoGenerateBindingRedirects Condition=" '$(IsNuget)' == '' ">true</AutoGenerateBindingRedirects>
Expand All @@ -31,7 +31,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.6" />
<PackageReference Update="FSharp.Core" Version="8.0.403" />
<PackageReference Include="BlackFox.ColoredPrintf" Version="1.0.5" />
<PackageReference Include="Fantomas.Core" Version="5.1.3" />
<PackageReference Include="Fantomas.FCS" Version="5.1.3" />
Expand Down
Loading