Skip to content

Commit f9fa0cc

Browse files
committed
sort schema imports
1 parent 977598e commit f9fa0cc

4 files changed

Lines changed: 90 additions & 63 deletions

File tree

codegen/schema/spago.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ You can edit this file as you like.
5353
, "spec-discovery"
5454
, "strings"
5555
, "strings-extra"
56+
, "tidy"
5657
, "tidy-codegen"
5758
, "transformers"
5859
, "tuples"

codegen/schema/src/GraphQL/Client/CodeGen/SchemaCst.purs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ import Data.Unfoldable (none)
2929
import GraphQL.Client.CodeGen.Types (InputOptions, GqlEnum)
3030
import GraphQL.Client.CodeGen.UtilCst (qualifiedTypeToName)
3131
import Partial.Unsafe (unsafePartial)
32-
import PureScript.CST.Types (Module, Proper, QualifiedName)
32+
import PureScript.CST.Types (ImportDecl, Module(..), ModuleHeader(..), ModuleName(..), Proper, QualifiedName)
3333
import PureScript.CST.Types as CST
3434
import Tidy.Codegen (declDerive, declNewtype, declType, docComments, leading, lineComments, typeApp, typeArrow, typeCtor, typeRecord, typeRecordEmpty, typeRow, typeString, typeWildcard)
3535
import Tidy.Codegen.Class (class OverLeadingComments, toQualifiedName)
3636
import Tidy.Codegen.Monad (CodegenT, codegenModule, importFrom, importType)
37+
import Tidy.Util (nameOf)
38+
import Unsafe.Coerce (unsafeCoerce)
3739

3840
gqlToPursSchema :: InputOptions -> String -> String -> AST.Document -> Array GqlEnum -> Module Void
3941
gqlToPursSchema
@@ -42,7 +44,7 @@ gqlToPursSchema
4244
mName
4345
(AST.Document defs)
4446
enums = do
45-
unsafePartial $ codegenModule mName do
47+
sortImports $ unsafePartial $ codegenModule mName do
4648
directives <- importFrom directivesMName (importType "Directives")
4749
voidT <- importQualified "Data.Void" "Void"
4850
proxyT <- importQualified "Type.Proxy" "Proxy"
@@ -350,6 +352,12 @@ gqlToPursSchema
350352
tell
351353
$ [ schema ] <> declarations
352354

355+
sortImports :: Module Void -> Module Void
356+
sortImports (Module m@{ header: ModuleHeader header }) = Module m { header = ModuleHeader header { imports = Array.sortWith getModuleName header.imports } }
357+
where
358+
getModuleName :: ImportDecl Void -> ModuleName
359+
getModuleName = unwrap >>> _.module >>> nameOf
360+
353361
hasRootOp :: forall f. Foldable f => f AST.Definition -> AST.OperationType -> Boolean
354362
hasRootOp defs op = defs # any case _ of
355363
AST.Definition_TypeSystemDefinition (AST.TypeSystemDefinition_SchemaDefinition (AST.SchemaDefinition d)) ->

0 commit comments

Comments
 (0)