Skip to content

Commit 2f154c7

Browse files
committed
removes arg gql from genned schema #102
1 parent 605823e commit 2f154c7

File tree

5 files changed

+17
-40
lines changed

5 files changed

+17
-40
lines changed

Diff for: gen-schema-bundled.mjs

+9-9
Original file line numberDiff line numberDiff line change
@@ -42141,7 +42141,7 @@ var template2 = function(v) {
4214142141
var enumImports = intercalate6("\n")(mapFlipped3(v.enums)(function(v1) {
4214242142
return "import " + (v.modulePrefix + ("Schema." + (v.name + (".Enum." + (v1 + (" (" + (v1 + ")")))))));
4214342143
}));
42144-
return "module " + (v.modulePrefix + ("Schema." + (v.name + (" where\n\nimport Data.Maybe (Maybe)\nimport Data.Newtype (class Newtype)\nimport GraphQL.Client.Args (class ArgGql, class RecordArg, NotNull)\nimport GraphQL.Client.Union (GqlUnion)\nimport " + (maybe("GraphQL.Client.ID (ID)")(getImport)(v.idImport) + ("\n" + (enumImports + ("\n\n" + (v.mainSchemaCode + "\n")))))))));
42144+
return "module " + (v.modulePrefix + ("Schema." + (v.name + (" where\n\nimport Data.Maybe (Maybe)\nimport Data.Newtype (class Newtype)\nimport GraphQL.Client.Args (NotNull)\nimport GraphQL.Client.Union (GqlUnion)\nimport " + (maybe("GraphQL.Client.ID (ID)")(getImport)(v.idImport) + ("\n" + (enumImports + ("\n\n" + (v.mainSchemaCode + "\n")))))))));
4214542145
};
4214642146

4214742147
// output/GraphQL.Client.CodeGen.Schema/index.js
@@ -42385,7 +42385,7 @@ var gqlToPursMainSchemaCode = function(v) {
4238542385
return notNullTypeToPurs(v1.value0);
4238642386
}
4238742387
;
42388-
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 429, column 16 - line 432, column 72): " + [v1.constructor.name]);
42388+
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 416, column 16 - line 419, column 72): " + [v1.constructor.name]);
4238942389
};
4239042390
var notNullTypeToPurs = function(v1) {
4239142391
if (v1 instanceof NonNullType_NamedType) {
@@ -42396,7 +42396,7 @@ var gqlToPursMainSchemaCode = function(v) {
4239642396
return listTypeToPurs(v1.value0);
4239742397
}
4239842398
;
42399-
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 443, column 23 - line 445, column 51): " + [v1.constructor.name]);
42399+
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 430, column 23 - line 432, column 51): " + [v1.constructor.name]);
4240042400
};
4240142401
var listTypeToPursNullable = function(t) {
4240242402
return wrapMaybe(listTypeToPurs(t));
@@ -42450,7 +42450,7 @@ var gqlToPursMainSchemaCode = function(v) {
4245042450
return wrapNotNull(argNotNullTypeToPurs(v1.value0));
4245142451
}
4245242452
;
42453-
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 413, column 19 - line 416, column 89): " + [v1.constructor.name]);
42453+
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 400, column 19 - line 403, column 89): " + [v1.constructor.name]);
4245442454
};
4245542455
var argNotNullTypeToPurs = function(v1) {
4245642456
if (v1 instanceof NonNullType_NamedType) {
@@ -42461,7 +42461,7 @@ var gqlToPursMainSchemaCode = function(v) {
4246142461
return argListTypeToPurs(v1.value0);
4246242462
}
4246342463
;
42464-
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 419, column 26 - line 421, column 54): " + [v1.constructor.name]);
42464+
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 406, column 26 - line 408, column 54): " + [v1.constructor.name]);
4246542465
};
4246642466
var argListTypeToPurs = function(v1) {
4246742467
return "(Array " + (argTypeToPurs(v1) + ")");
@@ -42486,7 +42486,7 @@ var gqlToPursMainSchemaCode = function(v) {
4248642486
return v2.value0.moduleName + ("." + v2.value0.typeName);
4248742487
}
4248842488
;
42489-
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 402, column 10 - line 407, column 53): " + [v2.constructor.name]);
42489+
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 389, column 10 - line 394, column 53): " + [v2.constructor.name]);
4249042490
}()));
4249142491
};
4249242492
};
@@ -42499,7 +42499,7 @@ var gqlToPursMainSchemaCode = function(v) {
4249942499
var tName = typeName_(v1.name);
4250042500
return docComment3(v1.description) + ("newtype " + (tName + (" = " + (tName + (maybe("{}")(function(v2) {
4250142501
return inputValueToFieldsDefinitionToPurs(tName)(v2);
42502-
})(v1.inputFieldsDefinition) + ("\nderive instance newtype" + (tName + (" :: Newtype " + (tName + (" _" + ("\ninstance argToGql" + (tName + (" :: (Newtype " + (tName + (" {| p}, RecordArg p a u) => ArgGql " + (tName + " { | a }"))))))))))))))));
42502+
})(v1.inputFieldsDefinition) + ("\nderive instance newtype" + (tName + (" :: Newtype " + (tName + " _")))))))));
4250342503
};
4250442504
var inputValueDefinitionsToPurs = function(v1) {
4250542505
return inlineComment(v1.description) + (safeFieldname(v1.name) + (" :: " + argTypeToPurs(v1.type)));
@@ -42527,7 +42527,7 @@ var gqlToPursMainSchemaCode = function(v) {
4252742527
return wrapMaybe(v2.value0.moduleName + ("." + v2.value0.typeName));
4252842528
}
4252942529
;
42530-
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 292, column 10 - line 297, column 65): " + [v2.constructor.name]);
42530+
throw new Error("Failed pattern match at GraphQL.Client.CodeGen.Schema (line 285, column 10 - line 290, column 65): " + [v2.constructor.name]);
4253142531
}())));
4253242532
};
4253342533
};
@@ -42540,7 +42540,7 @@ var gqlToPursMainSchemaCode = function(v) {
4254042540
var tName = typeName_(v1.name);
4254142541
return docComment3(v1.description) + function() {
4254242542
if (v.useNewtypesForRecords) {
42543-
return "newtype " + (typeName_(v1.name) + (" = " + (typeName_(v1.name) + (" " + (maybe("{}")(fieldsDefinitionToPurs(tName))(v1.fieldsDefinition) + ("\nderive instance newtype" + (tName + (" :: Newtype " + (tName + (" _" + ("\ninstance argToGql" + (tName + (" :: (Newtype " + (tName + (" {| p}, RecordArg p a u) => ArgGql " + (tName + " { | a }"))))))))))))))));
42543+
return "newtype " + (typeName_(v1.name) + (" = " + (typeName_(v1.name) + (" " + (maybe("{}")(fieldsDefinitionToPurs(tName))(v1.fieldsDefinition) + ("\nderive instance newtype" + (tName + (" :: Newtype " + (tName + " _")))))))));
4254442544
}
4254542545
;
4254642546
return "type " + (typeName_(v1.name) + foldMap5(function(fd) {

Diff for: src/GraphQL/Client/Args.purs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Data.Bifunctor (class Bifunctor)
66
import Data.Date (Date)
77
import Data.DateTime (DateTime)
88
import Data.Maybe (Maybe)
9+
import Data.Newtype (class Newtype)
910
import Data.Symbol (class IsSymbol)
1011
import Data.Time (Time)
1112
import GraphQL.Client.Variable (Var)
@@ -73,7 +74,8 @@ else instance argToGqlMaybe :: ArgGql param arg => ArgGql param (Maybe arg)
7374
else instance argToGqlArray :: ArgGql param arg => ArgGql (Array param) (Array arg)
7475
else instance argToGqlArrayOne :: ArgGql param arg => ArgGql (Array param) arg
7576
else instance argVar :: ArgGql param arg => ArgGql param (Var sym arg)
76-
77+
else instance argToGqlRecord :: RecordArg p a u => ArgGql { | p } { | a }
78+
else instance argToGqlNewtypeRecord :: (Newtype n {| p}, RecordArg p a u) => ArgGql n { | a }
7779
class IsNotNull :: forall k1 k2. k1 -> k2 -> Constraint
7880
class IsNotNull param arg
7981

@@ -125,7 +127,6 @@ instance argToGqlTime :: ArgGql Time Time
125127

126128
instance argToGqlDateTime :: ArgGql DateTime DateTime
127129

128-
instance argToGqlRecord :: RecordArg p a u => ArgGql { | p } { | a }
129130

130131
class HMapWithIndex (ArgPropToGql p) { | a } u <= RecordArg p a u
131132

Diff for: src/GraphQL/Client/CodeGen/Schema.purs

+1-14
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,6 @@ gqlToPursMainSchemaCode { gqlScalarsToPursTypes, externalTypes, fieldTypeOverrid
256256
<> " :: Newtype "
257257
<> tName
258258
<> " _"
259-
<> "\ninstance argToGql"
260-
<> tName
261-
<> " :: (Newtype "
262-
<> tName
263-
<> " {| p}, RecordArg p a u) => ArgGql "
264-
<> tName
265-
<> " { | a }"
266259
else
267260
"type "
268261
<> typeName_ name
@@ -372,13 +365,7 @@ gqlToPursMainSchemaCode { gqlScalarsToPursTypes, externalTypes, fieldTypeOverrid
372365
<> " :: Newtype "
373366
<> tName
374367
<> " _"
375-
<> "\ninstance argToGql"
376-
<> tName
377-
<> " :: (Newtype "
378-
<> tName
379-
<> " {| p}, RecordArg p a u) => ArgGql "
380-
<> tName
381-
<> " { | a }"
368+
382369

383370
inputValueToFieldsDefinitionToPurs :: String -> List AST.InputValueDefinition -> String
384371
inputValueToFieldsDefinitionToPurs objectName definitions =

Diff for: src/GraphQL/Client/CodeGen/Template/Schema.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ template { name, enums, idImport, mainSchemaCode, modulePrefix } =
1818
1919
import Data.Maybe (Maybe)
2020
import Data.Newtype (class Newtype)
21-
import GraphQL.Client.Args (class ArgGql, class RecordArg, NotNull)
21+
import GraphQL.Client.Args (NotNull)
2222
import GraphQL.Client.Union (GqlUnion)
2323
import """ <> maybe defaultIdImport getImport idImport <> """
2424
""" <> enumImports <> """

Diff for: test/GraphQL/Client/CodeGen/SchemaFromGqlToPurs.Test.purs

+3-14
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ spec =
149149
, subscription: "\n { prop :: Int\n }"
150150
}
151151
<> "\n\nnewtype MyType = MyType \n { prop :: (Maybe Int)\n }\nderive instance newtypeMyType :: Newtype MyType _"
152-
<> "\ninstance argToGqlMyType :: (Newtype MyType {| p}, RecordArg p a u) => ArgGql MyType { | a }"
153152
gql `shouldParseTo` result
154153
it "converts input types" do
155154
let
@@ -173,14 +172,12 @@ newtype QueryRoot = QueryRoot
173172
-> Int
174173
}
175174
derive instance newtypeQueryRoot :: Newtype QueryRoot _
176-
instance argToGqlQueryRoot :: (Newtype QueryRoot {| p}, RecordArg p a u) => ArgGql QueryRoot { | a }
177175
178176
newtype MyInputType = MyInputType
179177
{ id :: Int
180178
, username :: (NotNull String)
181179
}
182-
derive instance newtypeMyInputType :: Newtype MyInputType _
183-
instance argToGqlMyInputType :: (Newtype MyInputType {| p}, RecordArg p a u) => ArgGql MyInputType { | a }"""
180+
derive instance newtypeMyInputType :: Newtype MyInputType _"""
184181
gql `shouldParseTo` result
185182
it "converts enum types" do
186183
let
@@ -241,8 +238,7 @@ newtype Query = Query
241238
, my_type_b :: (Maybe MyModule.MyTypeB)
242239
, my_type_c :: (Array MyModule.MyTypeC)
243240
}
244-
derive instance newtypeQuery :: Newtype Query _
245-
instance argToGqlQuery :: (Newtype Query {| p}, RecordArg p a u) => ArgGql Query { | a }"""
241+
derive instance newtypeQuery :: Newtype Query _"""
246242
gql
247243
` ( shouldParseToOpts
248244
defaultOpts
@@ -291,7 +287,6 @@ newtype Query = Query
291287
, my_type_c :: (Array AlsoUnkown)
292288
}
293289
derive instance newtypeQuery :: Newtype Query _
294-
instance argToGqlQuery :: (Newtype Query {| p}, RecordArg p a u) => ArgGql Query { | a }
295290
296291
type SomethingUnknown = Data.Argonaut.Core.Json -- Unknown scalar type. Add SomethingUnknown to externalTypes in codegen options to override this behaviour
297292
@@ -323,13 +318,11 @@ newtype Query = Query
323318
{ int :: Int
324319
}
325320
derive instance newtypeQuery :: Newtype Query _
326-
instance argToGqlQuery :: (Newtype Query {| p}, RecordArg p a u) => ArgGql Query { | a }
327321
328322
newtype X = X
329323
{ int :: Int
330324
}
331-
derive instance newtypeX :: Newtype X _
332-
instance argToGqlX :: (Newtype X {| p}, RecordArg p a u) => ArgGql X { | a }"""
325+
derive instance newtypeX :: Newtype X _"""
333326
gql `shouldParseTo` result
334327
it "handles unsafe fieldnames (some not to gql spec)" do
335328
let
@@ -389,7 +382,6 @@ type Query = QueryRoot
389382
newtype QueryRoot = QueryRoot """
390383
<> queryRoot
391384
<> "\nderive instance newtypeQueryRoot :: Newtype QueryRoot _"
392-
<> "\ninstance argToGqlQueryRoot :: (Newtype QueryRoot {| p}, RecordArg p a u) => ArgGql QueryRoot { | a }"
393385

394386
schemaGql :: { query :: String, mutation :: String, subscription :: String } -> String
395387
schemaGql { query, mutation, subscription } =
@@ -423,18 +415,15 @@ newtype QueryRoot = QueryRoot """
423415
<> query
424416
<> """
425417
derive instance newtypeQueryRoot :: Newtype QueryRoot _
426-
instance argToGqlQueryRoot :: (Newtype QueryRoot {| p}, RecordArg p a u) => ArgGql QueryRoot { | a }
427418
428419
newtype MutationRoot = MutationRoot """
429420
<> mutation
430421
<> """
431422
derive instance newtypeMutationRoot :: Newtype MutationRoot _
432-
instance argToGqlMutationRoot :: (Newtype MutationRoot {| p}, RecordArg p a u) => ArgGql MutationRoot { | a }
433423
434424
newtype SubscriptionRoot = SubscriptionRoot """
435425
<> subscription
436426
<> "\nderive instance newtypeSubscriptionRoot :: Newtype SubscriptionRoot _"
437-
<> "\ninstance argToGqlSubscriptionRoot :: (Newtype SubscriptionRoot {| p}, RecordArg p a u) => ArgGql SubscriptionRoot { | a }"
438427

439428
defaultOpts :: InputOptions
440429
defaultOpts =

0 commit comments

Comments
 (0)