Gen non null custom field types
ghostiam opened this issue · comments
Vladislav Fursov commented
type BarFoo {
startCursor: ID
endCursor: ID
hasNextPage: Boolean!
}
type FooBar {
barFoo: BarFoo
barFoo2: BarFoo!
test: Test
test2: Test!
}
scalar Test
We get:
type FooBar struct {
// BarFoo
BarFoo *BarFooResolver `json:"barFoo"`
// BarFoo2
BarFoo2 *BarFooResolver `json:"barFoo2"`
// Test
Test *TestResolver `json:"test"`
// Test2
Test2 *TestResolver `json:"test2"`
}
Expected:
type FooBar struct {
// BarFoo
BarFoo *BarFooResolver `json:"barFoo"`
// BarFoo2
BarFoo2 *BarFooResolver `json:"barFoo2"`
// Test
Test *TestResolver `json:"test"`
// Test2
Test2 TestResolver `json:"test2"`
}
Vladislav Fursov commented
Maybe error in https://github.com/Applifier/graphql-codegen/blob/master/codegen/codegen.go#L426-L437
...
} else if tp.Kind() != "INPUT_OBJECT" {
if len(typ) > 0 {
if typ[len(typ)-1] != '*' {
typ = typ + "*"
}
} else {
typ = "*"
}
typ = typ + *name + "Resolver"
} else {
typ = typ + *name
}
...
Vladislav Fursov commented
If I commented line 432 https://github.com/Applifier/graphql-codegen/blob/master/codegen/codegen.go#L432
bug is fixed :)
Vladislav Fursov commented
fix
if tp.Kind() == "ENUM" {
typ = typ + *name
} else if tp.Kind() != "INPUT_OBJECT" {
if len(typ) > 0 {
if typ[len(typ)-1] != '*' {
typ = typ + "*"
}
- } else {
+ } else if tp.Kind() != "SCALAR" {
typ = "*"
}
typ = typ + *name + "Resolver"
} else {
typ = typ + *name
}