Skip to content

Commit

Permalink
require custom inputs and objects to be exported (#1491)
Browse files Browse the repository at this point in the history
  • Loading branch information
lolopinto committed Jun 9, 2023
1 parent 11e1719 commit d13eddb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 77 deletions.
43 changes: 43 additions & 0 deletions examples/ent-rsvp/backend/src/ent/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,46 @@ export * from "src/ent/guest_group/query/guest_group_to_guests_query";
export * from "src/ent/guest_group/query/guest_group_to_invited_events_query";
export * from "src/ent/user/query/user_owner_to_addresses_query";
export * from "src/ent/user/query/user_to_events_query";











































Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/simple/src/graphql/mutations/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class UserAuthInput {
}

@gqlInputObjectType()
class UserAuthJWTInput {
export class UserAuthJWTInput {
@gqlField({
class: "UserAuthJWTInput",
type: GraphQLString,
Expand All @@ -53,7 +53,7 @@ export class UserAuthPayload {
// TODO abstract classes..

@gqlObjectType()
class UserAuthJWTPayload {
export class UserAuthJWTPayload {
@gqlField({
class: "UserAuthJWTPayload",
type: GraphQLString,
Expand Down
3 changes: 0 additions & 3 deletions examples/todo-sqlite/src/graphql/generated/schema.gql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 2 additions & 60 deletions internal/graphql/custom_ts.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,6 @@ func buildObjectType(processor *codegen.Processor, cd *CustomData, s *gqlSchema,
}

cls := cd.Classes[item.Type]
createInterface := true
if cls != nil {
importPath, err := getRelativeImportPath(processor, destPath, cls.Path)
if err != nil {
Expand All @@ -690,73 +689,16 @@ func buildObjectType(processor *codegen.Processor, cd *CustomData, s *gqlSchema,
ImportPath: importPath,
Import: item.Type,
})
createInterface = false
} else if cls.Exported {
typ.Imports = append(typ.Imports, &tsimport.ImportPath{
ImportPath: importPath,
Import: item.Type,
})
createInterface = false
} else {
return nil, fmt.Errorf("class %s is not exported and objects referenced need to be exported", item.Type)
}
}

if createInterface {
// need to create an interface for it
customInt := newInterfaceType(&interfaceType{
Exported: false,
Name: item.Type,
})
fields, ok := cd.Fields[item.Type]
if !ok {
return nil, fmt.Errorf("type %s has no fields", item.Type)

}
for _, field := range fields {
newInt := &interfaceField{
Name: field.GraphQLName,
Type: field.Results[0].Type,
// TODO getGraphQLImportsForField???
// here we grab import from classessss
// but then later we need class
UseImport: false,
// TODO need to convert to number etc...
// need to convert from graphql type to TS type :(
}

if len(field.Results) == 1 {
result := field.Results[0]
// check for imported paths that are being used
if result.TSType != "" {
newInt.Type = result.TSType
if cls != nil {
file := cd.Files[cls.Path]
if file != nil {
imp := file.Imports[newInt.Type]
if imp != nil {
fImp := &tsimport.ImportPath{
Import: newInt.Type,
// TODO this needs to be resolved to be relative...
// for now assuming tsconfig.json paths being used
ImportPath: imp.Path,
}
if imp.DefaultImport {
typ.DefaultImports = append(typ.DefaultImports, fImp)
} else {
typ.Imports = append(typ.Imports, fImp)
}
newInt.UseImport = true
}
}
}
}
}

if err := customInt.addField(newInt); err != nil {
return nil, err
}
}
typ.TSInterfaces = []*interfaceType{customInt}
}
return typ, nil
}

Expand Down

0 comments on commit d13eddb

Please sign in to comment.